From 27e517ae533775889c98c65fa2f07b98357ecbc2 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 14 May 2015 17:53:04 -0700 Subject: add Min to SkNi, specialized for u8 and u16 on SSE and NEON 0x8001 / 0x7fff don't seem to work, but we were close: 0x8000 does. I plan to use this to implement the Difference xfermode, and it seems generally handy. BUG=skia: Review URL: https://codereview.chromium.org/1133933004 --- tests/SkNxTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/SkNxTest.cpp') diff --git a/tests/SkNxTest.cpp b/tests/SkNxTest.cpp index dec7329c2c..f8801500db 100644 --- a/tests/SkNxTest.cpp +++ b/tests/SkNxTest.cpp @@ -6,6 +6,7 @@ */ #include "SkNx.h" +#include "SkRandom.h" #include "Test.h" template @@ -130,3 +131,26 @@ DEF_TEST(SkNi, r) { test_Ni<4, int>(r); test_Ni<8, int>(r); } + +DEF_TEST(SkNi_min, r) { + // Exhaustively check the 8x8 bit space. + for (int a = 0; a < (1<<8); a++) { + for (int b = 0; b < (1<<8); b++) { + REPORTER_ASSERT(r, Sk16b::Min(Sk16b(a), Sk16b(b)).kth<0>() == SkTMin(a, b)); + }} + + // Exhausting the 16x16 bit space is kind of slow, so only do that in release builds. +#ifdef SK_DEBUG + SkRandom rand; + for (int i = 0; i < (1<<16); i++) { + uint16_t a = rand.nextU() >> 16, + b = rand.nextU() >> 16; + REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b)); + } +#else + for (int a = 0; a < (1<<16); a++) { + for (int b = 0; b < (1<<16); b++) { + REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b)); + }} +#endif +} -- cgit v1.2.3