 Chromium Code Reviews
 Chromium Code Reviews Issue 976493002:
  Add SSSE3 implementation for SkPMFloat, with faster get() and set().  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master
    
  
    Issue 976493002:
  Add SSSE3 implementation for SkPMFloat, with faster get() and set().  (Closed) 
  Base URL: https://skia.googlesource.com/skia.git@master| Index: src/opts/SkPMFloat_SSSE3.h | 
| diff --git a/src/opts/SkPMFloat_SSSE3.h b/src/opts/SkPMFloat_SSSE3.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..fb5685c04547d618b6d23dffa07088dadbf084bc | 
| --- /dev/null | 
| +++ b/src/opts/SkPMFloat_SSSE3.h | 
| @@ -0,0 +1,38 @@ | 
| +#include "SkColorPriv.h" | 
| +#include <tmmintrin.h> | 
| + | 
| +// For set(), we widen our 8 bit components (fix8) to 8-bit components in 32 bits (fix8_32), | 
| +// then convert those to floats. | 
| + | 
| +// get() does the opposite, working from floats to 8-bit-in-32-bits, then back to packed 8 bit. | 
| + | 
| +// clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bit, with | 
| +// _mm_packus_epi16() both clamping and narrowing. | 
| + | 
| +inline void SkPMFloat::set(SkPMColor c) { | 
| + SkPMColorAssert(c); | 
| + const int _ = 255; // _ means to zero that byte. | 
| + __m128i fix8 = _mm_set_epi32(0,0,0,c), | 
| + fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_,_,1, _,_,_,0)); | 
| + _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); | 
| 
msarett
2015/03/04 18:06:12
As far as instructions, it looks to me like you ha
 
mtklein
2015/03/04 18:10:24
+1, though keep in mind this code is inlined.   Se
 | 
| + SkASSERT(this->isValid()); | 
| +} | 
| + | 
| +inline SkPMColor SkPMFloat::get() const { | 
| + SkASSERT(this->isValid()); | 
| + const int _ = 255; // _ means to zero that byte. | 
| + __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us! | 
| + fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _,_,_,_, 12,8,4,0)); | 
| + SkPMColor c = _mm_cvtsi128_si32(fix8); | 
| + SkPMColorAssert(c); | 
| + return c; | 
| +} | 
| + | 
| +inline SkPMColor SkPMFloat::clamped() const { | 
| + __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us! | 
| + fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), | 
| 
msarett
2015/03/04 18:06:12
For lack of anything to comment on, it might be mo
 
mtklein
2015/03/04 18:10:24
Yeah.  I'd have done that, just for the readabilit
 | 
| + fix8 = _mm_packus_epi16(fix8_16, fix8_16); | 
| + SkPMColor c = _mm_cvtsi128_si32(fix8); | 
| + SkPMColorAssert(c); | 
| + return c; | 
| +} |