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

Unified Diff: src/core/Sk4x_portable.h

Issue 704923003: start again on Sk4x with portable version and unit tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows, do you like this? Created 6 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 | « src/core/Sk4x.h ('k') | tests/Sk4xTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/Sk4x_portable.h
diff --git a/src/core/Sk4x_portable.h b/src/core/Sk4x_portable.h
new file mode 100644
index 0000000000000000000000000000000000000000..2f985d0d89d818049ca9eee4988411c9a08a8a21
--- /dev/null
+++ b/src/core/Sk4x_portable.h
@@ -0,0 +1,101 @@
+// It is important _not_ to put header guards here.
+// This file will be intentionally included three times.
+
+#if defined(SK4X_PREAMBLE)
+
+#elif defined(SK4X_PRIVATE)
+ typedef T Type;
+ typedef T Vector[4];
+
+ Vector fVec;
+
+ template <int m, int a, int s, int k>
+ static Sk4x Shuffle(const Sk4x&, const Sk4x&);
+
+ void set(const T vals[4]) { for (int i = 0; i < 4; i++) { fVec[i] = vals[i]; } }
+
+#else
+
+#define M(...) template <typename T> __VA_ARGS__ Sk4x<T>::
+
+M() Sk4x() {}
+M() Sk4x(T a, T b, T c, T d) { fVec[0] = a; fVec[1] = b; fVec[2] = c; fVec[3] = d; }
+
+M() Sk4x(const Sk4x<T>& other) { this->set(other.fVec); }
+M(Sk4x<T>&) operator=(const Sk4x<T>& other) { this->set(other.fVec); return *this; }
+
+M(Sk4x<T>) Load (const T vals[4]) { Sk4x r; r.set(vals); return r; }
+M(Sk4x<T>) LoadAligned(const T vals[4]) { return Load(vals); }
+
+M(void) store (T vals[4]) const { for (int i = 0; i < 4; i++) { vals[i] = fVec[i]; } }
+M(void) storeAligned(T vals[4]) const { this->store(vals); }
+
+M(template <typename Dst> Dst) reinterpret() const {
+ Dst d;
+ memcpy(&d.fVec, fVec, sizeof(fVec));
+ return d;
+}
+M(template <typename Dst> Dst) cast() const {
+ return Dst((typename Dst::Type)fVec[0],
+ (typename Dst::Type)fVec[1],
+ (typename Dst::Type)fVec[2],
+ (typename Dst::Type)fVec[3]);
+}
+
+M(bool) allTrue() const { return fVec[0] && fVec[1] && fVec[2] && fVec[3]; }
+M(bool) anyTrue() const { return fVec[0] || fVec[1] || fVec[2] || fVec[3]; }
+
+M(Sk4x<T>) bitNot() const { return Sk4x(~fVec[0], ~fVec[1], ~fVec[2], ~fVec[3]); }
+
+#define BINOP(op) fVec[0] op other.fVec[0], \
+ fVec[1] op other.fVec[1], \
+ fVec[2] op other.fVec[2], \
+ fVec[3] op other.fVec[3]
+M(Sk4x<T>) bitAnd(const Sk4x& other) const { return Sk4x(BINOP(&)); }
+M(Sk4x<T>) bitOr(const Sk4x& other) const { return Sk4x(BINOP(|)); }
+M(Sk4x<T>) add(const Sk4x<T>& other) const { return Sk4x(BINOP(+)); }
+M(Sk4x<T>) subtract(const Sk4x<T>& other) const { return Sk4x(BINOP(-)); }
+M(Sk4x<T>) multiply(const Sk4x<T>& other) const { return Sk4x(BINOP(*)); }
+M(Sk4x<T>) divide(const Sk4x<T>& other) const { return Sk4x(BINOP(/)); }
+#undef BINOP
+
+#define BOOL_BINOP(op) fVec[0] op other.fVec[0] ? -1 : 0, \
+ fVec[1] op other.fVec[1] ? -1 : 0, \
+ fVec[2] op other.fVec[2] ? -1 : 0, \
+ fVec[3] op other.fVec[3] ? -1 : 0
+M(Sk4i) equal(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(==)); }
+M(Sk4i) notEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(!=)); }
+M(Sk4i) lessThan(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP( <)); }
+M(Sk4i) greaterThan(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP( >)); }
+M(Sk4i) lessThanEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(<=)); }
+M(Sk4i) greaterThanEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(>=)); }
+#undef BOOL_BINOP
+
+M(Sk4x<T>) Min(const Sk4x<T>& a, const Sk4x<T>& b) {
+ return Sk4x(SkTMin(a.fVec[0], b.fVec[0]),
+ SkTMin(a.fVec[1], b.fVec[1]),
+ SkTMin(a.fVec[2], b.fVec[2]),
+ SkTMin(a.fVec[3], b.fVec[3]));
+}
+
+M(Sk4x<T>) Max(const Sk4x<T>& a, const Sk4x<T>& b) {
+ return Sk4x(SkTMax(a.fVec[0], b.fVec[0]),
+ SkTMax(a.fVec[1], b.fVec[1]),
+ SkTMax(a.fVec[2], b.fVec[2]),
+ SkTMax(a.fVec[3], b.fVec[3]));
+}
+
+M(template <int m, int a, int s, int k> Sk4x<T>) Shuffle(const Sk4x<T>& x, const Sk4x<T>& y) {
+ return Sk4x(m < 4 ? x.fVec[m] : y.fVec[m-4],
+ a < 4 ? x.fVec[a] : y.fVec[a-4],
+ s < 4 ? x.fVec[s] : y.fVec[s-4],
+ k < 4 ? x.fVec[k] : y.fVec[k-4]);
+}
+
+M(Sk4x<T>) zwxy() const { return Shuffle<2,3,0,1>(*this, *this); }
+M(Sk4x<T>) XYAB(const Sk4x& xyzw, const Sk4x& abcd) { return Shuffle<0,1,4,5>( xyzw, abcd); }
+M(Sk4x<T>) ZWCD(const Sk4x& xyzw, const Sk4x& abcd) { return Shuffle<2,3,6,7>( xyzw, abcd); }
+
+#undef M
+
+#endif
« no previous file with comments | « src/core/Sk4x.h ('k') | tests/Sk4xTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698