| OLD | NEW |
| 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 "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 src, dst, a, r0, f1); | 181 src, dst, a, r0, f1); |
| 182 #endif | 182 #endif |
| 183 REPORTER_ASSERT(reporter, false); | 183 REPORTER_ASSERT(reporter, false); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 #if defined(SkLONGLONG) | |
| 192 static int symmetric_fixmul(int a, int b) { | |
| 193 int sa = SkExtractSign(a); | |
| 194 int sb = SkExtractSign(b); | |
| 195 | |
| 196 a = SkApplySign(a, sa); | |
| 197 b = SkApplySign(b, sb); | |
| 198 | |
| 199 #if 1 | |
| 200 int c = (int)(((SkLONGLONG)a * b) >> 16); | |
| 201 | |
| 202 return SkApplySign(c, sa ^ sb); | |
| 203 #else | |
| 204 SkLONGLONG ab = (SkLONGLONG)a * b; | |
| 205 if (sa ^ sb) { | |
| 206 ab = -ab; | |
| 207 } | |
| 208 return ab >> 16; | |
| 209 #endif | |
| 210 } | |
| 211 #endif | |
| 212 | |
| 213 static void check_length(skiatest::Reporter* reporter, | 191 static void check_length(skiatest::Reporter* reporter, |
| 214 const SkPoint& p, SkScalar targetLen) { | 192 const SkPoint& p, SkScalar targetLen) { |
| 215 float x = SkScalarToFloat(p.fX); | 193 float x = SkScalarToFloat(p.fX); |
| 216 float y = SkScalarToFloat(p.fY); | 194 float y = SkScalarToFloat(p.fY); |
| 217 float len = sk_float_sqrt(x*x + y*y); | 195 float len = sk_float_sqrt(x*x + y*y); |
| 218 | 196 |
| 219 len /= SkScalarToFloat(targetLen); | 197 len /= SkScalarToFloat(targetLen); |
| 220 | 198 |
| 221 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); | 199 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); |
| 222 } | 200 } |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 { | 463 { |
| 486 SkFixed result = SkFixedDiv(100, 100); | 464 SkFixed result = SkFixedDiv(100, 100); |
| 487 REPORTER_ASSERT(reporter, result == SK_Fixed1); | 465 REPORTER_ASSERT(reporter, result == SK_Fixed1); |
| 488 result = SkFixedDiv(1, SK_Fixed1); | 466 result = SkFixedDiv(1, SK_Fixed1); |
| 489 REPORTER_ASSERT(reporter, result == 1); | 467 REPORTER_ASSERT(reporter, result == 1); |
| 490 } | 468 } |
| 491 | 469 |
| 492 unittest_fastfloat(reporter); | 470 unittest_fastfloat(reporter); |
| 493 unittest_isfinite(reporter); | 471 unittest_isfinite(reporter); |
| 494 | 472 |
| 495 #ifdef SkLONGLONG | |
| 496 for (i = 0; i < 10000; i++) { | 473 for (i = 0; i < 10000; i++) { |
| 497 SkFixed numer = rand.nextS(); | 474 SkFixed numer = rand.nextS(); |
| 498 SkFixed denom = rand.nextS(); | 475 SkFixed denom = rand.nextS(); |
| 499 SkFixed result = SkFixedDiv(numer, denom); | 476 SkFixed result = SkFixedDiv(numer, denom); |
| 500 SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom; | 477 int64_t check = ((int64_t)numer << 16) / denom; |
| 501 | 478 |
| 502 (void)SkCLZ(numer); | 479 (void)SkCLZ(numer); |
| 503 (void)SkCLZ(denom); | 480 (void)SkCLZ(denom); |
| 504 | 481 |
| 505 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); | 482 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); |
| 506 if (check > SK_MaxS32) { | 483 if (check > SK_MaxS32) { |
| 507 check = SK_MaxS32; | 484 check = SK_MaxS32; |
| 508 } else if (check < -SK_MaxS32) { | 485 } else if (check < -SK_MaxS32) { |
| 509 check = SK_MinS32; | 486 check = SK_MinS32; |
| 510 } | 487 } |
| 511 REPORTER_ASSERT(reporter, result == (int32_t)check); | 488 REPORTER_ASSERT(reporter, result == (int32_t)check); |
| 512 | |
| 513 // make them <= 2^24, so we don't overflow in fixmul | |
| 514 numer = numer << 8 >> 8; | |
| 515 denom = denom << 8 >> 8; | |
| 516 | |
| 517 result = SkFixedMul(numer, denom); | |
| 518 SkFixed r2 = symmetric_fixmul(numer, denom); | |
| 519 // SkASSERT(result == r2); | |
| 520 | |
| 521 result = SkFixedMul(numer, numer); | |
| 522 r2 = SkFixedSquare(numer); | |
| 523 REPORTER_ASSERT(reporter, result == r2); | |
| 524 } | 489 } |
| 525 #endif | |
| 526 | 490 |
| 527 test_blend(reporter); | 491 test_blend(reporter); |
| 528 | 492 |
| 529 if (false) test_floor(reporter); | 493 if (false) test_floor(reporter); |
| 530 | 494 |
| 531 // disable for now | 495 // disable for now |
| 532 if (false) test_blend31(); // avoid bit rot, suppress warning | 496 if (false) test_blend31(); // avoid bit rot, suppress warning |
| 533 | 497 |
| 534 test_muldivround(reporter); | 498 test_muldivround(reporter); |
| 535 test_clz(reporter); | 499 test_clz(reporter); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 test_divmod<int16_t>(r); | 599 test_divmod<int16_t>(r); |
| 636 } | 600 } |
| 637 | 601 |
| 638 DEF_TEST(divmod_s32, r) { | 602 DEF_TEST(divmod_s32, r) { |
| 639 test_divmod<int32_t>(r); | 603 test_divmod<int32_t>(r); |
| 640 } | 604 } |
| 641 | 605 |
| 642 DEF_TEST(divmod_s64, r) { | 606 DEF_TEST(divmod_s64, r) { |
| 643 test_divmod<int64_t>(r); | 607 test_divmod<int64_t>(r); |
| 644 } | 608 } |
| OLD | NEW |