Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: tests/MathTest.cpp

Issue 1616013003: de-proc sk_float_rsqrt (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test both Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/opts/SkOpts_neon.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkEndian.h" 9 #include "SkEndian.h"
10 #include "SkFloatBits.h" 10 #include "SkFloatBits.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 f = SkHalfToFloat(h); 375 f = SkHalfToFloat(h);
376 REPORTER_ASSERT(reporter, !SkScalarIsFinite(f) ); 376 REPORTER_ASSERT(reporter, !SkScalarIsFinite(f) );
377 377
378 static const FloatUnion nan32 = { 255 << 23 | 1 }; 378 static const FloatUnion nan32 = { 255 << 23 | 1 };
379 h = SkFloatToHalf(nan32.fF); 379 h = SkFloatToHalf(nan32.fF);
380 f = SkHalfToFloat(h); 380 f = SkHalfToFloat(h);
381 REPORTER_ASSERT(reporter, SkScalarIsNaN(f) ); 381 REPORTER_ASSERT(reporter, SkScalarIsNaN(f) );
382 382
383 } 383 }
384 384
385 static void test_rsqrt(skiatest::Reporter* reporter) { 385 template <typename RSqrtFn>
386 static void test_rsqrt(skiatest::Reporter* reporter, RSqrtFn rsqrt) {
386 const float maxRelativeError = 6.50196699e-4f; 387 const float maxRelativeError = 6.50196699e-4f;
387 388
388 // test close to 0 up to 1 389 // test close to 0 up to 1
389 float input = 0.000001f; 390 float input = 0.000001f;
390 for (int i = 0; i < 1000; ++i) { 391 for (int i = 0; i < 1000; ++i) {
391 float exact = 1.0f/sk_float_sqrt(input); 392 float exact = 1.0f/sk_float_sqrt(input);
392 float estimate = sk_float_rsqrt(input); 393 float estimate = rsqrt(input);
393 float relativeError = sk_float_abs(exact - estimate)/exact; 394 float relativeError = sk_float_abs(exact - estimate)/exact;
394 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError); 395 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
395 input += 0.001f; 396 input += 0.001f;
396 } 397 }
397 398
398 // test 1 to ~100 399 // test 1 to ~100
399 input = 1.0f; 400 input = 1.0f;
400 for (int i = 0; i < 1000; ++i) { 401 for (int i = 0; i < 1000; ++i) {
401 float exact = 1.0f/sk_float_sqrt(input); 402 float exact = 1.0f/sk_float_sqrt(input);
402 float estimate = sk_float_rsqrt(input); 403 float estimate = rsqrt(input);
403 float relativeError = sk_float_abs(exact - estimate)/exact; 404 float relativeError = sk_float_abs(exact - estimate)/exact;
404 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError); 405 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
405 input += 0.01f; 406 input += 0.01f;
406 } 407 }
407 408
408 // test some big numbers 409 // test some big numbers
409 input = 1000000.0f; 410 input = 1000000.0f;
410 for (int i = 0; i < 100; ++i) { 411 for (int i = 0; i < 100; ++i) {
411 float exact = 1.0f/sk_float_sqrt(input); 412 float exact = 1.0f/sk_float_sqrt(input);
412 float estimate = sk_float_rsqrt(input); 413 float estimate = rsqrt(input);
413 float relativeError = sk_float_abs(exact - estimate)/exact; 414 float relativeError = sk_float_abs(exact - estimate)/exact;
414 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError); 415 REPORTER_ASSERT(reporter, relativeError <= maxRelativeError);
415 input += 754326.f; 416 input += 754326.f;
416 } 417 }
417 } 418 }
418 419
419 static void test_muldiv255(skiatest::Reporter* reporter) { 420 static void test_muldiv255(skiatest::Reporter* reporter) {
420 for (int a = 0; a <= 255; a++) { 421 for (int a = 0; a <= 255; a++) {
421 for (int b = 0; b <= 255; b++) { 422 for (int b = 0; b <= 255; b++) {
422 int ab = a * b; 423 int ab = a * b;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 { 549 {
549 SkFixed result = SkFixedDiv(100, 100); 550 SkFixed result = SkFixedDiv(100, 100);
550 REPORTER_ASSERT(reporter, result == SK_Fixed1); 551 REPORTER_ASSERT(reporter, result == SK_Fixed1);
551 result = SkFixedDiv(1, SK_Fixed1); 552 result = SkFixedDiv(1, SK_Fixed1);
552 REPORTER_ASSERT(reporter, result == 1); 553 REPORTER_ASSERT(reporter, result == 1);
553 } 554 }
554 555
555 unittest_fastfloat(reporter); 556 unittest_fastfloat(reporter);
556 unittest_isfinite(reporter); 557 unittest_isfinite(reporter);
557 unittest_half(reporter); 558 unittest_half(reporter);
558 test_rsqrt(reporter); 559 test_rsqrt(reporter, sk_float_rsqrt);
560 test_rsqrt(reporter, sk_float_rsqrt_portable);
559 561
560 for (i = 0; i < 10000; i++) { 562 for (i = 0; i < 10000; i++) {
561 SkFixed numer = rand.nextS(); 563 SkFixed numer = rand.nextS();
562 SkFixed denom = rand.nextS(); 564 SkFixed denom = rand.nextS();
563 SkFixed result = SkFixedDiv(numer, denom); 565 SkFixed result = SkFixedDiv(numer, denom);
564 int64_t check = SkLeftShift((int64_t)numer, 16) / denom; 566 int64_t check = SkLeftShift((int64_t)numer, 16) / denom;
565 567
566 (void)SkCLZ(numer); 568 (void)SkCLZ(numer);
567 (void)SkCLZ(denom); 569 (void)SkCLZ(denom);
568 570
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 test_divmod<int16_t>(r); 691 test_divmod<int16_t>(r);
690 } 692 }
691 693
692 DEF_TEST(divmod_s32, r) { 694 DEF_TEST(divmod_s32, r) {
693 test_divmod<int32_t>(r); 695 test_divmod<int32_t>(r);
694 } 696 }
695 697
696 DEF_TEST(divmod_s64, r) { 698 DEF_TEST(divmod_s64, r) {
697 test_divmod<int64_t>(r); 699 test_divmod<int64_t>(r);
698 } 700 }
OLDNEW
« no previous file with comments | « src/opts/SkOpts_neon.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698