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