diff options
-rw-r--r-- | include/config/SkUserConfig.h | 6 | ||||
-rw-r--r-- | include/core/Sk64.h | 13 | ||||
-rw-r--r-- | include/core/SkFixed.h | 18 | ||||
-rw-r--r-- | include/core/SkPostConfig.h | 10 | ||||
-rw-r--r-- | include/utils/SkCamera.h | 5 | ||||
-rw-r--r-- | src/core/Sk64.cpp | 8 | ||||
-rw-r--r-- | src/core/SkMath.cpp | 2 | ||||
-rw-r--r-- | tests/BitmapCopyTest.cpp | 12 | ||||
-rw-r--r-- | tests/MathTest.cpp | 38 | ||||
-rw-r--r-- | tests/Sk64Test.cpp | 48 |
10 files changed, 46 insertions, 114 deletions
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h index 534c79dde1..ec791d9a50 100644 --- a/include/config/SkUserConfig.h +++ b/include/config/SkUserConfig.h @@ -88,12 +88,6 @@ //#define SK_UINT8_BITFIELD_LENDIAN -/* Some compilers don't support long long for 64bit integers. If yours does - not, define this to the appropriate type. - */ -//#define SkLONGLONG int64_t - - /* To write debug messages to a console, skia will call SkDebugf(...) following printf conventions (e.g. const char* format, ...). If you want to redirect this to something other than printf, define yours here diff --git a/include/core/Sk64.h b/include/core/Sk64.h index eba8b684c6..009744938f 100644 --- a/include/core/Sk64.h +++ b/include/core/Sk64.h @@ -17,9 +17,17 @@ Sk64 is a 64-bit math package that does not require long long support from the compiler. */ struct SK_API Sk64 { +private: int32_t fHi; //!< the high 32 bits of the number (including sign) uint32_t fLo; //!< the low 32 bits of the number +public: + int32_t hi() const { return fHi; } + uint32_t lo() const { return fLo; } + + int64_t as64() const { return ((int64_t)fHi << 32) | fLo; } + int64_t getLongLong() const { return this->as64(); } + /** Returns non-zero if the Sk64 can be represented as a signed 32 bit integer */ SkBool is32() const { return fHi == ((int32_t)fLo >> 31); } @@ -169,9 +177,8 @@ struct SK_API Sk64 { return a.fHi > b.fHi || (a.fHi == b.fHi && a.fLo >= b.fLo); } -#ifdef SkLONGLONG - SkLONGLONG getLongLong() const; -#endif + // Private to unittests. Parameter is (skiatest::Reporter*) + static void UnitTestWithReporter(void* skiatest_reporter); }; #endif diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h index 580d94b9ca..e63794e862 100644 --- a/include/core/SkFixed.h +++ b/include/core/SkFixed.h @@ -86,17 +86,6 @@ typedef int32_t SkFixed; #define SkFixedAve(a, b) (((a) + (b)) >> 1) SkFixed SkFixedMul_portable(SkFixed, SkFixed); -inline SkFixed SkFixedSquare_portable(SkFixed value) -{ - uint32_t a = SkAbs32(value); - uint32_t ah = a >> 16; - uint32_t al = a & 0xFFFF; - SkFixed result = ah * a + al * ah + (al * al >> 16); - if (result >= 0) - return result; - else // Overflow. - return SK_FixedMax; -} #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) @@ -118,14 +107,9 @@ static inline SkFixed SkFixedCos(SkFixed radians) { #ifdef SkLONGLONG inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) { - return (SkFixed)((SkLONGLONG)a * b >> 16); - } - inline SkFixed SkFixedSquare_longlong(SkFixed value) - { - return (SkFixed)((SkLONGLONG)value * value >> 16); + return (SkFixed)((int64_t)a * b >> 16); } #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) - #define SkFixedSquare(a) SkFixedSquare_longlong(a) #endif #if defined(SK_CPU_ARM) diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h index 323d1e8b6d..2156519b2d 100644 --- a/include/core/SkPostConfig.h +++ b/include/core/SkPostConfig.h @@ -227,13 +227,13 @@ ////////////////////////////////////////////////////////////////////// +// TODO: rebaseline as needed so we can remove this flag entirely. +// - all platforms have int64_t now +// - we have slightly different fixed math results because of this check +// since we don't define this for linux/android #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) # ifndef SkLONGLONG -# ifdef SK_BUILD_FOR_WIN32 -# define SkLONGLONG __int64 -# else -# define SkLONGLONG long long -# endif +# define SkLONGLONG int64_t # endif #endif diff --git a/include/utils/SkCamera.h b/include/utils/SkCamera.h index ad74c81d2f..2e5e3423bb 100644 --- a/include/utils/SkCamera.h +++ b/include/utils/SkCamera.h @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,15 +5,11 @@ * found in the LICENSE file. */ - - - // Inspired by Rob Johnson's most excellent QuickDraw GX sample code #ifndef SkCamera_DEFINED #define SkCamera_DEFINED -#include "Sk64.h" #include "SkMatrix.h" class SkCanvas; diff --git a/src/core/Sk64.cpp b/src/core/Sk64.cpp index 1fb0454ae2..0b5b3dfb46 100644 --- a/src/core/Sk64.cpp +++ b/src/core/Sk64.cpp @@ -285,11 +285,3 @@ int32_t Sk64::getSqrt() const return root; } -#ifdef SkLONGLONG - SkLONGLONG Sk64::getLongLong() const - { - SkLONGLONG value = fHi; - value <<= 32; - return value | fLo; - } -#endif diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp index e1133c7850..e7c4fdcc53 100644 --- a/src/core/SkMath.cpp +++ b/src/core/SkMath.cpp @@ -55,7 +55,7 @@ int32_t SkMulDiv(int32_t numer1, int32_t numer2, int32_t denom) { SkFixed SkFixedMul_portable(SkFixed a, SkFixed b) { #if defined(SkLONGLONG) - return static_cast<SkFixed>((SkLONGLONG)a * b >> 16); + return static_cast<SkFixed>((int64_t)a * b >> 16); #else int sa = SkExtractSign(a); int sb = SkExtractSign(b); diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 0df8c06d9b..7a1d9acd7c 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -358,22 +358,22 @@ DEF_TEST(BitmapCopy, reporter) { case SkBitmap::kA8_Config: case SkBitmap::kIndex8_Config: - if (safeSize.fHi != 0x2386F2 || - safeSize.fLo != 0x6FC10000) + if (safeSize.as64() != 0x2386F26FC10000LL) { sizeFail = true; + } break; case SkBitmap::kRGB_565_Config: case SkBitmap::kARGB_4444_Config: - if (safeSize.fHi != 0x470DE4 || - safeSize.fLo != 0xDF820000) + if (safeSize.as64() != 0x470DE4DF820000LL) { sizeFail = true; + } break; case SkBitmap::kARGB_8888_Config: - if (safeSize.fHi != 0x8E1BC9 || - safeSize.fLo != 0xBF040000) + if (safeSize.as64() != 0x8E1BC9BF040000LL) { sizeFail = true; + } break; default: diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 1b8954a361..8cba67dd3d 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -188,28 +188,6 @@ static void test_blend(skiatest::Reporter* reporter) { } } -#if defined(SkLONGLONG) -static int symmetric_fixmul(int a, int b) { - int sa = SkExtractSign(a); - int sb = SkExtractSign(b); - - a = SkApplySign(a, sa); - b = SkApplySign(b, sb); - -#if 1 - int c = (int)(((SkLONGLONG)a * b) >> 16); - - return SkApplySign(c, sa ^ sb); -#else - SkLONGLONG ab = (SkLONGLONG)a * b; - if (sa ^ sb) { - ab = -ab; - } - return ab >> 16; -#endif -} -#endif - static void check_length(skiatest::Reporter* reporter, const SkPoint& p, SkScalar targetLen) { float x = SkScalarToFloat(p.fX); @@ -492,12 +470,11 @@ DEF_TEST(Math, reporter) { unittest_fastfloat(reporter); unittest_isfinite(reporter); -#ifdef SkLONGLONG for (i = 0; i < 10000; i++) { SkFixed numer = rand.nextS(); SkFixed denom = rand.nextS(); SkFixed result = SkFixedDiv(numer, denom); - SkLONGLONG check = ((SkLONGLONG)numer << 16) / denom; + int64_t check = ((int64_t)numer << 16) / denom; (void)SkCLZ(numer); (void)SkCLZ(denom); @@ -509,20 +486,7 @@ DEF_TEST(Math, reporter) { check = SK_MinS32; } REPORTER_ASSERT(reporter, result == (int32_t)check); - - // make them <= 2^24, so we don't overflow in fixmul - numer = numer << 8 >> 8; - denom = denom << 8 >> 8; - - result = SkFixedMul(numer, denom); - SkFixed r2 = symmetric_fixmul(numer, denom); - // SkASSERT(result == r2); - - result = SkFixedMul(numer, numer); - r2 = SkFixedSquare(numer); - REPORTER_ASSERT(reporter, result == r2); } -#endif test_blend(reporter); diff --git a/tests/Sk64Test.cpp b/tests/Sk64Test.cpp index 589801b272..1777d24d10 100644 --- a/tests/Sk64Test.cpp +++ b/tests/Sk64Test.cpp @@ -25,14 +25,9 @@ static void bool_table_test(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, a.getSign() == table.sign); } -#ifdef SkLONGLONG - static SkLONGLONG asLL(const Sk64& a) - { - return ((SkLONGLONG)a.fHi << 32) | a.fLo; - } -#endif +void Sk64::UnitTestWithReporter(void* reporterParam) { + skiatest::Reporter* reporter = (skiatest::Reporter*)reporterParam; -DEF_TEST(Sk64Test, reporter) { enum BoolTests { kZero_BoolTest, kPos_BoolTest, @@ -96,9 +91,7 @@ DEF_TEST(Sk64Test, reporter) { REPORTER_ASSERT(reporter, c.get32() == aa - bb); } -#ifdef SkLONGLONG - for (i = 0; i < 1000; i++) - { + for (i = 0; i < 1000; i++) { rand.next64(&a); //a.fHi >>= 1; // avoid overflow rand.next64(&b); //b.fHi >>= 1; // avoid overflow @@ -113,8 +106,8 @@ DEF_TEST(Sk64Test, reporter) { b.fHi = 0; } - SkLONGLONG aa = asLL(a); - SkLONGLONG bb = asLL(b); + int64_t aa = a.as64(); + int64_t bb = b.as64(); REPORTER_ASSERT(reporter, (a < b) == (aa < bb)); REPORTER_ASSERT(reporter, (a <= b) == (aa <= bb)); @@ -124,31 +117,31 @@ DEF_TEST(Sk64Test, reporter) { REPORTER_ASSERT(reporter, (a != b) == (aa != bb)); c = a; c.add(b); - REPORTER_ASSERT(reporter, asLL(c) == aa + bb); + REPORTER_ASSERT(reporter, c.as64() == aa + bb); c = a; c.sub(b); - REPORTER_ASSERT(reporter, asLL(c) == aa - bb); + REPORTER_ASSERT(reporter, c.as64() == aa - bb); c = a; c.rsub(b); - REPORTER_ASSERT(reporter, asLL(c) == bb - aa); + REPORTER_ASSERT(reporter, c.as64() == bb - aa); c = a; c.negate(); - REPORTER_ASSERT(reporter, asLL(c) == -aa); + REPORTER_ASSERT(reporter, c.as64() == -aa); int bits = rand.nextU() & 63; c = a; c.shiftLeft(bits); - REPORTER_ASSERT(reporter, asLL(c) == (aa << bits)); + REPORTER_ASSERT(reporter, c.as64() == (aa << bits)); c = a; c.shiftRight(bits); - REPORTER_ASSERT(reporter, asLL(c) == (aa >> bits)); + REPORTER_ASSERT(reporter, c.as64() == (aa >> bits)); c = a; c.roundRight(bits); - SkLONGLONG tmp; + int64_t tmp; tmp = aa; if (bits > 0) - tmp += (SkLONGLONG)1 << (bits - 1); - REPORTER_ASSERT(reporter, asLL(c) == (tmp >> bits)); + tmp += (int64_t)1 << (bits - 1); + REPORTER_ASSERT(reporter, c.as64() == (tmp >> bits)); c.setMul(a.fHi, b.fHi); - tmp = (SkLONGLONG)a.fHi * b.fHi; - REPORTER_ASSERT(reporter, asLL(c) == tmp); + tmp = (int64_t)a.fHi * b.fHi; + REPORTER_ASSERT(reporter, c.as64() == tmp); } @@ -160,11 +153,11 @@ DEF_TEST(Sk64Test, reporter) { while (denom == 0) denom = rand.nextS(); wide.setMul(rand.nextS(), rand.nextS()); - SkLONGLONG check = wide.getLongLong(); + int64_t check = wide.getLongLong(); wide.div(denom, Sk64::kTrunc_DivOption); check /= denom; - SkLONGLONG w = wide.getLongLong(); + int64_t w = wide.getLongLong(); REPORTER_ASSERT(reporter, check == w); @@ -175,5 +168,8 @@ DEF_TEST(Sk64Test, reporter) { int diff = denom - ck; REPORTER_ASSERT(reporter, SkAbs32(diff) <= 1); } -#endif +} + +DEF_TEST(Sk64Test, reporter) { + Sk64::UnitTestWithReporter(reporter); } |