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

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

Issue 1679343004: Revert of Sk4f: add floor() (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_neon.h ('k') | tests/SkNxTest.cpp » ('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_sse_DEFINED 8 #ifndef SkNx_sse_DEFINED
9 #define SkNx_sse_DEFINED 9 #define SkNx_sse_DEFINED
10 10
11 // This file may assume <= SSE2, but must check SK_CPU_SSE_LEVEL for anything mo re recent. 11 // This file may assume <= SSE2, but must check SK_CPU_SSE_LEVEL for anything mo re recent.
12 // If you do, make sure this is in a static inline function... anywhere else ris ks violating ODR. 12 // If you do, make sure this is in a static inline function... anywhere else ris ks violating ODR.
13 13
14 #define SKNX_IS_FAST 14 #define SKNX_IS_FAST
15 15
16 // SSE 4.1 has _mm_floor_ps to floor 4 floats. We emulate it:
17 // - round by adding (1<<23) with our sign, then subtracting it;
18 // - if that rounded value is bigger than our input, subtract 1.
19 static inline __m128 sse2_mm_floor_ps(__m128 v) {
20 __m128 sign = _mm_and_ps(v, _mm_set1_ps(-0.0f));
21 __m128 bias = _mm_or_ps(sign, _mm_set1_ps(1<<23));
22 __m128 rounded = _mm_sub_ps(_mm_add_ps(v, bias), bias);
23 __m128 too_big = _mm_cmpgt_ps(rounded, v);
24 return _mm_sub_ps(rounded, _mm_and_ps(too_big, _mm_set1_ps(1.0f)));
25 }
26
27 template <> 16 template <>
28 class SkNx<2, float> { 17 class SkNx<2, float> {
29 public: 18 public:
30 SkNx(const __m128& vec) : fVec(vec) {} 19 SkNx(const __m128& vec) : fVec(vec) {}
31 20
32 SkNx() {} 21 SkNx() {}
33 SkNx(float val) : fVec(_mm_set1_ps(val)) {} 22 SkNx(float val) : fVec(_mm_set1_ps(val)) {}
34 static SkNx Load(const void* ptr) { 23 static SkNx Load(const void* ptr) {
35 return _mm_castsi128_ps(_mm_loadl_epi64((const __m128i*)ptr)); 24 return _mm_castsi128_ps(_mm_loadl_epi64((const __m128i*)ptr));
36 } 25 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 SkNx operator != (const SkNx& o) const { return _mm_cmpneq_ps(fVec, o.fVec); } 85 SkNx operator != (const SkNx& o) const { return _mm_cmpneq_ps(fVec, o.fVec); }
97 SkNx operator < (const SkNx& o) const { return _mm_cmplt_ps (fVec, o.fVec); } 86 SkNx operator < (const SkNx& o) const { return _mm_cmplt_ps (fVec, o.fVec); }
98 SkNx operator > (const SkNx& o) const { return _mm_cmpgt_ps (fVec, o.fVec); } 87 SkNx operator > (const SkNx& o) const { return _mm_cmpgt_ps (fVec, o.fVec); }
99 SkNx operator <= (const SkNx& o) const { return _mm_cmple_ps (fVec, o.fVec); } 88 SkNx operator <= (const SkNx& o) const { return _mm_cmple_ps (fVec, o.fVec); }
100 SkNx operator >= (const SkNx& o) const { return _mm_cmpge_ps (fVec, o.fVec); } 89 SkNx operator >= (const SkNx& o) const { return _mm_cmpge_ps (fVec, o.fVec); }
101 90
102 static SkNx Min(const SkNx& l, const SkNx& r) { return _mm_min_ps(l.fVec, r. fVec); } 91 static SkNx Min(const SkNx& l, const SkNx& r) { return _mm_min_ps(l.fVec, r. fVec); }
103 static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r. fVec); } 92 static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r. fVec); }
104 93
105 SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); } 94 SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); }
106 SkNx floor() const { return sse2_mm_floor_ps(fVec); }
107 95
108 SkNx sqrt () const { return _mm_sqrt_ps (fVec); } 96 SkNx sqrt () const { return _mm_sqrt_ps (fVec); }
109 SkNx rsqrt0() const { return _mm_rsqrt_ps(fVec); } 97 SkNx rsqrt0() const { return _mm_rsqrt_ps(fVec); }
110 SkNx rsqrt1() const { return this->rsqrt0(); } 98 SkNx rsqrt1() const { return this->rsqrt0(); }
111 SkNx rsqrt2() const { return this->rsqrt1(); } 99 SkNx rsqrt2() const { return this->rsqrt1(); }
112 100
113 SkNx invert() const { return SkNx(1) / *this; } 101 SkNx invert() const { return SkNx(1) / *this; }
114 SkNx approxInvert() const { return _mm_rcp_ps(fVec); } 102 SkNx approxInvert() const { return _mm_rcp_ps(fVec); }
115 103
116 float operator[](int k) const { 104 float operator[](int k) const {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 336
349 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) { 337 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) {
350 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128()); 338 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128());
351 } 339 }
352 340
353 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) { 341 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) {
354 return _mm_packus_epi16(src.fVec, src.fVec); 342 return _mm_packus_epi16(src.fVec, src.fVec);
355 } 343 }
356 344
357 #endif//SkNx_sse_DEFINED 345 #endif//SkNx_sse_DEFINED
OLDNEW
« no previous file with comments | « src/opts/SkNx_neon.h ('k') | tests/SkNxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698