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

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

Issue 1714363002: SkNx: kth<...>() -> [...] (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: the rest Created 4 years, 10 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/SkNx_neon.h ('k') | src/opts/SkXfermode_opts.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 #ifndef SkNx_sse_DEFINED 8 #ifndef SkNx_sse_DEFINED
9 #define SkNx_sse_DEFINED 9 #define SkNx_sse_DEFINED
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SkNx rsqrt2() const { return this->rsqrt1(); } 58 SkNx rsqrt2() const { return this->rsqrt1(); }
59 59
60 SkNx invert() const { return SkNx(1) / *this; } 60 SkNx invert() const { return SkNx(1) / *this; }
61 SkNx approxInvert() const { return _mm_rcp_ps(fVec); } 61 SkNx approxInvert() const { return _mm_rcp_ps(fVec); }
62 62
63 float operator[](int k) const { 63 float operator[](int k) const {
64 SkASSERT(0 <= k && k < 2); 64 SkASSERT(0 <= k && k < 2);
65 union { __m128 v; float fs[4]; } pun = {fVec}; 65 union { __m128 v; float fs[4]; } pun = {fVec};
66 return pun.fs[k&1]; 66 return pun.fs[k&1];
67 } 67 }
68 template <int k> float kth() const { return (*this)[k]; }
69 68
70 bool allTrue() const { return 0xff == (_mm_movemask_epi8(_mm_castps_si128(fV ec)) & 0xff); } 69 bool allTrue() const { return 0xff == (_mm_movemask_epi8(_mm_castps_si128(fV ec)) & 0xff); }
71 bool anyTrue() const { return 0x00 != (_mm_movemask_epi8(_mm_castps_si128(fV ec)) & 0xff); } 70 bool anyTrue() const { return 0x00 != (_mm_movemask_epi8(_mm_castps_si128(fV ec)) & 0xff); }
72 71
73 __m128 fVec; 72 __m128 fVec;
74 }; 73 };
75 74
76 template <> 75 template <>
77 class SkNx<4, float> { 76 class SkNx<4, float> {
78 public: 77 public:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 SkNx rsqrt2() const { return this->rsqrt1(); } 109 SkNx rsqrt2() const { return this->rsqrt1(); }
111 110
112 SkNx invert() const { return SkNx(1) / *this; } 111 SkNx invert() const { return SkNx(1) / *this; }
113 SkNx approxInvert() const { return _mm_rcp_ps(fVec); } 112 SkNx approxInvert() const { return _mm_rcp_ps(fVec); }
114 113
115 float operator[](int k) const { 114 float operator[](int k) const {
116 SkASSERT(0 <= k && k < 4); 115 SkASSERT(0 <= k && k < 4);
117 union { __m128 v; float fs[4]; } pun = {fVec}; 116 union { __m128 v; float fs[4]; } pun = {fVec};
118 return pun.fs[k&3]; 117 return pun.fs[k&3];
119 } 118 }
120 template <int k> float kth() const { return (*this)[k]; }
121 119
122 bool allTrue() const { return 0xffff == _mm_movemask_epi8(_mm_castps_si128(f Vec)); } 120 bool allTrue() const { return 0xffff == _mm_movemask_epi8(_mm_castps_si128(f Vec)); }
123 bool anyTrue() const { return 0x0000 != _mm_movemask_epi8(_mm_castps_si128(f Vec)); } 121 bool anyTrue() const { return 0x0000 != _mm_movemask_epi8(_mm_castps_si128(f Vec)); }
124 122
125 SkNx thenElse(const SkNx& t, const SkNx& e) const { 123 SkNx thenElse(const SkNx& t, const SkNx& e) const {
126 return _mm_or_ps(_mm_and_ps (fVec, t.fVec), 124 return _mm_or_ps(_mm_and_ps (fVec, t.fVec),
127 _mm_andnot_ps(fVec, e.fVec)); 125 _mm_andnot_ps(fVec, e.fVec));
128 } 126 }
129 127
130 __m128 fVec; 128 __m128 fVec;
(...skipping 21 matching lines...) Expand all
152 } 150 }
153 151
154 SkNx operator << (int bits) const { return _mm_slli_epi32(fVec, bits); } 152 SkNx operator << (int bits) const { return _mm_slli_epi32(fVec, bits); }
155 SkNx operator >> (int bits) const { return _mm_srai_epi32(fVec, bits); } 153 SkNx operator >> (int bits) const { return _mm_srai_epi32(fVec, bits); }
156 154
157 int operator[](int k) const { 155 int operator[](int k) const {
158 SkASSERT(0 <= k && k < 4); 156 SkASSERT(0 <= k && k < 4);
159 union { __m128i v; int is[4]; } pun = {fVec}; 157 union { __m128i v; int is[4]; } pun = {fVec};
160 return pun.is[k&3]; 158 return pun.is[k&3];
161 } 159 }
162 template <int k> int kth() const { return (*this)[k]; }
163 160
164 __m128i fVec; 161 __m128i fVec;
165 }; 162 };
166 163
167 template <> 164 template <>
168 class SkNx<4, uint16_t> { 165 class SkNx<4, uint16_t> {
169 public: 166 public:
170 SkNx(const __m128i& vec) : fVec(vec) {} 167 SkNx(const __m128i& vec) : fVec(vec) {}
171 168
172 SkNx() {} 169 SkNx() {}
173 SkNx(uint16_t val) : fVec(_mm_set1_epi16(val)) {} 170 SkNx(uint16_t val) : fVec(_mm_set1_epi16(val)) {}
174 static SkNx Load(const void* ptr) { return _mm_loadl_epi64((const __m128i*)p tr); } 171 static SkNx Load(const void* ptr) { return _mm_loadl_epi64((const __m128i*)p tr); }
175 SkNx(uint16_t a, uint16_t b, uint16_t c, uint16_t d) : fVec(_mm_setr_epi16(a ,b,c,d,0,0,0,0)) {} 172 SkNx(uint16_t a, uint16_t b, uint16_t c, uint16_t d) : fVec(_mm_setr_epi16(a ,b,c,d,0,0,0,0)) {}
176 173
177 void store(void* ptr) const { _mm_storel_epi64((__m128i*)ptr, fVec); } 174 void store(void* ptr) const { _mm_storel_epi64((__m128i*)ptr, fVec); }
178 175
179 SkNx operator + (const SkNx& o) const { return _mm_add_epi16(fVec, o.fVec); } 176 SkNx operator + (const SkNx& o) const { return _mm_add_epi16(fVec, o.fVec); }
180 SkNx operator - (const SkNx& o) const { return _mm_sub_epi16(fVec, o.fVec); } 177 SkNx operator - (const SkNx& o) const { return _mm_sub_epi16(fVec, o.fVec); }
181 SkNx operator * (const SkNx& o) const { return _mm_mullo_epi16(fVec, o.fVec) ; } 178 SkNx operator * (const SkNx& o) const { return _mm_mullo_epi16(fVec, o.fVec) ; }
182 179
183 SkNx operator << (int bits) const { return _mm_slli_epi16(fVec, bits); } 180 SkNx operator << (int bits) const { return _mm_slli_epi16(fVec, bits); }
184 SkNx operator >> (int bits) const { return _mm_srli_epi16(fVec, bits); } 181 SkNx operator >> (int bits) const { return _mm_srli_epi16(fVec, bits); }
185 182
186 uint16_t operator[](int k) const { 183 uint16_t operator[](int k) const {
187 SkASSERT(0 <= k && k < 4); 184 SkASSERT(0 <= k && k < 4);
188 union { __m128i v; uint16_t us[8]; } pun = {fVec}; 185 union { __m128i v; uint16_t us[8]; } pun = {fVec};
189 return pun.us[k&3]; 186 return pun.us[k&3];
190 } 187 }
191 template <int k> uint16_t kth() const { return (*this)[k]; }
192 188
193 __m128i fVec; 189 __m128i fVec;
194 }; 190 };
195 191
196 template <> 192 template <>
197 class SkNx<8, uint16_t> { 193 class SkNx<8, uint16_t> {
198 public: 194 public:
199 SkNx(const __m128i& vec) : fVec(vec) {} 195 SkNx(const __m128i& vec) : fVec(vec) {}
200 196
201 SkNx() {} 197 SkNx() {}
(...skipping 23 matching lines...) Expand all
225 SkNx thenElse(const SkNx& t, const SkNx& e) const { 221 SkNx thenElse(const SkNx& t, const SkNx& e) const {
226 return _mm_or_si128(_mm_and_si128 (fVec, t.fVec), 222 return _mm_or_si128(_mm_and_si128 (fVec, t.fVec),
227 _mm_andnot_si128(fVec, e.fVec)); 223 _mm_andnot_si128(fVec, e.fVec));
228 } 224 }
229 225
230 uint16_t operator[](int k) const { 226 uint16_t operator[](int k) const {
231 SkASSERT(0 <= k && k < 8); 227 SkASSERT(0 <= k && k < 8);
232 union { __m128i v; uint16_t us[8]; } pun = {fVec}; 228 union { __m128i v; uint16_t us[8]; } pun = {fVec};
233 return pun.us[k&7]; 229 return pun.us[k&7];
234 } 230 }
235 template <int k> uint16_t kth() const { return (*this)[k]; }
236 231
237 __m128i fVec; 232 __m128i fVec;
238 }; 233 };
239 234
240 template <> 235 template <>
241 class SkNx<4, uint8_t> { 236 class SkNx<4, uint8_t> {
242 public: 237 public:
243 SkNx(const __m128i& vec) : fVec(vec) {} 238 SkNx(const __m128i& vec) : fVec(vec) {}
244 239
245 SkNx() {} 240 SkNx() {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // There's no unsigned _mm_cmplt_epu8, so we flip the sign bits then use a signed compare. 272 // There's no unsigned _mm_cmplt_epu8, so we flip the sign bits then use a signed compare.
278 auto flip = _mm_set1_epi8(char(0x80)); 273 auto flip = _mm_set1_epi8(char(0x80));
279 return _mm_cmplt_epi8(_mm_xor_si128(flip, fVec), _mm_xor_si128(flip, o.f Vec)); 274 return _mm_cmplt_epi8(_mm_xor_si128(flip, fVec), _mm_xor_si128(flip, o.f Vec));
280 } 275 }
281 276
282 uint8_t operator[](int k) const { 277 uint8_t operator[](int k) const {
283 SkASSERT(0 <= k && k < 16); 278 SkASSERT(0 <= k && k < 16);
284 union { __m128i v; uint8_t us[16]; } pun = {fVec}; 279 union { __m128i v; uint8_t us[16]; } pun = {fVec};
285 return pun.us[k&15]; 280 return pun.us[k&15];
286 } 281 }
287 template <int k> uint8_t kth() const { return (*this)[k]; }
288 282
289 SkNx thenElse(const SkNx& t, const SkNx& e) const { 283 SkNx thenElse(const SkNx& t, const SkNx& e) const {
290 return _mm_or_si128(_mm_and_si128 (fVec, t.fVec), 284 return _mm_or_si128(_mm_and_si128 (fVec, t.fVec),
291 _mm_andnot_si128(fVec, e.fVec)); 285 _mm_andnot_si128(fVec, e.fVec));
292 } 286 }
293 287
294 __m128i fVec; 288 __m128i fVec;
295 }; 289 };
296 290
297 template<> /*static*/ inline Sk4f SkNx_cast<float, int>(const Sk4i& src) { 291 template<> /*static*/ inline Sk4f SkNx_cast<float, int>(const Sk4i& src) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 348
355 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) { 349 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) {
356 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128()); 350 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128());
357 } 351 }
358 352
359 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) { 353 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) {
360 return _mm_packus_epi16(src.fVec, src.fVec); 354 return _mm_packus_epi16(src.fVec, src.fVec);
361 } 355 }
362 356
363 #endif//SkNx_sse_DEFINED 357 #endif//SkNx_sse_DEFINED
OLDNEW
« no previous file with comments | « src/opts/SkNx_neon.h ('k') | src/opts/SkXfermode_opts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698