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

Side by Side Diff: tests/SkNxTest.cpp

Issue 1683543002: sknx refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: typos Created 4 years, 10 months 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/SkXfermode_opts.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "Sk4px.h" 8 #include "Sk4px.h"
9 #include "SkNx.h" 9 #include "SkNx.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 REPORTER_ASSERT(r, Sk16b::Min(aw, bw).kth<0>() == SkTMin(a, b)); 139 REPORTER_ASSERT(r, Sk16b::Min(aw, bw).kth<0>() == SkTMin(a, b));
140 REPORTER_ASSERT(r, !(aw < bw).kth<0>() == !(a < b)); 140 REPORTER_ASSERT(r, !(aw < bw).kth<0>() == !(a < b));
141 }} 141 }}
142 142
143 // Exhausting the 16x16 bit space is kind of slow, so only do that in releas e builds. 143 // Exhausting the 16x16 bit space is kind of slow, so only do that in releas e builds.
144 #ifdef SK_DEBUG 144 #ifdef SK_DEBUG
145 SkRandom rand; 145 SkRandom rand;
146 for (int i = 0; i < (1<<16); i++) { 146 for (int i = 0; i < (1<<16); i++) {
147 uint16_t a = rand.nextU() >> 16, 147 uint16_t a = rand.nextU() >> 16,
148 b = rand.nextU() >> 16; 148 b = rand.nextU() >> 16;
149 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b)) ; 149 REPORTER_ASSERT(r, Sk16h::Min(Sk16h(a), Sk16h(b)).kth<0>() == SkTMin(a, b));
150 } 150 }
151 #else 151 #else
152 for (int a = 0; a < (1<<16); a++) { 152 for (int a = 0; a < (1<<16); a++) {
153 for (int b = 0; b < (1<<16); b++) { 153 for (int b = 0; b < (1<<16); b++) {
154 REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b)) ; 154 REPORTER_ASSERT(r, Sk16h::Min(Sk16h(a), Sk16h(b)).kth<0>() == SkTMin(a, b));
155 }} 155 }}
156 #endif 156 #endif
157 } 157 }
158 158
159 DEF_TEST(SkNi_saturatedAdd, r) { 159 DEF_TEST(SkNi_saturatedAdd, r) {
160 for (int a = 0; a < (1<<8); a++) { 160 for (int a = 0; a < (1<<8); a++) {
161 for (int b = 0; b < (1<<8); b++) { 161 for (int b = 0; b < (1<<8); b++) {
162 int exact = a+b; 162 int exact = a+b;
163 if (exact > 255) { exact = 255; } 163 if (exact > 255) { exact = 255; }
164 if (exact < 0) { exact = 0; } 164 if (exact < 0) { exact = 0; }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 }; 200 };
201 auto packed = Sk4px::Load4(colors); 201 auto packed = Sk4px::Load4(colors);
202 202
203 auto wideLo = packed.widenLo(), 203 auto wideLo = packed.widenLo(),
204 wideHi = packed.widenHi(), 204 wideHi = packed.widenHi(),
205 wideLoHi = packed.widenLoHi(), 205 wideLoHi = packed.widenLoHi(),
206 wideLoHiAlt = wideLo + wideHi; 206 wideLoHiAlt = wideLo + wideHi;
207 REPORTER_ASSERT(r, 0 == memcmp(&wideLoHi, &wideLoHiAlt, sizeof(wideLoHi))); 207 REPORTER_ASSERT(r, 0 == memcmp(&wideLoHi, &wideLoHiAlt, sizeof(wideLoHi)));
208 } 208 }
209 209
210 DEF_TEST(SkNx_cast, r) {
211 Sk4f fs(-1.7f, -1.4f, 0.5f, 1.9f);
212 Sk4i is = SkNx_cast<int>(fs);
213
214 REPORTER_ASSERT(r, is.kth<0>() == -1);
215 REPORTER_ASSERT(r, is.kth<1>() == -1);
216 REPORTER_ASSERT(r, is.kth<2>() == 0);
217 REPORTER_ASSERT(r, is.kth<3>() == 1);
218 }
219
220 DEF_TEST(SkNx_abs, r) { 210 DEF_TEST(SkNx_abs, r) {
221 auto fs = Sk4f(0.0f, -0.0f, 2.0f, -4.0f).abs(); 211 auto fs = Sk4f(0.0f, -0.0f, 2.0f, -4.0f).abs();
222 REPORTER_ASSERT(r, fs.kth<0>() == 0.0f); 212 REPORTER_ASSERT(r, fs.kth<0>() == 0.0f);
223 REPORTER_ASSERT(r, fs.kth<1>() == 0.0f); 213 REPORTER_ASSERT(r, fs.kth<1>() == 0.0f);
224 REPORTER_ASSERT(r, fs.kth<2>() == 2.0f); 214 REPORTER_ASSERT(r, fs.kth<2>() == 2.0f);
225 REPORTER_ASSERT(r, fs.kth<3>() == 4.0f); 215 REPORTER_ASSERT(r, fs.kth<3>() == 4.0f);
226 } 216 }
227 217
218 DEF_TEST(SkNx_shuffle, r) {
219 Sk4f f4(0,10,20,30);
220
221 Sk2f f2 = SkNx_shuffle<2,1>(f4);
222 REPORTER_ASSERT(r, f2[0] == 20);
223 REPORTER_ASSERT(r, f2[1] == 10);
224
225 f4 = SkNx_shuffle<0,1,1,0>(f2);
226 REPORTER_ASSERT(r, f4[0] == 20);
227 REPORTER_ASSERT(r, f4[1] == 10);
228 REPORTER_ASSERT(r, f4[2] == 10);
229 REPORTER_ASSERT(r, f4[3] == 20);
230 }
231
228 #include "SkRandom.h" 232 #include "SkRandom.h"
229 233
230 static void dump(const Sk4f& f4, const Sk4h& h4) {
231 SkDebugf("%g %g %g %g --> %d %d %d %d\n",
232 f4.kth<0>(), f4.kth<1>(), f4.kth<2>(), f4.kth<3>(),
233 h4.kth<0>(), h4.kth<1>(), h4.kth<2>(), h4.kth<3>());
234 }
235
236 DEF_TEST(SkNx_u16_float, r) { 234 DEF_TEST(SkNx_u16_float, r) {
237 { 235 {
238 // u16 --> float 236 // u16 --> float
239 auto h4 = Sk4h(15, 17, 257, 65535); 237 auto h4 = Sk4h(15, 17, 257, 65535);
240 auto f4 = SkNx_cast<float>(h4); 238 auto f4 = SkNx_cast<float>(h4);
241 dump(f4, h4);
242 REPORTER_ASSERT(r, f4.kth<0>() == 15.0f); 239 REPORTER_ASSERT(r, f4.kth<0>() == 15.0f);
243 REPORTER_ASSERT(r, f4.kth<1>() == 17.0f); 240 REPORTER_ASSERT(r, f4.kth<1>() == 17.0f);
244 REPORTER_ASSERT(r, f4.kth<2>() == 257.0f); 241 REPORTER_ASSERT(r, f4.kth<2>() == 257.0f);
245 REPORTER_ASSERT(r, f4.kth<3>() == 65535.0f); 242 REPORTER_ASSERT(r, f4.kth<3>() == 65535.0f);
246 } 243 }
247 { 244 {
248 // float -> u16 245 // float -> u16
249 auto f4 = Sk4f(15, 17, 257, 65535); 246 auto f4 = Sk4f(15, 17, 257, 65535);
250 auto h4 = SkNx_cast<uint16_t>(f4); 247 auto h4 = SkNx_cast<uint16_t>(f4);
251 dump(f4, h4);
252 REPORTER_ASSERT(r, h4.kth<0>() == 15); 248 REPORTER_ASSERT(r, h4.kth<0>() == 15);
253 REPORTER_ASSERT(r, h4.kth<1>() == 17); 249 REPORTER_ASSERT(r, h4.kth<1>() == 17);
254 REPORTER_ASSERT(r, h4.kth<2>() == 257); 250 REPORTER_ASSERT(r, h4.kth<2>() == 257);
255 REPORTER_ASSERT(r, h4.kth<3>() == 65535); 251 REPORTER_ASSERT(r, h4.kth<3>() == 65535);
256 } 252 }
257 253
258 // starting with any u16 value, we should be able to have a perfect round-tr ip in/out of floats 254 // starting with any u16 value, we should be able to have a perfect round-tr ip in/out of floats
259 // 255 //
260 SkRandom rand; 256 SkRandom rand;
261 for (int i = 0; i < 0; ++i) { 257 for (int i = 0; i < 10000; ++i) {
262 const uint16_t s16[4] { 258 const uint16_t s16[4] {
263 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), 259 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(),
264 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), 260 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(),
265 }; 261 };
266 auto u4_0 = Sk4h::Load(s16); 262 auto u4_0 = Sk4h::Load(s16);
267 auto f4 = SkNx_cast<float>(u4_0); 263 auto f4 = SkNx_cast<float>(u4_0);
268 auto u4_1 = SkNx_cast<uint16_t>(f4); 264 auto u4_1 = SkNx_cast<uint16_t>(f4);
269 uint16_t d16[4]; 265 uint16_t d16[4];
270 u4_1.store(d16); 266 u4_1.store(d16);
271 REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16))); 267 REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16)));
272 } 268 }
273 } 269 }
OLDNEW
« no previous file with comments | « src/opts/SkXfermode_opts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698