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

Side by Side Diff: src/opts/SkPx_neon.h

Issue 1317233005: SkPx: new approach to fixed-point SIMD (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: shl,shr 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 unified diff | Download patch
« no previous file with comments | « src/opts/SkBlitMask_opts.h ('k') | src/opts/SkPx_none.h » ('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 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkPx_neon_DEFINED
9 #define SkPx_neon_DEFINED
10
11 // When we have NEON, we like to work 8 pixels at a time.
12 // This lets us exploit vld4/vst4 and represent SkPx as planar uint8x8x4_t,
13 // Wide as planar uint16x8x4_t, and Alpha as a single uint8x8_t plane.
14
15 struct SkPx_neon {
16 static const int N = 8;
17
18 uint8x8x4_t fVec;
19 SkPx_neon(uint8x8x4_t vec) : fVec(vec) {}
20
21 static SkPx_neon Dup(uint32_t px) { return vld4_dup_u8((const uint8_t*)&px); }
22 static SkPx_neon Load(const uint32_t* px) { return vld4_u8((const uint8_t*)p x); }
23 static SkPx_neon Load(const uint32_t* px, int n) {
24 SkASSERT(0 < n && n < 8);
25 uint8x8x4_t v = vld4_dup_u8((const uint8_t*)px); // n>=1, so start all lanes with pixel 0.
26 switch (n) {
27 case 7: v = vld4_lane_u8((const uint8_t*)(px+6), v, 6); // fall thr ough
28 case 6: v = vld4_lane_u8((const uint8_t*)(px+5), v, 5); // fall thr ough
29 case 5: v = vld4_lane_u8((const uint8_t*)(px+4), v, 4); // fall thr ough
30 case 4: v = vld4_lane_u8((const uint8_t*)(px+3), v, 3); // fall thr ough
31 case 3: v = vld4_lane_u8((const uint8_t*)(px+2), v, 2); // fall thr ough
32 case 2: v = vld4_lane_u8((const uint8_t*)(px+1), v, 1);
33 }
34 return v;
35 }
36
37 void store(uint32_t* px) const { vst4_u8((uint8_t*)px, fVec); }
38 void store(uint32_t* px, int n) const {
39 SkASSERT(0 < n && n < 8);
40 switch (n) {
41 case 7: vst4_lane_u8((uint8_t*)(px+6), fVec, 6);
42 case 6: vst4_lane_u8((uint8_t*)(px+5), fVec, 5);
43 case 5: vst4_lane_u8((uint8_t*)(px+4), fVec, 4);
44 case 4: vst4_lane_u8((uint8_t*)(px+3), fVec, 3);
45 case 3: vst4_lane_u8((uint8_t*)(px+2), fVec, 2);
46 case 2: vst4_lane_u8((uint8_t*)(px+1), fVec, 1);
47 case 1: vst4_lane_u8((uint8_t*)(px+0), fVec, 0);
48 }
49 }
50
51 struct Alpha {
52 uint8x8_t fA;
53 Alpha(uint8x8_t a) : fA(a) {}
54
55 static Alpha Dup(uint8_t a) { return vdup_n_u8(a); }
56 static Alpha Load(const uint8_t* a) { return vld1_u8(a); }
57 static Alpha Load(const uint8_t* a, int n) {
58 SkASSERT(0 < n && n < 8);
59 uint8x8_t v = vld1_dup_u8(a); // n>=1, so start all lanes with alph a 0.
60 switch (n) {
61 case 7: v = vld1_lane_u8(a+6, v, 6); // fall through
62 case 6: v = vld1_lane_u8(a+5, v, 5); // fall through
63 case 5: v = vld1_lane_u8(a+4, v, 4); // fall through
64 case 4: v = vld1_lane_u8(a+3, v, 3); // fall through
65 case 3: v = vld1_lane_u8(a+2, v, 2); // fall through
66 case 2: v = vld1_lane_u8(a+1, v, 1);
67 }
68 return v;
69 }
70 Alpha inv() const { return vsub_u8(vdup_n_u8(255), fA); }
71 };
72
73 struct Wide {
74 uint16x8x4_t fVec;
75 Wide(uint16x8x4_t vec) : fVec(vec) {}
76
77 Wide operator+(const Wide& o) const {
78 return (uint16x8x4_t) {{
79 vaddq_u16(fVec.val[0], o.fVec.val[0]),
80 vaddq_u16(fVec.val[1], o.fVec.val[1]),
81 vaddq_u16(fVec.val[2], o.fVec.val[2]),
82 vaddq_u16(fVec.val[3], o.fVec.val[3]),
83 }};
84 }
85 Wide operator-(const Wide& o) const {
86 return (uint16x8x4_t) {{
87 vsubq_u16(fVec.val[0], o.fVec.val[0]),
88 vsubq_u16(fVec.val[1], o.fVec.val[1]),
89 vsubq_u16(fVec.val[2], o.fVec.val[2]),
90 vsubq_u16(fVec.val[3], o.fVec.val[3]),
91 }};
92 }
93
94 template <int bits> Wide shl() const {
95 return (uint16x8x4_t) {{
96 vshlq_n_u16(fVec.val[0], bits),
97 vshlq_n_u16(fVec.val[1], bits),
98 vshlq_n_u16(fVec.val[2], bits),
99 vshlq_n_u16(fVec.val[3], bits),
100 }};
101 }
102 template <int bits> Wide shr() const {
103 return (uint16x8x4_t) {{
104 vshrq_n_u16(fVec.val[0], bits),
105 vshrq_n_u16(fVec.val[1], bits),
106 vshrq_n_u16(fVec.val[2], bits),
107 vshrq_n_u16(fVec.val[3], bits),
108 }};
109 }
110
111 SkPx_neon addNarrowHi(const SkPx_neon& o) const {
112 return (uint8x8x4_t) {{
113 vshrn_n_u16(vaddw_u8(fVec.val[0], o.fVec.val[0]), 8),
114 vshrn_n_u16(vaddw_u8(fVec.val[1], o.fVec.val[1]), 8),
115 vshrn_n_u16(vaddw_u8(fVec.val[2], o.fVec.val[2]), 8),
116 vshrn_n_u16(vaddw_u8(fVec.val[3], o.fVec.val[3]), 8),
117 }};
118 }
119 };
120
121 Alpha alpha() const { return fVec.val[3]; }
122
123 Wide widenLo() const {
124 return (uint16x8x4_t) {{
125 vmovl_u8(fVec.val[0]),
126 vmovl_u8(fVec.val[1]),
127 vmovl_u8(fVec.val[2]),
128 vmovl_u8(fVec.val[3]),
129 }};
130 }
131 // TODO: these two can probably be done faster.
132 Wide widenHi() const { return this->widenLo().shl<8>(); }
133 Wide widenLoHi() const { return this->widenLo() + this->widenHi(); }
134
135 SkPx_neon operator+(const SkPx_neon& o) const {
136 return (uint8x8x4_t) {{
137 vadd_u8(fVec.val[0], o.fVec.val[0]),
138 vadd_u8(fVec.val[1], o.fVec.val[1]),
139 vadd_u8(fVec.val[2], o.fVec.val[2]),
140 vadd_u8(fVec.val[3], o.fVec.val[3]),
141 }};
142 }
143 SkPx_neon operator-(const SkPx_neon& o) const {
144 return (uint8x8x4_t) {{
145 vsub_u8(fVec.val[0], o.fVec.val[0]),
146 vsub_u8(fVec.val[1], o.fVec.val[1]),
147 vsub_u8(fVec.val[2], o.fVec.val[2]),
148 vsub_u8(fVec.val[3], o.fVec.val[3]),
149 }};
150 }
151 SkPx_neon saturatedAdd(const SkPx_neon& o) const {
152 return (uint8x8x4_t) {{
153 vqadd_u8(fVec.val[0], o.fVec.val[0]),
154 vqadd_u8(fVec.val[1], o.fVec.val[1]),
155 vqadd_u8(fVec.val[2], o.fVec.val[2]),
156 vqadd_u8(fVec.val[3], o.fVec.val[3]),
157 }};
158 }
159
160 Wide operator*(const Alpha& a) const {
161 return (uint16x8x4_t) {{
162 vmull_u8(fVec.val[0], a.fA),
163 vmull_u8(fVec.val[1], a.fA),
164 vmull_u8(fVec.val[2], a.fA),
165 vmull_u8(fVec.val[3], a.fA),
166 }};
167 }
168 SkPx_neon approxMulDiv255(const Alpha& a) const {
169 return (*this * a).addNarrowHi(*this);
170 }
171
172 SkPx_neon addAlpha(const Alpha& a) const {
173 return (uint8x8x4_t) {{
174 fVec.val[0],
175 fVec.val[1],
176 fVec.val[2],
177 vadd_u8(fVec.val[3], a.fA),
178 }};
179 }
180 };
181 typedef SkPx_neon SkPx;
182
183 #endif//SkPx_neon_DEFINED
OLDNEW
« no previous file with comments | « src/opts/SkBlitMask_opts.h ('k') | src/opts/SkPx_none.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698