diff options
author | 2016-02-08 05:54:38 -0800 | |
---|---|---|
committer | 2016-02-08 05:54:38 -0800 | |
commit | 629f25a7ef229d97e22530eae043882b20cd8d8c (patch) | |
tree | f45890121140e9750c38e0f26964e9a45bb06665 /src/opts/SkNx_sse.h | |
parent | a58ec2162c0a1e0c934d4ce485019303c51349a4 (diff) |
fix float <---> uint16_t conversion, with Mike's tests.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1679713002
patch from issue 1679713002 at patchset 1 (http://crrev.com/1679713002#ps1)
CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot
Review URL: https://codereview.chromium.org/1676893002
Diffstat (limited to 'src/opts/SkNx_sse.h')
-rw-r--r-- | src/opts/SkNx_sse.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h index ee6fdc5654..10db1c438f 100644 --- a/src/opts/SkNx_sse.h +++ b/src/opts/SkNx_sse.h @@ -350,7 +350,16 @@ template<> inline Sk4i SkNx_cast<int, float, 4>(const Sk4f& src) { template<> inline Sk4h SkNx_cast<uint16_t, float, 4>(const Sk4f& src) { auto _32 = _mm_cvttps_epi32(src.fVec); - return _mm_packus_epi16(_32, _32); + // Ideally we'd use _mm_packus_epi32 here. But that's SSE4.1+. +#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 + // With SSSE3, we can just shuffle the low 2 bytes from each lane right into place. + const int _ = ~0; + return _mm_shuffle_epi8(_32, _mm_setr_epi8(0,1, 4,5, 8,9, 12,13, _,_,_,_,_,_,_,_)); +#else + // With SSE2, we have to emulate _mm_packus_epi32 with _mm_packs_epi32: + _32 = _mm_sub_epi32(_32, _mm_set1_epi32((int)0x00008000)); + return _mm_add_epi16(_mm_packs_epi32(_32, _32), _mm_set1_epi16((short)0x8000)); +#endif } template<> inline Sk4b SkNx_cast<uint8_t, float, 4>(const Sk4f& src) { |