OLD | NEW |
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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), | 281 (uint16_t)rand.nextU16(), (uint16_t)rand.nextU16(), |
282 }; | 282 }; |
283 auto u4_0 = Sk4h::Load(s16); | 283 auto u4_0 = Sk4h::Load(s16); |
284 auto f4 = SkNx_cast<float>(u4_0); | 284 auto f4 = SkNx_cast<float>(u4_0); |
285 auto u4_1 = SkNx_cast<uint16_t>(f4); | 285 auto u4_1 = SkNx_cast<uint16_t>(f4); |
286 uint16_t d16[4]; | 286 uint16_t d16[4]; |
287 u4_1.store(d16); | 287 u4_1.store(d16); |
288 REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16))); | 288 REPORTER_ASSERT(r, !memcmp(s16, d16, sizeof(s16))); |
289 } | 289 } |
290 } | 290 } |
| 291 |
| 292 // The SSE2 implementation of SkNx_cast<uint16_t>(Sk4i) is non-trivial, so worth
a test. |
| 293 DEF_TEST(SkNx_int_u16, r) { |
| 294 // These are pretty hard to get wrong. |
| 295 for (int i = 0; i <= 0x7fff; i++) { |
| 296 uint16_t expected = (uint16_t)i; |
| 297 uint16_t actual = SkNx_cast<uint16_t>(Sk4i(i))[0]; |
| 298 |
| 299 REPORTER_ASSERT(r, expected == actual); |
| 300 } |
| 301 |
| 302 // A naive implementation with _mm_packs_epi32 would succeed up to 0x7fff bu
t fail here: |
| 303 for (int i = 0x8000; (1) && i <= 0xffff; i++) { |
| 304 uint16_t expected = (uint16_t)i; |
| 305 uint16_t actual = SkNx_cast<uint16_t>(Sk4i(i))[0]; |
| 306 |
| 307 REPORTER_ASSERT(r, expected == actual); |
| 308 } |
| 309 } |
OLD | NEW |