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

Side by Side Diff: tests/MathTest.cpp

Issue 18539004: ARM Skia NEON patches - 04 - Clean SkFixed / SkLONGLONG (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Completely remove SkLONGLONG Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
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
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) {
191 int sa = SkExtractSign(a);
192 int sb = SkExtractSign(b);
193
194 a = SkApplySign(a, sa);
195 b = SkApplySign(b, sb);
196
197 #if 1
198 int c = (int)(((SkLONGLONG)a * b) >> 16);
199
200 return SkApplySign(c, sa ^ sb);
201 #else
202 SkLONGLONG ab = (SkLONGLONG)a * b;
203 if (sa ^ sb) {
204 ab = -ab;
205 }
206 return ab >> 16;
207 #endif
208 }
209 #endif
210
211 static void check_length(skiatest::Reporter* reporter, 189 static void check_length(skiatest::Reporter* reporter,
212 const SkPoint& p, SkScalar targetLen) { 190 const SkPoint& p, SkScalar targetLen) {
213 float x = SkScalarToFloat(p.fX); 191 float x = SkScalarToFloat(p.fX);
214 float y = SkScalarToFloat(p.fY); 192 float y = SkScalarToFloat(p.fY);
215 float len = sk_float_sqrt(x*x + y*y); 193 float len = sk_float_sqrt(x*x + y*y);
216 194
217 len /= SkScalarToFloat(targetLen); 195 len /= SkScalarToFloat(targetLen);
218 196
219 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f); 197 REPORTER_ASSERT(reporter, len > 0.999f && len < 1.001f);
220 } 198 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 { 493 {
516 SkFixed result = SkFixedDiv(100, 100); 494 SkFixed result = SkFixedDiv(100, 100);
517 REPORTER_ASSERT(reporter, result == SK_Fixed1); 495 REPORTER_ASSERT(reporter, result == SK_Fixed1);
518 result = SkFixedDiv(1, SK_Fixed1); 496 result = SkFixedDiv(1, SK_Fixed1);
519 REPORTER_ASSERT(reporter, result == 1); 497 REPORTER_ASSERT(reporter, result == 1);
520 } 498 }
521 499
522 unittest_fastfloat(reporter); 500 unittest_fastfloat(reporter);
523 unittest_isfinite(reporter); 501 unittest_isfinite(reporter);
524 502
525 #ifdef SkLONGLONG
526 for (i = 0; i < 10000; i++) {
527 SkFixed numer = rand.nextS();
528 SkFixed denom = rand.nextS();
529 SkFixed result = SkFixedDiv(numer, denom);
530 SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom;
531
532 (void)SkCLZ(numer);
533 (void)SkCLZ(denom);
534
535 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32);
536 if (check > SK_MaxS32) {
537 check = SK_MaxS32;
538 } else if (check < -SK_MaxS32) {
539 check = SK_MinS32;
540 }
541 REPORTER_ASSERT(reporter, result == (int32_t)check);
542
543 result = SkFractDiv(numer, denom);
544 check = ((SkLONGLONG)numer << 30) / denom;
545
546 REPORTER_ASSERT(reporter, result != (SkFixed)SK_NaN32);
547 if (check > SK_MaxS32) {
548 check = SK_MaxS32;
549 } else if (check < -SK_MaxS32) {
550 check = SK_MinS32;
551 }
552 REPORTER_ASSERT(reporter, result == (int32_t)check);
553
554 // make them <= 2^24, so we don't overflow in fixmul
555 numer = numer << 8 >> 8;
556 denom = denom << 8 >> 8;
557
558 result = SkFixedMul(numer, denom);
559 SkFixed r2 = symmetric_fixmul(numer, denom);
560 // SkASSERT(result == r2);
561
562 result = SkFixedMul(numer, numer);
563 r2 = SkFixedSquare(numer);
564 REPORTER_ASSERT(reporter, result == r2);
565
566 if (numer >= 0 && denom >= 0) {
567 SkFixed mean = SkFixedMean(numer, denom);
568 float prod = SkFixedToFloat(numer) * SkFixedToFloat(denom);
569 float fm = sk_float_sqrt(sk_float_abs(prod));
570 SkFixed mean2 = SkFloatToFixed(fm);
571 int diff = SkAbs32(mean - mean2);
572 REPORTER_ASSERT(reporter, diff <= 1);
573 }
574
575 {
576 SkFixed mod = SkFixedMod(numer, denom);
577 float n = SkFixedToFloat(numer);
578 float d = SkFixedToFloat(denom);
579 float m = sk_float_mod(n, d);
580 // ensure the same sign
581 REPORTER_ASSERT(reporter, mod == 0 || (mod < 0) == (m < 0));
582 int diff = SkAbs32(mod - SkFloatToFixed(m));
583 REPORTER_ASSERT(reporter, (diff >> 7) == 0);
584 }
585 }
586 #endif
587
588 for (i = 0; i < 10000; i++) { 503 for (i = 0; i < 10000; i++) {
589 SkFract x = rand.nextU() >> 1; 504 SkFract x = rand.nextU() >> 1;
590 double xx = (double)x / SK_Fract1; 505 double xx = (double)x / SK_Fract1;
591 SkFract xr = SkFractSqrt(x); 506 SkFract xr = SkFractSqrt(x);
592 SkFract check = SkFloatToFract(sqrt(xx)); 507 SkFract check = SkFloatToFract(sqrt(xx));
593 REPORTER_ASSERT(reporter, xr == check || 508 REPORTER_ASSERT(reporter, xr == check ||
594 xr == check-1 || 509 xr == check-1 ||
595 xr == check+1); 510 xr == check+1);
596 511
597 xr = SkFixedSqrt(x); 512 xr = SkFixedSqrt(x);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 } 599 }
685 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) { 600 for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) {
686 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin)); 601 REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin));
687 } 602 }
688 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) { 603 for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) {
689 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin)); 604 REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin));
690 } 605 }
691 } 606 }
692 607
693 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian) 608 DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian)
OLDNEW
« src/core/SkMath.cpp ('K') | « src/core/SkMath.cpp ('k') | tests/Sk64Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698