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

Side by Side Diff: src/opts/SkPMFloat_SSE2.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/core/SkPMFloat.h ('k') | src/opts/SkPMFloat_SSSE3.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 <emmintrin.h> 2 #include <emmintrin.h>
3 3
4 // For set(), we widen our 8 bit components (fix8) to 8-bit components in 16 bit s (fix8_16), 4 // For SkPMFloat(SkPMColor), we widen our 8 bit components (fix8) to 8-bit compo nents in 16 bits
5 // then widen those to 8-bit-in-32-bits (fix8_32), and finally convert those to floats. 5 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats.
6 6
7 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, 7 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit,
8 // to 8-bit-in-16-bit, back down to 8-bit components. 8 // to 8-bit-in-16-bit, back down to 8-bit components.
9 // _mm_packus_epi16() gives us clamping for free while narrowing. 9 // _mm_packus_epi16() gives us clamping for free while narrowing.
10 10
11 inline void SkPMFloat::set(SkPMColor c) { 11 inline SkPMFloat::SkPMFloat(SkPMColor c) {
12 SkPMColorAssert(c); 12 SkPMColorAssert(c);
13 __m128i fix8 = _mm_set_epi32(0,0,0,c), 13 __m128i fix8 = _mm_set_epi32(0,0,0,c),
14 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()), 14 fix8_16 = _mm_unpacklo_epi8 (fix8, _mm_setzero_si128()),
15 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128()); 15 fix8_32 = _mm_unpacklo_epi16(fix8_16, _mm_setzero_si128());
16 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32)); 16 _mm_store_ps(fColor, _mm_cvtepi32_ps(fix8_32));
17 SkASSERT(this->isValid()); 17 SkASSERT(this->isValid());
18 } 18 }
19 19
20 inline SkPMColor SkPMFloat::get() const { 20 inline SkPMColor SkPMFloat::get() const {
21 SkASSERT(this->isValid()); 21 SkASSERT(this->isValid());
22 return this->clamped(); // At the moment, we don't know anything faster. 22 return this->clamped(); // At the moment, we don't know anything faster.
23 } 23 }
24 24
25 inline SkPMColor SkPMFloat::clamped() const { 25 inline SkPMColor SkPMFloat::clamped() const {
26 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us! 26 __m128i fix8_32 = _mm_cvtps_epi32(_mm_load_ps(fColor)), // _mm_cvtps_epi32 rounds for us!
27 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32), 27 fix8_16 = _mm_packus_epi16(fix8_32, fix8_32),
28 fix8 = _mm_packus_epi16(fix8_16, fix8_16); 28 fix8 = _mm_packus_epi16(fix8_16, fix8_16);
29 SkPMColor c = _mm_cvtsi128_si32(fix8); 29 SkPMColor c = _mm_cvtsi128_si32(fix8);
30 SkPMColorAssert(c); 30 SkPMColorAssert(c);
31 return c; 31 return c;
32 } 32 }
OLDNEW
« no previous file with comments | « src/core/SkPMFloat.h ('k') | src/opts/SkPMFloat_SSSE3.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698