Index: tests/SkNxTest.cpp |
diff --git a/tests/SkNxTest.cpp b/tests/SkNxTest.cpp |
index 5509814c07ee1b6ff27037ef6cd65a12a2fb44ee..51d937dd4dc29b25da65630981cc3417f43ad2eb 100644 |
--- a/tests/SkNxTest.cpp |
+++ b/tests/SkNxTest.cpp |
@@ -288,3 +288,22 @@ DEF_TEST(SkNx_u16_float, r) { |
REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16))); |
} |
} |
+ |
+// The SSE2 implementation of SkNx_cast<uint16_t>(Sk4i) is non-trivial, so worth a test. |
+DEF_TEST(SkNx_int_u16, r) { |
+ // These are pretty hard to get wrong. |
+ for (int i = 0; i <= 0x7fff; i++) { |
+ uint16_t expected = (uint16_t)i; |
+ uint16_t actual = SkNx_cast<uint16_t>(Sk4i(i))[0]; |
+ |
+ REPORTER_ASSERT(r, expected == actual); |
+ } |
+ |
+ // A naive implementation with _mm_packs_epi32 would succeed up to 0x7fff but fail here: |
+ for (int i = 0x8000; (1) && i <= 0xffff; i++) { |
+ uint16_t expected = (uint16_t)i; |
+ uint16_t actual = SkNx_cast<uint16_t>(Sk4i(i))[0]; |
+ |
+ REPORTER_ASSERT(r, expected == actual); |
+ } |
+} |