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

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

Issue 1464623002: Add SkNx_cast(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: derp, is stands for _ints_ 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/core/SkNx.h ('k') | src/opts/SkNx_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 /* 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_avx_DEFINED 8 #ifndef SkNx_avx_DEFINED
9 #define SkNx_avx_DEFINED 9 #define SkNx_avx_DEFINED
10 10
11 // This file may assume <= AVX, but must check SK_CPU_SSE_LEVEL for anything mor e recent. 11 // This file may assume <= AVX, but must check SK_CPU_SSE_LEVEL for anything mor e recent.
12 12
13 // All the SSE specializations are still good ideas. We'll just add Sk8f. 13 // All the SSE specializations are still good ideas. We'll just add Sk8f.
14 #include "SkNx_sse.h" 14 #include "SkNx_sse.h"
15 15
16 namespace { // See SkNx.h 16 namespace { // See SkNx.h
17 17
18 template <> 18 template <>
19 class SkNf<8> { 19 class SkNx<8, float> {
20 public: 20 public:
21 SkNf(const __m256& vec) : fVec(vec) {} 21 SkNx(const __m256& vec) : fVec(vec) {}
22 22
23 SkNf() {} 23 SkNx() {}
24 SkNf(float val) : fVec(_mm256_set1_ps(val)) {} 24 SkNx(float val) : fVec(_mm256_set1_ps(val)) {}
25 static SkNf Load(const float vals[8]) { return _mm256_loadu_ps(vals); } 25 static SkNx Load(const float vals[8]) { return _mm256_loadu_ps(vals); }
26 26
27 static SkNf FromBytes(const uint8_t bytes[8]) { 27 static SkNx FromBytes(const uint8_t bytes[8]) {
28 __m128i fix8 = _mm_loadl_epi64((const __m128i*)bytes), 28 __m128i fix8 = _mm_loadl_epi64((const __m128i*)bytes),
29 fix16 = _mm_unpacklo_epi8 (fix8 , _mm_setzero_si128()), 29 fix16 = _mm_unpacklo_epi8 (fix8 , _mm_setzero_si128()),
30 lo32 = _mm_unpacklo_epi16(fix16, _mm_setzero_si128()), 30 lo32 = _mm_unpacklo_epi16(fix16, _mm_setzero_si128()),
31 hi32 = _mm_unpackhi_epi16(fix16, _mm_setzero_si128()); 31 hi32 = _mm_unpackhi_epi16(fix16, _mm_setzero_si128());
32 __m256i fix32 = _mm256_insertf128_si256(_mm256_castsi128_si256(lo32), hi 32, 1); 32 __m256i fix32 = _mm256_insertf128_si256(_mm256_castsi128_si256(lo32), hi 32, 1);
33 return _mm256_cvtepi32_ps(fix32); 33 return _mm256_cvtepi32_ps(fix32);
34 } 34 }
35 35
36 SkNf(float a, float b, float c, float d, 36 SkNx(float a, float b, float c, float d,
37 float e, float f, float g, float h) : fVec(_mm256_setr_ps(a,b,c,d,e,f,g ,h)) {} 37 float e, float f, float g, float h) : fVec(_mm256_setr_ps(a,b,c,d,e,f,g ,h)) {}
38 38
39 void store(float vals[8]) const { _mm256_storeu_ps(vals, fVec); } 39 void store(float vals[8]) const { _mm256_storeu_ps(vals, fVec); }
40 void toBytes(uint8_t bytes[8]) const { 40 void toBytes(uint8_t bytes[8]) const {
41 __m256i fix32 = _mm256_cvttps_epi32(fVec); 41 __m256i fix32 = _mm256_cvttps_epi32(fVec);
42 __m128i lo32 = _mm256_extractf128_si256(fix32, 0), 42 __m128i lo32 = _mm256_extractf128_si256(fix32, 0),
43 hi32 = _mm256_extractf128_si256(fix32, 1), 43 hi32 = _mm256_extractf128_si256(fix32, 1),
44 fix16 = _mm_packus_epi32(lo32, hi32), 44 fix16 = _mm_packus_epi32(lo32, hi32),
45 fix8 = _mm_packus_epi16(fix16, fix16); 45 fix8 = _mm_packus_epi16(fix16, fix16);
46 _mm_storel_epi64((__m128i*)bytes, fix8); 46 _mm_storel_epi64((__m128i*)bytes, fix8);
47 } 47 }
48 48
49 SkNf operator + (const SkNf& o) const { return _mm256_add_ps(fVec, o.fVec); } 49 SkNx operator + (const SkNx& o) const { return _mm256_add_ps(fVec, o.fVec); }
50 SkNf operator - (const SkNf& o) const { return _mm256_sub_ps(fVec, o.fVec); } 50 SkNx operator - (const SkNx& o) const { return _mm256_sub_ps(fVec, o.fVec); }
51 SkNf operator * (const SkNf& o) const { return _mm256_mul_ps(fVec, o.fVec); } 51 SkNx operator * (const SkNx& o) const { return _mm256_mul_ps(fVec, o.fVec); }
52 SkNf operator / (const SkNf& o) const { return _mm256_div_ps(fVec, o.fVec); } 52 SkNx operator / (const SkNx& o) const { return _mm256_div_ps(fVec, o.fVec); }
53 53
54 SkNf operator == (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_EQ_OQ); } 54 SkNx operator == (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_EQ_OQ); }
55 SkNf operator != (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_NEQ_OQ); } 55 SkNx operator != (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_NEQ_OQ); }
56 SkNf operator < (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_LT_OQ); } 56 SkNx operator < (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_LT_OQ); }
57 SkNf operator > (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_GT_OQ); } 57 SkNx operator > (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_GT_OQ); }
58 SkNf operator <= (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_LE_OQ); } 58 SkNx operator <= (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_LE_OQ); }
59 SkNf operator >= (const SkNf& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_GE_OQ); } 59 SkNx operator >= (const SkNx& o) const { return _mm256_cmp_ps(fVec, o.fVec, _CMP_GE_OQ); }
60 60
61 static SkNf Min(const SkNf& l, const SkNf& r) { return _mm256_min_ps(l.fVec, r.fVec); } 61 static SkNx Min(const SkNx& l, const SkNx& r) { return _mm256_min_ps(l.fVec, r.fVec); }
62 static SkNf Max(const SkNf& l, const SkNf& r) { return _mm256_max_ps(l.fVec, r.fVec); } 62 static SkNx Max(const SkNx& l, const SkNx& r) { return _mm256_max_ps(l.fVec, r.fVec); }
63 63
64 SkNf sqrt() const { return _mm256_sqrt_ps (fVec); } 64 SkNx sqrt() const { return _mm256_sqrt_ps (fVec); }
65 SkNf rsqrt0() const { return _mm256_rsqrt_ps(fVec); } 65 SkNx rsqrt0() const { return _mm256_rsqrt_ps(fVec); }
66 SkNf rsqrt1() const { return this->rsqrt0(); } 66 SkNx rsqrt1() const { return this->rsqrt0(); }
67 SkNf rsqrt2() const { return this->rsqrt1(); } 67 SkNx rsqrt2() const { return this->rsqrt1(); }
68 68
69 SkNf invert() const { return SkNf(1) / *this; } 69 SkNx invert() const { return SkNx(1) / *this; }
70 SkNf approxInvert() const { return _mm256_rcp_ps(fVec); } 70 SkNx approxInvert() const { return _mm256_rcp_ps(fVec); }
71 71
72 template <int k> float kth() const { 72 template <int k> float kth() const {
73 SkASSERT(0 <= k && k < 8); 73 SkASSERT(0 <= k && k < 8);
74 union { __m256 v; float fs[8]; } pun = {fVec}; 74 union { __m256 v; float fs[8]; } pun = {fVec};
75 return pun.fs[k&7]; 75 return pun.fs[k&7];
76 } 76 }
77 77
78 bool allTrue() const { return 0xff == _mm256_movemask_ps(fVec); } 78 bool allTrue() const { return 0xff == _mm256_movemask_ps(fVec); }
79 bool anyTrue() const { return 0x00 != _mm256_movemask_ps(fVec); } 79 bool anyTrue() const { return 0x00 != _mm256_movemask_ps(fVec); }
80 80
81 SkNf thenElse(const SkNf& t, const SkNf& e) const { 81 SkNx thenElse(const SkNx& t, const SkNx& e) const {
82 return _mm256_blendv_ps(e.fVec, t.fVec, fVec); 82 return _mm256_blendv_ps(e.fVec, t.fVec, fVec);
83 } 83 }
84 84
85 __m256 fVec; 85 __m256 fVec;
86 }; 86 };
87 87
88 } // namespace 88 } // namespace
89 89
90 #endif//SkNx_avx_DEFINED 90 #endif//SkNx_avx_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkNx.h ('k') | src/opts/SkNx_neon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698