| 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_DEFINED | 8 #ifndef SkNx_DEFINED |
| 9 #define SkNx_DEFINED | 9 #define SkNx_DEFINED |
| 10 | 10 |
| 11 | 11 |
| 12 #define SKNX_NO_SIMDx // Remove the x to disable SIMD for all SkNx types. | 12 #define SKNX_NO_SIMDx // Remove the x to disable SIMD for all SkNx types. |
| 13 | 13 |
| 14 | 14 |
| 15 #include "SkScalar.h" | 15 #include "SkScalar.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 #include <math.h> | 17 #include <math.h> |
| 18 #define REQUIRE(x) static_assert(x, #x) | 18 #define REQUIRE(x) static_assert(x, #x) |
| 19 | 19 |
| 20 // This file may be included multiple times by .cpp files with different flags,
leading |
| 21 // to different definitions. Usually that doesn't matter because it's all inlin
ed, but |
| 22 // in Debug modes the compilers may not inline everything. So wrap everything i
n an |
| 23 // anonymous namespace to give each includer their own silo of this code (or the
linker |
| 24 // will probably pick one randomly for us, which is rarely correct). |
| 25 namespace { |
| 26 |
| 20 // The default implementations just fall back on a pair of size N/2. | 27 // The default implementations just fall back on a pair of size N/2. |
| 21 | 28 |
| 22 // SkNb is a _very_ minimal class representing a vector of bools returned by com
parison operators. | 29 // SkNb is a _very_ minimal class representing a vector of bools returned by com
parison operators. |
| 23 // We pass along the byte size of the compared types (Bytes) to help platform sp
ecializations. | 30 // We pass along the byte size of the compared types (Bytes) to help platform sp
ecializations. |
| 24 template <int N, int Bytes> | 31 template <int N, int Bytes> |
| 25 class SkNb { | 32 class SkNb { |
| 26 public: | 33 public: |
| 27 SkNb() {} | 34 SkNb() {} |
| 28 SkNb(const SkNb<N/2, Bytes>& lo, const SkNb<N/2, Bytes>& hi) : fLo(lo), fHi(
hi) {} | 35 SkNb(const SkNb<N/2, Bytes>& lo, const SkNb<N/2, Bytes>& hi) : fLo(lo), fHi(
hi) {} |
| 29 | 36 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 251 |
| 245 protected: | 252 protected: |
| 246 // We do double sqrts natively, or via floats for any other type. | 253 // We do double sqrts natively, or via floats for any other type. |
| 247 template <typename U> | 254 template <typename U> |
| 248 static U Sqrt(U val) { return (U) ::sqrtf((float)val); } | 255 static U Sqrt(U val) { return (U) ::sqrtf((float)val); } |
| 249 static double Sqrt(double val) { return ::sqrt ( val); } | 256 static double Sqrt(double val) { return ::sqrt ( val); } |
| 250 | 257 |
| 251 T fVal; | 258 T fVal; |
| 252 }; | 259 }; |
| 253 | 260 |
| 261 } // namespace |
| 254 | 262 |
| 255 // Generic syntax sugar that should work equally well for all implementations. | 263 // Generic syntax sugar that should work equally well for all implementations. |
| 256 template <typename T> T operator - (const T& l) { return T(0) - l; } | 264 template <typename T> T operator - (const T& l) { return T(0) - l; } |
| 257 | 265 |
| 258 template <typename L, typename R> L& operator += (L& l, const R& r) { return (l
= l + r); } | 266 template <typename L, typename R> L& operator += (L& l, const R& r) { return (l
= l + r); } |
| 259 template <typename L, typename R> L& operator -= (L& l, const R& r) { return (l
= l - r); } | 267 template <typename L, typename R> L& operator -= (L& l, const R& r) { return (l
= l - r); } |
| 260 template <typename L, typename R> L& operator *= (L& l, const R& r) { return (l
= l * r); } | 268 template <typename L, typename R> L& operator *= (L& l, const R& r) { return (l
= l * r); } |
| 261 template <typename L, typename R> L& operator /= (L& l, const R& r) { return (l
= l / r); } | 269 template <typename L, typename R> L& operator /= (L& l, const R& r) { return (l
= l / r); } |
| 262 | 270 |
| 263 template <typename L> L& operator <<= (L& l, int bits) { return (l = l << bits);
} | 271 template <typename L> L& operator <<= (L& l, int bits) { return (l = l << bits);
} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 285 typedef SkNi<4, uint16_t> Sk4h; | 293 typedef SkNi<4, uint16_t> Sk4h; |
| 286 typedef SkNi<8, uint16_t> Sk8h; | 294 typedef SkNi<8, uint16_t> Sk8h; |
| 287 typedef SkNi<16, uint16_t> Sk16h; | 295 typedef SkNi<16, uint16_t> Sk16h; |
| 288 | 296 |
| 289 typedef SkNi<16, uint8_t> Sk16b; | 297 typedef SkNi<16, uint8_t> Sk16b; |
| 290 | 298 |
| 291 typedef SkNi<4, int32_t> Sk4i; | 299 typedef SkNi<4, int32_t> Sk4i; |
| 292 typedef SkNi<4, uint32_t> Sk4u; | 300 typedef SkNi<4, uint32_t> Sk4u; |
| 293 | 301 |
| 294 #endif//SkNx_DEFINED | 302 #endif//SkNx_DEFINED |
| OLD | NEW |