OLD | NEW |
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 private: | 140 private: |
141 __m128d fVec; | 141 __m128d fVec; |
142 }; | 142 }; |
143 | 143 |
144 template <> | 144 template <> |
145 class SkNf<4, float> { | 145 class SkNf<4, float> { |
146 typedef SkNi<4, int32_t> Ni; | 146 typedef SkNi<4, int32_t> Ni; |
147 public: | 147 public: |
148 SkNf(const __m128& vec) : fVec(vec) {} | 148 SkNf(const __m128& vec) : fVec(vec) {} |
| 149 __m128 vec() const { return fVec; } |
149 | 150 |
150 SkNf() {} | 151 SkNf() {} |
151 explicit SkNf(float val) : fVec( _mm_set1_ps(val) ) {} | 152 explicit SkNf(float val) : fVec( _mm_set1_ps(val) ) {} |
152 static SkNf Load(const float vals[4]) { return _mm_loadu_ps(vals); } | 153 static SkNf Load(const float vals[4]) { return _mm_loadu_ps(vals); } |
153 SkNf(float a, float b, float c, float d) : fVec(_mm_setr_ps(a,b,c,d)) {} | 154 SkNf(float a, float b, float c, float d) : fVec(_mm_setr_ps(a,b,c,d)) {} |
154 | 155 |
155 void store(float vals[4]) const { _mm_storeu_ps(vals, fVec); } | 156 void store(float vals[4]) const { _mm_storeu_ps(vals, fVec); } |
156 | 157 |
157 SkNf operator + (const SkNf& o) const { return _mm_add_ps(fVec, o.fVec); } | 158 SkNf operator + (const SkNf& o) const { return _mm_add_ps(fVec, o.fVec); } |
158 SkNf operator - (const SkNf& o) const { return _mm_sub_ps(fVec, o.fVec); } | 159 SkNf operator - (const SkNf& o) const { return _mm_sub_ps(fVec, o.fVec); } |
(...skipping 15 matching lines...) Expand all Loading... |
174 | 175 |
175 SkNf invert() const { return SkNf(1) / *this; } | 176 SkNf invert() const { return SkNf(1) / *this; } |
176 SkNf approxInvert() const { return _mm_rcp_ps(fVec); } | 177 SkNf approxInvert() const { return _mm_rcp_ps(fVec); } |
177 | 178 |
178 template <int k> float kth() const { | 179 template <int k> float kth() const { |
179 SkASSERT(0 <= k && k < 4); | 180 SkASSERT(0 <= k && k < 4); |
180 union { __m128 v; float fs[4]; } pun = {fVec}; | 181 union { __m128 v; float fs[4]; } pun = {fVec}; |
181 return pun.fs[k&3]; | 182 return pun.fs[k&3]; |
182 } | 183 } |
183 | 184 |
184 protected: | 185 private: |
185 __m128 fVec; | 186 __m128 fVec; |
186 }; | 187 }; |
187 | 188 |
188 | 189 |
189 #endif//SkNx_sse_DEFINED | 190 #endif//SkNx_sse_DEFINED |
OLD | NEW |