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

Unified Diff: src/core/SkNx.h

Issue 1411563008: prune unused SkNx features (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 0.001f 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/effects/gradients/SkRadialGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkNx.h
diff --git a/src/core/SkNx.h b/src/core/SkNx.h
index f8b27fc1ed0572c862839d80c707d2a3f25280f2..1e32a2aa265e4ad83b46eced451e9bd83f8d8e26 100644
--- a/src/core/SkNx.h
+++ b/src/core/SkNx.h
@@ -81,29 +81,28 @@ protected:
SkNi<N/2, T> fLo, fHi;
};
-template <int N, typename T>
+template <int N>
class SkNf {
- static int32_t MyNi(float);
- static int64_t MyNi(double);
- typedef decltype(MyNi(T())) I;
public:
SkNf() {}
- explicit SkNf(T val) : fLo(val), fHi(val) {}
- static SkNf Load(const T vals[N]) {
- return SkNf(SkNf<N/2,T>::Load(vals), SkNf<N/2,T>::Load(vals+N/2));
+ explicit SkNf(float val) : fLo(val), fHi(val) {}
+ static SkNf Load(const float vals[N]) {
+ return SkNf(SkNf<N/2>::Load(vals), SkNf<N/2>::Load(vals+N/2));
}
// FromBytes() and toBytes() specializations may assume their argument is N-byte aligned.
// E.g. Sk4f::FromBytes() may assume it's reading from a 4-byte-aligned pointer.
// Converts [0,255] bytes to [0.0, 255.0] floats.
static SkNf FromBytes(const uint8_t bytes[N]) {
- return SkNf(SkNf<N/2,T>::FromBytes(bytes), SkNf<N/2,T>::FromBytes(bytes+N/2));
+ return SkNf(SkNf<N/2>::FromBytes(bytes), SkNf<N/2>::FromBytes(bytes+N/2));
}
- SkNf(T a, T b) : fLo(a), fHi(b) { REQUIRE(N==2); }
- SkNf(T a, T b, T c, T d) : fLo(a,b), fHi(c,d) { REQUIRE(N==4); }
- SkNf(T a, T b, T c, T d, T e, T f, T g, T h) : fLo(a,b,c,d), fHi(e,f,g,h) { REQUIRE(N==8); }
+ SkNf(float a, float b) : fLo(a), fHi(b) { REQUIRE(N==2); }
+ SkNf(float a, float b, float c, float d) : fLo(a,b), fHi(c,d) { REQUIRE(N==4); }
+ SkNf(float a, float b, float c, float d, float e, float f, float g, float h)
+ : fLo(a,b,c,d)
+ , fHi(e,f,g,h) { REQUIRE(N==8); }
- void store(T vals[N]) const {
+ void store(float vals[N]) const {
fLo.store(vals);
fHi.store(vals+N/2);
}
@@ -114,8 +113,6 @@ public:
fHi.toBytes(bytes+N/2);
}
- SkNi<N,I> castTrunc() const { return SkNi<N,I>(fLo.castTrunc(), fHi.castTrunc()); }
-
SkNf operator + (const SkNf& o) const { return SkNf(fLo + o.fLo, fHi + o.fHi); }
SkNf operator - (const SkNf& o) const { return SkNf(fLo - o.fLo, fHi - o.fHi); }
SkNf operator * (const SkNf& o) const { return SkNf(fLo * o.fLo, fHi * o.fHi); }
@@ -129,10 +126,10 @@ public:
SkNf operator >= (const SkNf& o) const { return SkNf(fLo >= o.fLo, fHi >= o.fHi); }
static SkNf Min(const SkNf& l, const SkNf& r) {
- return SkNf(SkNf<N/2,T>::Min(l.fLo, r.fLo), SkNf<N/2,T>::Min(l.fHi, r.fHi));
+ return SkNf(SkNf<N/2>::Min(l.fLo, r.fLo), SkNf<N/2>::Min(l.fHi, r.fHi));
}
static SkNf Max(const SkNf& l, const SkNf& r) {
- return SkNf(SkNf<N/2,T>::Max(l.fLo, r.fLo), SkNf<N/2,T>::Max(l.fHi, r.fHi));
+ return SkNf(SkNf<N/2>::Max(l.fLo, r.fLo), SkNf<N/2>::Max(l.fHi, r.fHi));
}
SkNf sqrt() const { return SkNf(fLo. sqrt(), fHi. sqrt()); }
@@ -145,7 +142,7 @@ public:
SkNf invert() const { return SkNf(fLo. invert(), fHi. invert()); }
SkNf approxInvert() const { return SkNf(fLo.approxInvert(), fHi.approxInvert()); }
- template <int k> T kth() const {
+ template <int k> float kth() const {
SkASSERT(0 <= k && k < N);
return k < N/2 ? fLo.template kth<k>() : fHi.template kth<k-N/2>();
}
@@ -158,9 +155,9 @@ public:
protected:
REQUIRE(0 == (N & (N-1)));
- SkNf(const SkNf<N/2, T>& lo, const SkNf<N/2, T>& hi) : fLo(lo), fHi(hi) {}
+ SkNf(const SkNf<N/2>& lo, const SkNf<N/2>& hi) : fLo(lo), fHi(hi) {}
- SkNf<N/2, T> fLo, fHi;
+ SkNf<N/2> fLo, fHi;
};
@@ -204,21 +201,16 @@ protected:
T fVal;
};
-template <typename T>
-class SkNf<1,T> {
- static int32_t MyNi(float);
- static int64_t MyNi(double);
- typedef decltype(MyNi(T())) I;
+template <>
+class SkNf<1> {
public:
SkNf() {}
- explicit SkNf(T val) : fVal(val) {}
- static SkNf Load(const T vals[1]) { return SkNf(vals[0]); }
- static SkNf FromBytes(const uint8_t bytes[1]) { return SkNf((T)bytes[0]); }
-
- void store(T vals[1]) const { vals[0] = fVal; }
- void toBytes(uint8_t bytes[1]) const { bytes[0] = (uint8_t)(SkTMin(fVal, (T)255.0)); }
+ explicit SkNf(float val) : fVal(val) {}
+ static SkNf Load(const float vals[1]) { return SkNf(vals[0]); }
+ static SkNf FromBytes(const uint8_t bytes[1]) { return SkNf((float)bytes[0]); }
- SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); }
+ void store(float vals[1]) const { vals[0] = fVal; }
+ void toBytes(uint8_t bytes[1]) const { bytes[0] = (uint8_t)(SkTMin(fVal, 255.0f)); }
SkNf operator + (const SkNf& o) const { return SkNf(fVal + o.fVal); }
SkNf operator - (const SkNf& o) const { return SkNf(fVal - o.fVal); }
@@ -235,35 +227,30 @@ public:
static SkNf Min(const SkNf& l, const SkNf& r) { return SkNf(SkTMin(l.fVal, r.fVal)); }
static SkNf Max(const SkNf& l, const SkNf& r) { return SkNf(SkTMax(l.fVal, r.fVal)); }
- SkNf sqrt() const { return SkNf(Sqrt(fVal)); }
- SkNf rsqrt0() const { return SkNf((T)1 / Sqrt(fVal)); }
+ SkNf sqrt() const { return SkNf(sqrtf(fVal)); }
+ SkNf rsqrt0() const { return SkNf(1.0f / sqrtf(fVal)); }
SkNf rsqrt1() const { return this->rsqrt0(); }
SkNf rsqrt2() const { return this->rsqrt1(); }
- SkNf invert() const { return SkNf((T)1 / fVal); }
+ SkNf invert() const { return SkNf(1.0f / fVal); }
SkNf approxInvert() const { return this->invert(); }
- template <int k> T kth() const {
+ template <int k> float kth() const {
SkASSERT(k == 0);
return fVal;
}
- bool allTrue() const { return this->pun(); }
- bool anyTrue() const { return this->pun(); }
+ bool allTrue() const { return this->pun() != 0; }
+ bool anyTrue() const { return this->pun() != 0; }
SkNf thenElse(const SkNf& t, const SkNf& e) const { return this->pun() ? t : e; }
protected:
- // We do double sqrts natively, or via floats for any other type.
- template <typename U>
- static U Sqrt(U val) { return (U) ::sqrtf((float)val); }
- static double Sqrt(double val) { return ::sqrt ( val); }
-
- I pun() const {
- union { T f; I i; } pun = { fVal };
+ uint32_t pun() const {
+ union { float f; uint32_t i; } pun = { fVal };
return pun.i;
}
- T fVal;
+ float fVal;
};
// This default implementation can be specialized by ../opts/SkNx_foo.h
@@ -285,8 +272,6 @@ inline SkNx SkNx_dup(const SkNx& src) { return SkNx_shuffle<Ix>(src); }
} // namespace
-
-
// Include platform specific specializations if available.
#ifndef SKNX_NO_SIMD
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
@@ -298,21 +283,14 @@ inline SkNx SkNx_dup(const SkNx& src) { return SkNx_shuffle<Ix>(src); }
#undef REQUIRE
-typedef SkNf<2, float> Sk2f;
-typedef SkNf<2, double> Sk2d;
-typedef SkNf<2, SkScalar> Sk2s;
+typedef SkNf<2> Sk2f;
+typedef SkNf<2> Sk2s;
-typedef SkNf<4, float> Sk4f;
-typedef SkNf<4, double> Sk4d;
-typedef SkNf<4, SkScalar> Sk4s;
+typedef SkNf<4> Sk4f;
+typedef SkNf<4> Sk4s;
-typedef SkNi<4, uint16_t> Sk4h;
typedef SkNi<8, uint16_t> Sk8h;
typedef SkNi<16, uint16_t> Sk16h;
-
-typedef SkNi<16, uint8_t> Sk16b;
-
-typedef SkNi<4, int32_t> Sk4i;
-typedef SkNi<4, uint32_t> Sk4u;
+typedef SkNi<16, uint8_t> Sk16b;
#endif//SkNx_DEFINED
« no previous file with comments | « no previous file | src/effects/gradients/SkRadialGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698