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

Side by Side Diff: tests/SkNxTest.cpp

Issue 1676893002: fix float <---> uint16_t conversion, with Mike's tests. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkNx_sse.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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 REPORTER_ASSERT(r, is.kth<3>() == 1); 217 REPORTER_ASSERT(r, is.kth<3>() == 1);
218 } 218 }
219 219
220 DEF_TEST(SkNx_abs, r) { 220 DEF_TEST(SkNx_abs, r) {
221 auto fs = Sk4f(0.0f, -0.0f, 2.0f, -4.0f).abs(); 221 auto fs = Sk4f(0.0f, -0.0f, 2.0f, -4.0f).abs();
222 REPORTER_ASSERT(r, fs.kth<0>() == 0.0f); 222 REPORTER_ASSERT(r, fs.kth<0>() == 0.0f);
223 REPORTER_ASSERT(r, fs.kth<1>() == 0.0f); 223 REPORTER_ASSERT(r, fs.kth<1>() == 0.0f);
224 REPORTER_ASSERT(r, fs.kth<2>() == 2.0f); 224 REPORTER_ASSERT(r, fs.kth<2>() == 2.0f);
225 REPORTER_ASSERT(r, fs.kth<3>() == 4.0f); 225 REPORTER_ASSERT(r, fs.kth<3>() == 4.0f);
226 } 226 }
227
228 #include "SkRandom.h"
229
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) {
237 {
238 // u16 --> float
239 auto h4 = Sk4h(15, 17, 257, 65535);
240 auto f4 = SkNx_cast<float>(h4);
241 dump(f4, h4);
242 REPORTER_ASSERT(r, f4.kth<0>() == 15.0f);
243 REPORTER_ASSERT(r, f4.kth<1>() == 17.0f);
244 REPORTER_ASSERT(r, f4.kth<2>() == 257.0f);
245 REPORTER_ASSERT(r, f4.kth<3>() == 65535.0f);
246 }
247 {
248 // float -> u16
249 auto f4 = Sk4f(15, 17, 257, 65535);
250 auto h4 = SkNx_cast<uint16_t>(f4);
251 dump(f4, h4);
252 REPORTER_ASSERT(r, h4.kth<0>() == 15);
253 REPORTER_ASSERT(r, h4.kth<1>() == 17);
254 REPORTER_ASSERT(r, h4.kth<2>() == 257);
255 REPORTER_ASSERT(r, h4.kth<3>() == 65535);
256 }
257
258 // starting with any u16 value, we should be able to have a perfect round-tr ip in/out of floats
259 //
260 SkRandom rand;
261 for (int i = 0; i < 0; ++i) {
262 const uint16_t s16[4] {
263 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(),
264 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(),
265 };
266 auto u4_0 = Sk4h::Load(s16);
267 auto f4 = SkNx_cast<float>(u4_0);
268 auto u4_1 = SkNx_cast<uint16_t>(f4);
269 uint16_t d16[4];
270 u4_1.store(d16);
271 REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16)));
272 }
273 }
OLDNEW
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698