diff options
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r-- | tests/MathTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 35b4136b44..0bd3cf5da5 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -9,6 +9,7 @@ #include "SkColorPriv.h" #include "SkEndian.h" +#include "SkFDot6.h" #include "SkFixed.h" #include "SkFloatBits.h" #include "SkFloatingPoint.h" @@ -36,6 +37,38 @@ static void test_clz(skiatest::Reporter* reporter) { } } +static void test_quick_div(skiatest::Reporter* reporter) { + /* + The inverse table is generated by turning on SkDebugf in the following test code + */ + SkFixed storage[kInverseTableSize * 2]; + SkFixed* table = storage + kInverseTableSize; + + // SkDebugf("static const int gFDot6INVERSE[] = {"); + for (SkFDot6 i=-kInverseTableSize; i<kInverseTableSize; i++) { + if (i != 0) { + table[i] = SkFDot6Div(SK_FDot6One, i); + REPORTER_ASSERT(reporter, table[i] == gFDot6INVERSE[i + kInverseTableSize]); + } + // SkDebugf("%d, ", table[i]); + } + // SkDebugf("}\n"); + + + for (SkFDot6 a = -1024; a <= 1024; a++) { + for (SkFDot6 b = -1024; b <= 1024; b++) { + if (b != 0) { + SkFixed ourAnswer = QuickSkFDot6Div(a, b); + SkFixed directAnswer = SkFDot6Div(a, b); + REPORTER_ASSERT(reporter, + (directAnswer == 0 && ourAnswer == 0) || + SkFixedDiv(SkAbs32(directAnswer - ourAnswer), SkAbs32(directAnswer)) <= 1 << 10 + ); + } + } + } +} + /////////////////////////////////////////////////////////////////////////////// static float sk_fsel(float pred, float result_ge, float result_lt) { @@ -576,6 +609,7 @@ DEF_TEST(Math, reporter) { test_muldivround(reporter); test_clz(reporter); + test_quick_div(reporter); } template <typename T> struct PairRec { |