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

Side by Side Diff: src/opts/SkPMFloat_SSSE3.h

Issue 977773002: Update SkPMFloat API a bit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 32 Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/opts/SkPMFloat_SSE2.h ('k') | src/opts/SkPMFloat_neon.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "SkColorPriv.h" 1 #include "SkColorPriv.h"
2 #include <tmmintrin.h> 2 #include <tmmintrin.h>
3 3
4 // For set(), we widen our 8 bit components (fix8) to 8-bit components in 32 bit s (fix8_32), 4 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 32 bits
5 // then convert those to floats. 5 // (fix8_32), then convert those to floats.
6 6
7 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t o packed 8 bit. 7 // get() does the opposite, working from floats to 8-bit-in-32-bits, then back t o packed 8 bit.
8 8
9 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi t, with 9 // clamped() is the same as _SSE2: floats to 8-in-32, to 8-in-16, to packed 8 bi t, with
10 // _mm_packus_epi16() both clamping and narrowing. 10 // _mm_packus_epi16() both clamping and narrowing.
11 11
12 inline void SkPMFloat::set(SkPMColor c) { 12 inline SkPMFloat::SkPMFloat(SkPMColor c) {
13 SkPMColorAssert(c); 13 SkPMColorAssert(c);
14 const int _ = 255; // _ means to zero that byte. 14 const int _ = 255; // _ means to zero that byte.
15 __m128i fix8 = _mm_set_epi32(0,0,0,c), 15 __m128i fix8 = _mm_set_epi32(0,0,0,c),
16 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_, _,1, _,_,_,0)); 16 fix8_32 = _mm_shuffle_epi8(fix8, _mm_set_epi8(_,_,_,3, _,_,_,2, _,_, _,1, _,_,_,0));
17 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); 17 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32));
18 SkASSERT(this->isValid()); 18 SkASSERT(this->isValid());
19 } 19 }
20 20
21 inline SkPMColor SkPMFloat::get() const { 21 inline SkPMColor SkPMFloat::get() const {
22 SkASSERT(this->isValid()); 22 SkASSERT(this->isValid());
23 const int _ = 255; // _ means to zero that byte. 23 const int _ = 255; // _ means to zero that byte.
24 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us! 24 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us!
25 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _ ,_,_,_, 12,8,4,0)); 25 fix8 = _mm_shuffle_epi8(fix8_32, _mm_set_epi8(_,_,_,_, _,_,_,_, _ ,_,_,_, 12,8,4,0));
26 SkPMColor c = _mm_cvtsi128_si32(fix8); 26 SkPMColor c = _mm_cvtsi128_si32(fix8);
27 SkPMColorAssert(c); 27 SkPMColorAssert(c);
28 return c; 28 return c;
29 } 29 }
30 30
31 inline SkPMColor SkPMFloat::clamped() const { 31 inline SkPMColor SkPMFloat::clamped() const {
32 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us! 32 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us!
33 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 33 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
34 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 34 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
35 SkPMColor c = _mm_cvtsi128_si32(fix8); 35 SkPMColor c = _mm_cvtsi128_si32(fix8);
36 SkPMColorAssert(c); 36 SkPMColorAssert(c);
37 return c; 37 return c;
38 } 38 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_SSE2.h ('k') | src/opts/SkPMFloat_neon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698