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