Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: src/opts/SkNx_sse.h

Issue 2150343002: Add a bench to measure the best way to pack from int to uint16_t with SSE. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: so tired of this MSVC... Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/pack_int_uint16_t_Bench.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkNx_sse.h
diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h
index ab88382bd2a111ccb4d4ebf082fda6480ce6e560..553ff1de3e9f3d83e8d83b6bb201c054a7580ae7 100644
--- a/src/opts/SkNx_sse.h
+++ b/src/opts/SkNx_sse.h
@@ -323,20 +323,25 @@ template <> /*static*/ inline Sk4i SkNx_cast<int, float>(const Sk4f& src) {
return _mm_cvttps_epi32(src.fVec);
}
-template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, float>(const Sk4f& src) {
- auto _32 = _mm_cvttps_epi32(src.fVec);
- // Ideally we'd use _mm_packus_epi32 here. But that's SSE4.1+.
-#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, int>(const Sk4i& src) {
+#if 0 && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
+ // TODO: This seems to be causing code generation problems. Investigate?
+ return _mm_packus_epi32(src.fVec);
+#elif 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, _,_,_,_,_,_,_,_));
+ return _mm_shuffle_epi8(src.fVec, _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));
+ // With SSE2, we have to sign extend our input, making _mm_packs_epi32 do the pack we want.
+ __m128i x = _mm_srai_epi32(_mm_slli_epi32(src.fVec, 16), 16);
+ return _mm_packs_epi32(x,x);
#endif
}
+template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, float>(const Sk4f& src) {
+ return SkNx_cast<uint16_t>(SkNx_cast<int>(src));
+}
+
template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, float>(const Sk4f& src) {
auto _32 = _mm_cvttps_epi32(src.fVec);
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
@@ -390,14 +395,6 @@ template<> /*static*/ inline Sk4i SkNx_cast<int, uint16_t>(const Sk4h& src) {
return _mm_unpacklo_epi16(src.fVec, _mm_setzero_si128());
}
-template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, int>(const Sk4i& src) {
- // TODO: merge with other work exploring best int -> uint16_t conversion.
-
- // Sign extend to trick _mm_packs_epi32() into doing the pack we want.
- __m128i x = _mm_srai_epi32(_mm_slli_epi32(src.fVec, 16), 16);
- return _mm_packs_epi32(x,x);
-}
-
template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, int>(const Sk4i& src) {
return _mm_packus_epi16(_mm_packus_epi16(src.fVec, src.fVec), src.fVec);
}
« no previous file with comments | « bench/pack_int_uint16_t_Bench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698