diff options
author | mtklein <mtklein@chromium.org> | 2016-02-09 13:46:49 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-09 13:46:49 -0800 |
commit | 86c6c4935171a1d2d6a9ffbff37ec6dac1326614 (patch) | |
tree | 500badd83fef02cc26d45ab047ce38fb7efd4568 /src/opts | |
parent | b8d6e088590160f1198110c2371b802c1d541a36 (diff) |
Sk4f: add floor()
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1685773002
CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot
Review URL: https://codereview.chromium.org/1685773002
Diffstat (limited to 'src/opts')
-rw-r--r-- | src/opts/SkNx_neon.h | 19 | ||||
-rw-r--r-- | src/opts/SkNx_sse.h | 12 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/opts/SkNx_neon.h b/src/opts/SkNx_neon.h index 2cb8eb348d..cdc4615849 100644 --- a/src/opts/SkNx_neon.h +++ b/src/opts/SkNx_neon.h @@ -10,6 +10,17 @@ #define SKNX_IS_FAST +// ARMv8 has vrndmq_f32 to floor 4 floats. Here we emulate it: +// - round by adding (1<<23) with our sign, then subtracting it; +// - if that rounded value is bigger than our input, subtract 1. +static inline float32x4_t armv7_vrndmq_f32(float32x4_t v) { + auto sign = vandq_u32((uint32x4_t)v, vdupq_n_u32(1<<31)); + auto bias = (float32x4_t)(vorrq_u32((uint32x4_t)vdupq_n_f32(1<<23), sign)); + auto rounded = vsubq_f32(vaddq_f32(v, bias), bias); + auto too_big = vcgtq_f32(rounded, v); + return vsubq_f32(rounded, (float32x4_t)vandq_u32(too_big, (uint32x4_t)vdupq_n_f32(1))); +} + // Well, this is absurd. The shifts require compile-time constant arguments. #define SHIFT8(op, v, bits) switch(bits) { \ @@ -161,6 +172,14 @@ public: static SkNx Max(const SkNx& l, const SkNx& r) { return vmaxq_f32(l.fVec, r.fVec); } SkNx abs() const { return vabsq_f32(fVec); } + SkNx floor() const { + #if defined(SK_CPU_ARM64) + return vrndmq_f32(fVec); + #else + return armv7_vrndmq_f32(fVec); + #endif + } + SkNx rsqrt0() const { return vrsqrteq_f32(fVec); } SkNx rsqrt1() const { diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h index 889253b9d8..def7ba1719 100644 --- a/src/opts/SkNx_sse.h +++ b/src/opts/SkNx_sse.h @@ -13,6 +13,17 @@ #define SKNX_IS_FAST +// SSE 4.1 has _mm_floor_ps to floor 4 floats. We emulate it: +// - round by adding (1<<23) with our sign, then subtracting it; +// - if that rounded value is bigger than our input, subtract 1. +static inline __m128 sse2_mm_floor_ps(__m128 v) { + __m128 sign = _mm_and_ps(v, _mm_set1_ps(-0.0f)); + __m128 bias = _mm_or_ps(sign, _mm_set1_ps(1<<23)); + __m128 rounded = _mm_sub_ps(_mm_add_ps(v, bias), bias); + __m128 too_big = _mm_cmpgt_ps(rounded, v); + return _mm_sub_ps(rounded, _mm_and_ps(too_big, _mm_set1_ps(1.0f))); +} + template <> class SkNx<2, float> { public: @@ -92,6 +103,7 @@ public: static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r.fVec); } SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); } + SkNx floor() const { return sse2_mm_floor_ps(fVec); } SkNx sqrt () const { return _mm_sqrt_ps (fVec); } SkNx rsqrt0() const { return _mm_rsqrt_ps(fVec); } |