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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 fHi.store(vals+N/2); | 43 fHi.store(vals+N/2); |
44 } | 44 } |
45 | 45 |
46 #define OP(op) SkNx operator op(const SkNx& o) const { return {fLo op o.fLo, fHi
op o.fHi}; } | 46 #define OP(op) SkNx operator op(const SkNx& o) const { return {fLo op o.fLo, fHi
op o.fHi}; } |
47 OP(+) OP(-) OP(*) OP(/) | 47 OP(+) OP(-) OP(*) OP(/) |
48 OP(&) OP(|) OP(^) | 48 OP(&) OP(|) OP(^) |
49 OP(==) OP(!=) OP(<) OP(>) OP(<=) OP(>=) | 49 OP(==) OP(!=) OP(<) OP(>) OP(<=) OP(>=) |
50 #undef OP | 50 #undef OP |
51 | 51 |
52 #define OP(op) SkNx op() const { return {fLo.op(), fHi.op()}; } | 52 #define OP(op) SkNx op() const { return {fLo.op(), fHi.op()}; } |
53 OP(abs) | 53 OP(abs) OP(floor) |
54 OP(sqrt) OP(rsqrt0) OP(rsqrt1) OP(rsqrt2) | 54 OP(sqrt) OP(rsqrt0) OP(rsqrt1) OP(rsqrt2) |
55 OP(invert) OP(approxInvert) | 55 OP(invert) OP(approxInvert) |
56 #undef OP | 56 #undef OP |
57 | 57 |
58 SkNx operator << (int bits) const { return SkNx(fLo << bits, fHi << bits); } | 58 SkNx operator << (int bits) const { return SkNx(fLo << bits, fHi << bits); } |
59 SkNx operator >> (int bits) const { return SkNx(fLo >> bits, fHi >> bits); } | 59 SkNx operator >> (int bits) const { return SkNx(fLo >> bits, fHi >> bits); } |
60 | 60 |
61 SkNx saturatedAdd(const SkNx& o) const { | 61 SkNx saturatedAdd(const SkNx& o) const { |
62 return {fLo.saturatedAdd(o.fLo), fHi.saturatedAdd(o.fHi)}; | 62 return {fLo.saturatedAdd(o.fLo), fHi.saturatedAdd(o.fHi)}; |
63 } | 63 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 SkNx saturatedAdd(const SkNx& o) const { | 117 SkNx saturatedAdd(const SkNx& o) const { |
118 SkASSERT((T)(~0) > 0); // TODO: support signed T? | 118 SkASSERT((T)(~0) > 0); // TODO: support signed T? |
119 T sum = fVal + o.fVal; | 119 T sum = fVal + o.fVal; |
120 return sum < fVal ? (T)(~0) : sum; | 120 return sum < fVal ? (T)(~0) : sum; |
121 } | 121 } |
122 | 122 |
123 static SkNx Min(const SkNx& a, const SkNx& b) { return SkTMin(a.fVal, b.fVal
); } | 123 static SkNx Min(const SkNx& a, const SkNx& b) { return SkTMin(a.fVal, b.fVal
); } |
124 static SkNx Max(const SkNx& a, const SkNx& b) { return SkTMax(a.fVal, b.fVal
); } | 124 static SkNx Max(const SkNx& a, const SkNx& b) { return SkTMax(a.fVal, b.fVal
); } |
125 | 125 |
126 SkNx abs() const { return SkTAbs(fVal); } | 126 SkNx abs() const { return SkTAbs(fVal); } |
| 127 SkNx floor() const { return Floor(fVal); } |
127 | 128 |
128 SkNx sqrt () const { return Sqrt(fVal); } | 129 SkNx sqrt () const { return Sqrt(fVal); } |
129 SkNx rsqrt0() const { return this->sqrt().invert(); } | 130 SkNx rsqrt0() const { return this->sqrt().invert(); } |
130 SkNx rsqrt1() const { return this->rsqrt0(); } | 131 SkNx rsqrt1() const { return this->rsqrt0(); } |
131 SkNx rsqrt2() const { return this->rsqrt1(); } | 132 SkNx rsqrt2() const { return this->rsqrt1(); } |
132 | 133 |
133 SkNx invert() const { return 1 / fVal; } | 134 SkNx invert() const { return 1 / fVal; } |
134 SkNx approxInvert() const { return this->invert(); } | 135 SkNx approxInvert() const { return this->invert(); } |
135 | 136 |
136 T operator[](int k) const { | 137 T operator[](int k) const { |
137 SkASSERT(0 == k); | 138 SkASSERT(0 == k); |
138 return fVal; | 139 return fVal; |
139 } | 140 } |
140 | 141 |
141 template <int k> T kth() const { return (*this)[k]; } | 142 template <int k> T kth() const { return (*this)[k]; } |
142 | 143 |
143 bool allTrue() const { return fVal != 0; } | 144 bool allTrue() const { return fVal != 0; } |
144 bool anyTrue() const { return fVal != 0; } | 145 bool anyTrue() const { return fVal != 0; } |
145 SkNx thenElse(const SkNx& t, const SkNx& e) const { return fVal != 0 ? t : e
; } | 146 SkNx thenElse(const SkNx& t, const SkNx& e) const { return fVal != 0 ? t : e
; } |
146 | 147 |
147 protected: | 148 protected: |
| 149 static double Floor(double val) { return ::floor (val); } |
| 150 static float Floor(float val) { return ::floorf(val); } |
148 static double Sqrt(double val) { return ::sqrt (val); } | 151 static double Sqrt(double val) { return ::sqrt (val); } |
149 static float Sqrt(float val) { return ::sqrtf(val); } | 152 static float Sqrt(float val) { return ::sqrtf(val); } |
150 | 153 |
151 T fVal; | 154 T fVal; |
152 }; | 155 }; |
153 | 156 |
154 // This generic shuffle can be called to create any valid SkNx<N,T>. | 157 // This generic shuffle can be called to create any valid SkNx<N,T>. |
155 // Sk4f f(a,b,c,d); | 158 // Sk4f f(a,b,c,d); |
156 // Sk2f t = SkNx_shuffle<2,1>(f); // ~~~> Sk2f(c,b) | 159 // Sk2f t = SkNx_shuffle<2,1>(f); // ~~~> Sk2f(c,b) |
157 // f = SkNx_shuffle<0,1,1,0>(t); // ~~~> Sk4f(c,b,b,c) | 160 // f = SkNx_shuffle<0,1,1,0>(t); // ~~~> Sk4f(c,b,b,c) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 static inline | 208 static inline |
206 void Sk4f_ToBytes(uint8_t p[16], const Sk4f& a, const Sk4f& b, const Sk4f& c
, const Sk4f& d) { | 209 void Sk4f_ToBytes(uint8_t p[16], const Sk4f& a, const Sk4f& b, const Sk4f& c
, const Sk4f& d) { |
207 SkNx_cast<uint8_t>(a).store(p+ 0); | 210 SkNx_cast<uint8_t>(a).store(p+ 0); |
208 SkNx_cast<uint8_t>(b).store(p+ 4); | 211 SkNx_cast<uint8_t>(b).store(p+ 4); |
209 SkNx_cast<uint8_t>(c).store(p+ 8); | 212 SkNx_cast<uint8_t>(c).store(p+ 8); |
210 SkNx_cast<uint8_t>(d).store(p+12); | 213 SkNx_cast<uint8_t>(d).store(p+12); |
211 } | 214 } |
212 #endif | 215 #endif |
213 | 216 |
214 #endif//SkNx_DEFINED | 217 #endif//SkNx_DEFINED |
OLD | NEW |