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

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

Issue 1452903004: div255(x) as ((x+128)*257)>>16 with SSE (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: notes Created 5 years, 1 month 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/Sk4px_NEON.h ('k') | src/opts/Sk4px_none.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 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 namespace { // See Sk4px.h 8 namespace { // See Sk4px.h
9 9
10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); } 10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); }
(...skipping 27 matching lines...) Expand all
38 38
39 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { 39 inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const {
40 return this->widenLo() * Sk4px(other).widenLo(); 40 return this->widenLo() * Sk4px(other).widenLo();
41 } 41 }
42 42
43 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { 43 inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const {
44 Sk4px::Wide r = (*this + other) >> 8; 44 Sk4px::Wide r = (*this + other) >> 8;
45 return Sk4px(_mm_packus_epi16(r.fLo.fVec, r.fHi.fVec)); 45 return Sk4px(_mm_packus_epi16(r.fLo.fVec, r.fHi.fVec));
46 } 46 }
47 47
48 inline Sk4px Sk4px::Wide::div255() const {
49 // (x + 127) / 255 == ((x+128) * 257)>>16,
50 // and _mm_mulhi_epu16 makes the (_ * 257)>>16 part very convenient.
51 const __m128i _128 = _mm_set1_epi16(128),
52 _257 = _mm_set1_epi16(257);
53 return Sk4px(_mm_packus_epi16(_mm_mulhi_epu16(_mm_add_epi16(fLo.fVec, _128), _257),
54 _mm_mulhi_epu16(_mm_add_epi16(fHi.fVec, _128), _257)));
55 }
56
48 // Load4Alphas and Load2Alphas use possibly-unaligned loads (SkAlpha[] -> uint16 _t or uint32_t). 57 // Load4Alphas and Load2Alphas use possibly-unaligned loads (SkAlpha[] -> uint16 _t or uint32_t).
49 // These are safe on x86, often with no speed penalty. 58 // These are safe on x86, often with no speed penalty.
50 59
51 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 60 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
52 inline Sk4px Sk4px::alphas() const { 61 inline Sk4px Sk4px::alphas() const {
53 static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian."); 62 static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian.");
54 __m128i splat = _mm_set_epi8(15,15,15,15, 11,11,11,11, 7,7,7,7, 3,3,3,3) ; 63 __m128i splat = _mm_set_epi8(15,15,15,15, 11,11,11,11, 7,7,7,7, 3,3,3,3) ;
55 return Sk16b(_mm_shuffle_epi8(this->fVec, splat)); 64 return Sk16b(_mm_shuffle_epi8(this->fVec, splat));
56 } 65 }
57 66
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec)); 170 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec));
162 dst[0] = dst2; 171 dst[0] = dst2;
163 dst[1] = dst2 >> 16; 172 dst[1] = dst2 >> 16;
164 } 173 }
165 inline void Sk4px::store1(SkPMColor16 dst[1]) const { 174 inline void Sk4px::store1(SkPMColor16 dst[1]) const {
166 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec)); 175 uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec));
167 dst[0] = dst2; 176 dst[0] = dst2;
168 } 177 }
169 178
170 } // namespace 179 } // namespace
OLDNEW
« no previous file with comments | « src/opts/Sk4px_NEON.h ('k') | src/opts/Sk4px_none.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698