OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkFloatingPoint.h" | 10 #include "SkFloatingPoint.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 src, dst, a, r0, f1); | 179 src, dst, a, r0, f1); |
180 #endif | 180 #endif |
181 REPORTER_ASSERT(reporter, false); | 181 REPORTER_ASSERT(reporter, false); |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 } | 185 } |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 #if defined(SkLONGLONG) | |
190 static int symmetric_fixmul(int a, int b) { | 189 static int symmetric_fixmul(int a, int b) { |
191 int sa = SkExtractSign(a); | 190 int sa = SkExtractSign(a); |
192 int sb = SkExtractSign(b); | 191 int sb = SkExtractSign(b); |
193 | 192 |
194 a = SkApplySign(a, sa); | 193 a = SkApplySign(a, sa); |
195 b = SkApplySign(b, sb); | 194 b = SkApplySign(b, sb); |
196 | 195 |
197 #if 1 | 196 #if 1 |
198 int c = (int)(((SkLONGLONG)a * b) >> 16); | 197 int c = (int)(((int64_t)a * b) >> 16); |
199 | 198 |
200 return SkApplySign(c, sa ^ sb); | 199 return SkApplySign(c, sa ^ sb); |
201 #else | 200 #else |
202 SkLONGLONG ab = (SkLONGLONG)a * b; | 201 int64_t ab = (int64_t)a * b; |
203 if (sa ^ sb) { | 202 if (sa ^ sb) { |
204 ab = -ab; | 203 ab = -ab; |
205 } | 204 } |
206 return ab >> 16; | 205 return ab >> 16; |
207 #endif | 206 #endif |
208 } | 207 } |
209 #endif | |
210 | 208 |
211 static void check_length(skiatest::Reporter* reporter, | 209 static void check_length(skiatest::Reporter* reporter, |
212 const SkPoint& p, SkScalar targetLen) { | 210 const SkPoint& p, SkScalar targetLen) { |
213 float x = SkScalarToFloat(p.fX); | 211 float x = SkScalarToFloat(p.fX); |
214 float y = SkScalarToFloat(p.fY); | 212 float y = SkScalarToFloat(p.fY); |
215 float len = sk_float_sqrt(x*x + y*y); | 213 float len = sk_float_sqrt(x*x + y*y); |
216 | 214 |
217 len /= SkScalarToFloat(targetLen); | 215 len /= SkScalarToFloat(targetLen); |
218 | 216 |
219 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); | 217 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 { | 513 { |
516 SkFixed result = SkFixedDiv(100, 100); | 514 SkFixed result = SkFixedDiv(100, 100); |
517 REPORTER_ASSERT(reporter, result == SK_Fixed1); | 515 REPORTER_ASSERT(reporter, result == SK_Fixed1); |
518 result = SkFixedDiv(1, SK_Fixed1); | 516 result = SkFixedDiv(1, SK_Fixed1); |
519 REPORTER_ASSERT(reporter, result == 1); | 517 REPORTER_ASSERT(reporter, result == 1); |
520 } | 518 } |
521 | 519 |
522 unittest_fastfloat(reporter); | 520 unittest_fastfloat(reporter); |
523 unittest_isfinite(reporter); | 521 unittest_isfinite(reporter); |
524 | 522 |
525 #ifdef SkLONGLONG | |
526 for (i = 0; i < 10000; i++) { | 523 for (i = 0; i < 10000; i++) { |
527 SkFixed numer = rand.nextS(); | 524 SkFixed numer = rand.nextS(); |
528 SkFixed denom = rand.nextS(); | 525 SkFixed denom = rand.nextS(); |
529 SkFixed result = SkFixedDiv(numer, denom); | 526 SkFixed result = SkFixedDiv(numer, denom); |
530 SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom; | 527 int64_t check = ((int64_t)numer << 16) / denom; |
531 | 528 |
532 (void)SkCLZ(numer); | 529 (void)SkCLZ(numer); |
533 (void)SkCLZ(denom); | 530 (void)SkCLZ(denom); |
534 | 531 |
535 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); | 532 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); |
536 if (check > SK_MaxS32) { | 533 if (check > SK_MaxS32) { |
537 check = SK_MaxS32; | 534 check = SK_MaxS32; |
538 } else if (check < -SK_MaxS32) { | 535 } else if (check < -SK_MaxS32) { |
539 check = SK_MinS32; | 536 check = SK_MinS32; |
540 } | 537 } |
541 REPORTER_ASSERT(reporter, result == (int32_t)check); | 538 REPORTER_ASSERT(reporter, result == (int32_t)check); |
542 | 539 |
543 result = SkFractDiv(numer, denom); | 540 result = SkFractDiv(numer, denom); |
544 check = ((SkLONGLONG)numer << 30) / denom; | 541 check = ((int64_t)numer << 30) / denom; |
545 | 542 |
546 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); | 543 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32); |
547 if (check > SK_MaxS32) { | 544 if (check > SK_MaxS32) { |
548 check = SK_MaxS32; | 545 check = SK_MaxS32; |
549 } else if (check < -SK_MaxS32) { | 546 } else if (check < -SK_MaxS32) { |
550 check = SK_MinS32; | 547 check = SK_MinS32; |
551 } | 548 } |
552 REPORTER_ASSERT(reporter, result == (int32_t)check); | 549 REPORTER_ASSERT(reporter, result == (int32_t)check); |
553 | 550 |
554 // make them <= 2^24, so we don't overflow in fixmul | 551 // make them <= 2^24, so we don't overflow in fixmul |
(...skipping 21 matching lines...) Expand all Loading... |
576 SkFixed mod = SkFixedMod(numer, denom); | 573 SkFixed mod = SkFixedMod(numer, denom); |
577 float n = SkFixedToFloat(numer); | 574 float n = SkFixedToFloat(numer); |
578 float d = SkFixedToFloat(denom); | 575 float d = SkFixedToFloat(denom); |
579 float m = sk_float_mod(n, d); | 576 float m = sk_float_mod(n, d); |
580 // ensure the same sign | 577 // ensure the same sign |
581 REPORTER_ASSERT(reporter, mod == 0 || (mod < 0) == (m < 0)); | 578 REPORTER_ASSERT(reporter, mod == 0 || (mod < 0) == (m < 0)); |
582 int diff = SkAbs32(mod - SkFloatToFixed(m)); | 579 int diff = SkAbs32(mod - SkFloatToFixed(m)); |
583 REPORTER_ASSERT(reporter, (diff >> 7) == 0); | 580 REPORTER_ASSERT(reporter, (diff >> 7) == 0); |
584 } | 581 } |
585 } | 582 } |
586 #endif | |
587 | 583 |
588 for (i = 0; i < 10000; i++) { | 584 for (i = 0; i < 10000; i++) { |
589 SkFract x = rand.nextU() >> 1; | 585 SkFract x = rand.nextU() >> 1; |
590 double xx = (double)x / SK_Fract1; | 586 double xx = (double)x / SK_Fract1; |
591 SkFract xr = SkFractSqrt(x); | 587 SkFract xr = SkFractSqrt(x); |
592 SkFract check = SkFloatToFract(sqrt(xx)); | 588 SkFract check = SkFloatToFract(sqrt(xx)); |
593 REPORTER_ASSERT(reporter, xr == check || | 589 REPORTER_ASSERT(reporter, xr == check || |
594 xr == check-1 || | 590 xr == check-1 || |
595 xr == check+1); | 591 xr == check+1); |
596 | 592 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 680 } |
685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { | 681 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { |
686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); | 682 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); |
687 } | 683 } |
688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { | 684 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { |
689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); | 685 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); |
690 } | 686 } |
691 } | 687 } |
692 | 688 |
693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) | 689 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) |
OLD | NEW |