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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/Sk4x.h ('k') | tests/Sk4xTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // It is important _not_ to put header guards here.
2 // This file will be intentionally included three times.
3
4 #if defined(SK4X_PREAMBLE)
5
6 #elif defined(SK4X_PRIVATE)
7 typedef T Type;
8 typedef T Vector[4];
9
10 Vector fVec;
11
12 template <int m, int a, int s, int k>
13 static Sk4x Shuffle(const Sk4x&, const Sk4x&);
14
15 void set(const T vals[4]) { for (int i = 0; i < 4; i++) { fVec[i] = vals[i]; } }
16
17 #else
18
19 #define M(...) template <typename T> __VA_ARGS__ Sk4x<T>::
20
21 M() Sk4x() {}
22 M() Sk4x(T a, T b, T c, T d) { fVec[0] = a; fVec[1] = b; fVec[2] = c; fVec[3] = d; }
23
24 M() Sk4x(const Sk4x<T>& other) { this->set(other.fVec); }
25 M(Sk4x<T>&) operator=(const Sk4x<T>& other) { this->set(other.fVec); return *thi s; }
26
27 M(Sk4x<T>) Load (const T vals[4]) { Sk4x r; r.set(vals); return r; }
28 M(Sk4x<T>) LoadAligned(const T vals[4]) { return Load(vals); }
29
30 M(void) store (T vals[4]) const { for (int i = 0; i < 4; i++) { vals[i] = fVec[i]; } }
31 M(void) storeAligned(T vals[4]) const { this->store(vals); }
32
33 M(template <typename Dst> Dst) reinterpret() const {
34 Dst d;
35 memcpy(&d.fVec, fVec, sizeof(fVec));
36 return d;
37 }
38 M(template <typename Dst> Dst) cast() const {
39 return Dst((typename Dst::Type)fVec[0],
40 (typename Dst::Type)fVec[1],
41 (typename Dst::Type)fVec[2],
42 (typename Dst::Type)fVec[3]);
43 }
44
45 M(bool) allTrue() const { return fVec[0] && fVec[1] && fVec[2] && fVec[3]; }
46 M(bool) anyTrue() const { return fVec[0] || fVec[1] || fVec[2] || fVec[3]; }
47
48 M(Sk4x<T>) bitNot() const { return Sk4x(~fVec[0], ~fVec[1], ~fVec[2], ~fVec[3]); }
49
50 #define BINOP(op) fVec[0] op other.fVec[0], \
51 fVec[1] op other.fVec[1], \
52 fVec[2] op other.fVec[2], \
53 fVec[3] op other.fVec[3]
54 M(Sk4x<T>) bitAnd(const Sk4x& other) const { return Sk4x(BINOP(&)); }
55 M(Sk4x<T>) bitOr(const Sk4x& other) const { return Sk4x(BINOP(|)); }
56 M(Sk4x<T>) add(const Sk4x<T>& other) const { return Sk4x(BINOP(+)); }
57 M(Sk4x<T>) subtract(const Sk4x<T>& other) const { return Sk4x(BINOP(-)); }
58 M(Sk4x<T>) multiply(const Sk4x<T>& other) const { return Sk4x(BINOP(*)); }
59 M(Sk4x<T>) divide(const Sk4x<T>& other) const { return Sk4x(BINOP(/)); }
60 #undef BINOP
61
62 #define BOOL_BINOP(op) fVec[0] op other.fVec[0] ? -1 : 0, \
63 fVec[1] op other.fVec[1] ? -1 : 0, \
64 fVec[2] op other.fVec[2] ? -1 : 0, \
65 fVec[3] op other.fVec[3] ? -1 : 0
66 M(Sk4i) equal(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(== )); }
67 M(Sk4i) notEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(!= )); }
68 M(Sk4i) lessThan(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP( < )); }
69 M(Sk4i) greaterThan(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP( > )); }
70 M(Sk4i) lessThanEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(<= )); }
71 M(Sk4i) greaterThanEqual(const Sk4x<T>& other) const { return Sk4i(BOOL_BINOP(>= )); }
72 #undef BOOL_BINOP
73
74 M(Sk4x<T>) Min(const Sk4x<T>& a, const Sk4x<T>& b) {
75 return Sk4x(SkTMin(a.fVec[0], b.fVec[0]),
76 SkTMin(a.fVec[1], b.fVec[1]),
77 SkTMin(a.fVec[2], b.fVec[2]),
78 SkTMin(a.fVec[3], b.fVec[3]));
79 }
80
81 M(Sk4x<T>) Max(const Sk4x<T>& a, const Sk4x<T>& b) {
82 return Sk4x(SkTMax(a.fVec[0], b.fVec[0]),
83 SkTMax(a.fVec[1], b.fVec[1]),
84 SkTMax(a.fVec[2], b.fVec[2]),
85 SkTMax(a.fVec[3], b.fVec[3]));
86 }
87
88 M(template <int m, int a, int s, int k> Sk4x<T>) Shuffle(const Sk4x<T>& x, const Sk4x<T>& y) {
89 return Sk4x(m < 4 ? x.fVec[m] : y.fVec[m-4],
90 a < 4 ? x.fVec[a] : y.fVec[a-4],
91 s < 4 ? x.fVec[s] : y.fVec[s-4],
92 k < 4 ? x.fVec[k] : y.fVec[k-4]);
93 }
94
95 M(Sk4x<T>) zwxy() const { return Shuffle<2,3,0,1>(*t his, *this); }
96 M(Sk4x<T>) XYAB(const Sk4x& xyzw, const Sk4x& abcd) { return Shuffle<0,1,4,5>( x yzw, abcd); }
97 M(Sk4x<T>) ZWCD(const Sk4x& xyzw, const Sk4x& abcd) { return Shuffle<2,3,6,7>( x yzw, abcd); }
98
99 #undef M
100
101 #endif
OLDNEW
« 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