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

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

Issue 1682953002: Sk4f: floor() via int32_t roundtrip. (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 | « no previous file | src/opts/SkNx_sse.h » ('j') | 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 #ifndef SkNx_neon_DEFINED 8 #ifndef SkNx_neon_DEFINED
9 #define SkNx_neon_DEFINED 9 #define SkNx_neon_DEFINED
10 10
11 #define SKNX_IS_FAST 11 #define SKNX_IS_FAST
12 12
13 // ARMv8 has vrndmq_f32 to floor 4 floats. Here we emulate it: 13 // ARMv8 has vrndmq_f32 to floor 4 floats. Here we emulate it:
14 // - round by adding (1<<23) with our sign, then subtracting it; 14 // - roundtrip through integers via truncation
15 // - if that rounded value is bigger than our input, subtract 1. 15 // - subtract 1 if that's too big (possible for negative values).
16 // This restricts the domain of our inputs to a maximum somehwere around 2^31. Seems plenty big.
16 static inline float32x4_t armv7_vrndmq_f32(float32x4_t v) { 17 static inline float32x4_t armv7_vrndmq_f32(float32x4_t v) {
17 auto sign = vandq_u32((uint32x4_t)v, vdupq_n_u32(1<<31)); 18 auto roundtrip = vcvtq_f32_s32(vcvtq_s32_f32(v));
18 auto bias = (float32x4_t)(vorrq_u32((uint32x4_t)vdupq_n_f32(1<<23), sign)); 19 auto too_big = vcgtq_f32(roundtrip, v);
19 auto rounded = vsubq_f32(vaddq_f32(v, bias), bias); 20 return vsubq_f32(roundtrip, (float32x4_t)vandq_u32(too_big, (uint32x4_t)vdup q_n_f32(1)));
20 auto too_big = vcgtq_f32(rounded, v);
21 return vsubq_f32(rounded, (float32x4_t)vandq_u32(too_big, (uint32x4_t)vdupq_ n_f32(1)));
22 } 21 }
23 22
24 // Well, this is absurd. The shifts require compile-time constant arguments. 23 // Well, this is absurd. The shifts require compile-time constant arguments.
25 24
26 #define SHIFT8(op, v, bits) switch(bits) { \ 25 #define SHIFT8(op, v, bits) switch(bits) { \
27 case 1: return op(v, 1); case 2: return op(v, 2); case 3: return op(v , 3); \ 26 case 1: return op(v, 1); case 2: return op(v, 2); case 3: return op(v , 3); \
28 case 4: return op(v, 4); case 5: return op(v, 5); case 6: return op(v , 6); \ 27 case 4: return op(v, 4); case 5: return op(v, 5); case 6: return op(v , 6); \
29 case 7: return op(v, 7); \ 28 case 7: return op(v, 7); \
30 } return fVec 29 } return fVec
31 30
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 387
389 template<> inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) { 388 template<> inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) {
390 return vget_low_u16(vmovl_u8(src.fVec)); 389 return vget_low_u16(vmovl_u8(src.fVec));
391 } 390 }
392 391
393 template<> inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) { 392 template<> inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) {
394 return vmovn_u16(vcombine_u16(src.fVec, src.fVec)); 393 return vmovn_u16(vcombine_u16(src.fVec, src.fVec));
395 } 394 }
396 395
397 #endif//SkNx_neon_DEFINED 396 #endif//SkNx_neon_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/opts/SkNx_sse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698