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

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

Issue 1891513002: skcpu: sse4.1 floor, f16c f16<->f32 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: invert #ifs Created 4 years, 8 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/core/SkXfermodeF16.cpp ('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 #ifndef SkNx_sse_DEFINED 8 #ifndef SkNx_sse_DEFINED
9 #define SkNx_sse_DEFINED 9 #define SkNx_sse_DEFINED
10 10
11 #include "SkCpu.h"
12
11 // This file may assume <= SSE2, but must check SK_CPU_SSE_LEVEL for anything mo re recent. 13 // 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. 14 // If you do, make sure this is in a static inline function... anywhere else ris ks violating ODR.
13 15
14 #define SKNX_IS_FAST 16 #define SKNX_IS_FAST
15 17
16 // SSE 4.1 has _mm_floor_ps to floor 4 floats. We emulate it:
17 // - roundtrip through integers via truncation
18 // - subtract 1 if that's too big (possible for negative values).
19 // This restricts the domain of our inputs to a maximum somehwere around 2^31. Seems plenty big.
20 static inline __m128 sse2_mm_floor_ps(__m128 v) {
21 __m128 roundtrip = _mm_cvtepi32_ps(_mm_cvttps_epi32(v));
22 __m128 too_big = _mm_cmpgt_ps(roundtrip, v);
23 return _mm_sub_ps(roundtrip, _mm_and_ps(too_big, _mm_set1_ps(1.0f)));
24 }
25
26 template <> 18 template <>
27 class SkNx<2, float> { 19 class SkNx<2, float> {
28 public: 20 public:
29 SkNx(const __m128& vec) : fVec(vec) {} 21 SkNx(const __m128& vec) : fVec(vec) {}
30 22
31 SkNx() {} 23 SkNx() {}
32 SkNx(float val) : fVec(_mm_set1_ps(val)) {} 24 SkNx(float val) : fVec(_mm_set1_ps(val)) {}
33 static SkNx Load(const void* ptr) { 25 static SkNx Load(const void* ptr) {
34 return _mm_castsi128_ps(_mm_loadl_epi64((const __m128i*)ptr)); 26 return _mm_castsi128_ps(_mm_loadl_epi64((const __m128i*)ptr));
35 } 27 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 SkNx operator != (const SkNx& o) const { return _mm_cmpneq_ps(fVec, o.fVec); } 82 SkNx operator != (const SkNx& o) const { return _mm_cmpneq_ps(fVec, o.fVec); }
91 SkNx operator < (const SkNx& o) const { return _mm_cmplt_ps (fVec, o.fVec); } 83 SkNx operator < (const SkNx& o) const { return _mm_cmplt_ps (fVec, o.fVec); }
92 SkNx operator > (const SkNx& o) const { return _mm_cmpgt_ps (fVec, o.fVec); } 84 SkNx operator > (const SkNx& o) const { return _mm_cmpgt_ps (fVec, o.fVec); }
93 SkNx operator <= (const SkNx& o) const { return _mm_cmple_ps (fVec, o.fVec); } 85 SkNx operator <= (const SkNx& o) const { return _mm_cmple_ps (fVec, o.fVec); }
94 SkNx operator >= (const SkNx& o) const { return _mm_cmpge_ps (fVec, o.fVec); } 86 SkNx operator >= (const SkNx& o) const { return _mm_cmpge_ps (fVec, o.fVec); }
95 87
96 static SkNx Min(const SkNx& l, const SkNx& r) { return _mm_min_ps(l.fVec, r. fVec); } 88 static SkNx Min(const SkNx& l, const SkNx& r) { return _mm_min_ps(l.fVec, r. fVec); }
97 static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r. fVec); } 89 static SkNx Max(const SkNx& l, const SkNx& r) { return _mm_max_ps(l.fVec, r. fVec); }
98 90
99 SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); } 91 SkNx abs() const { return _mm_andnot_ps(_mm_set1_ps(-0.0f), fVec); }
100 SkNx floor() const { return sse2_mm_floor_ps(fVec); } 92 SkNx floor() const {
93 if (SkCpu::Supports(SkCpu::SSE41)) {
94 __m128 r;
95 #if defined(__GNUC__) || defined(__clang__)
96 asm("roundps $0x1, %[fVec], %[r]" : [r]"=x"(r) : [fVec]"x"(fVec));
97 #else
98 r = _mm_floor_ps(fVec);
99 #endif
100 return r;
101 }
102 // Emulate _mm_floor_ps() with SSE2:
103 // - roundtrip through integers via truncation
104 // - subtract 1 if that's too big (possible for negative values).
105 // This restricts the domain of our inputs to a maximum somehwere around 2^31.
106 // Seems plenty big.
107 __m128 roundtrip = _mm_cvtepi32_ps(_mm_cvttps_epi32(fVec));
108 __m128 too_big = _mm_cmpgt_ps(roundtrip, fVec);
109 return _mm_sub_ps(roundtrip, _mm_and_ps(too_big, _mm_set1_ps(1.0f)));
110 }
101 111
102 SkNx sqrt() const { return _mm_sqrt_ps (fVec); } 112 SkNx sqrt() const { return _mm_sqrt_ps (fVec); }
103 SkNx rsqrt() const { return _mm_rsqrt_ps(fVec); } 113 SkNx rsqrt() const { return _mm_rsqrt_ps(fVec); }
104 SkNx invert() const { return _mm_rcp_ps(fVec); } 114 SkNx invert() const { return _mm_rcp_ps(fVec); }
105 115
106 float operator[](int k) const { 116 float operator[](int k) const {
107 SkASSERT(0 <= k && k < 4); 117 SkASSERT(0 <= k && k < 4);
108 union { __m128 v; float fs[4]; } pun = {fVec}; 118 union { __m128 v; float fs[4]; } pun = {fVec};
109 return pun.fs[k&3]; 119 return pun.fs[k&3];
110 } 120 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 364
355 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) { 365 template<> /*static*/ inline Sk4h SkNx_cast<uint16_t, uint8_t>(const Sk4b& src) {
356 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128()); 366 return _mm_unpacklo_epi8(src.fVec, _mm_setzero_si128());
357 } 367 }
358 368
359 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) { 369 template<> /*static*/ inline Sk4b SkNx_cast<uint8_t, uint16_t>(const Sk4h& src) {
360 return _mm_packus_epi16(src.fVec, src.fVec); 370 return _mm_packus_epi16(src.fVec, src.fVec);
361 } 371 }
362 372
363 #endif//SkNx_sse_DEFINED 373 #endif//SkNx_sse_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkXfermodeF16.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698