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

Side by Side Diff: src/core/SkNx.h

Issue 1059743002: Use switch operator[](int) to kth<int>() so we can use vget_lane. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « no previous file | src/core/SkPMFloat.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_DEFINED 8 #ifndef SkNx_DEFINED
9 #define SkNx_DEFINED 9 #define SkNx_DEFINED
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 static SkNf Max(const SkNf& l, const SkNf& r) { 71 static SkNf Max(const SkNf& l, const SkNf& r) {
72 return SkNf(SkNf<N/2,T>::Max(l.fLo, r.fLo), SkNf<N/2,T>::Max(l.fHi, r.fH i)); 72 return SkNf(SkNf<N/2,T>::Max(l.fLo, r.fLo), SkNf<N/2,T>::Max(l.fHi, r.fH i));
73 } 73 }
74 74
75 SkNf sqrt() const { return SkNf(fLo. sqrt(), fHi. sqrt()); } 75 SkNf sqrt() const { return SkNf(fLo. sqrt(), fHi. sqrt()); }
76 SkNf rsqrt() const { return SkNf(fLo.rsqrt(), fHi.rsqrt()); } 76 SkNf rsqrt() const { return SkNf(fLo.rsqrt(), fHi.rsqrt()); }
77 77
78 SkNf invert() const { return SkNf(fLo. invert(), fHi. invert ()); } 78 SkNf invert() const { return SkNf(fLo. invert(), fHi. invert ()); }
79 SkNf approxInvert() const { return SkNf(fLo.approxInvert(), fHi.approxInvert ()); } 79 SkNf approxInvert() const { return SkNf(fLo.approxInvert(), fHi.approxInvert ()); }
80 80
81 T operator[] (int k) const { 81 template <int k> T kth() const {
82 SkASSERT(0 <= k && k < N); 82 SkASSERT(0 <= k && k < N);
83 return k < N/2 ? fLo[k] : fHi[k-N/2]; 83 return k < N/2 ? fLo.template kth<k>() : fHi.template kth<k-N/2>();
84 } 84 }
85 85
86 private: 86 private:
87 REQUIRE(0 == (N & (N-1))); 87 REQUIRE(0 == (N & (N-1)));
88 SkNf(const SkNf<N/2, T>& lo, const SkNf<N/2, T>& hi) : fLo(lo), fHi(hi) {} 88 SkNf(const SkNf<N/2, T>& lo, const SkNf<N/2, T>& hi) : fLo(lo), fHi(hi) {}
89 89
90 SkNf<N/2, T> fLo, fHi; 90 SkNf<N/2, T> fLo, fHi;
91 }; 91 };
92 92
93 93
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 static SkNf Min(const SkNf& l, const SkNf& r) { return SkNf(SkTMin(l.fVal, r .fVal)); } 131 static SkNf Min(const SkNf& l, const SkNf& r) { return SkNf(SkTMin(l.fVal, r .fVal)); }
132 static SkNf Max(const SkNf& l, const SkNf& r) { return SkNf(SkTMax(l.fVal, r .fVal)); } 132 static SkNf Max(const SkNf& l, const SkNf& r) { return SkNf(SkTMax(l.fVal, r .fVal)); }
133 133
134 SkNf sqrt() const { return SkNf(Sqrt(fVal)); } 134 SkNf sqrt() const { return SkNf(Sqrt(fVal)); }
135 SkNf rsqrt() const { return SkNf((T)1 / Sqrt(fVal)); } 135 SkNf rsqrt() const { return SkNf((T)1 / Sqrt(fVal)); }
136 136
137 SkNf invert() const { return SkNf((T)1 / fVal); } 137 SkNf invert() const { return SkNf((T)1 / fVal); }
138 SkNf approxInvert() const { return this->invert(); } 138 SkNf approxInvert() const { return this->invert(); }
139 139
140 T operator[] (int SkDEBUGCODE(k)) const { 140 template <int k> T kth() const {
141 SkASSERT(k == 0); 141 SkASSERT(k == 0);
142 return fVal; 142 return fVal;
143 } 143 }
144 144
145 private: 145 private:
146 // We do double sqrts natively, or via floats for any other type. 146 // We do double sqrts natively, or via floats for any other type.
147 template <typename U> 147 template <typename U>
148 static U Sqrt(U val) { return (U) ::sqrtf((float)val); } 148 static U Sqrt(U val) { return (U) ::sqrtf((float)val); }
149 static double Sqrt(double val) { return ::sqrt ( val); } 149 static double Sqrt(double val) { return ::sqrt ( val); }
150 150
151 T fVal; 151 T fVal;
152 }; 152 };
153 153
154 154
155 // Generic syntax sugar that should work equally well for all SkNi and SkNf impl ementations. 155 // Generic syntax sugar that should work equally well for all SkNi and SkNf impl ementations.
156 template <typename SkNx> SkNx operator - (const SkNx& l) { return SkNx((decltype (l[0]))0) - l; } 156 template <typename SkNx> SkNx operator - (const SkNx& l) { return SkNx(0) - l; }
157 157
158 template <typename SkNx> SkNx& operator += (SkNx& l, const SkNx& r) { return (l = l + r); } 158 template <typename SkNx> SkNx& operator += (SkNx& l, const SkNx& r) { return (l = l + r); }
159 template <typename SkNx> SkNx& operator -= (SkNx& l, const SkNx& r) { return (l = l - r); } 159 template <typename SkNx> SkNx& operator -= (SkNx& l, const SkNx& r) { return (l = l - r); }
160 template <typename SkNx> SkNx& operator *= (SkNx& l, const SkNx& r) { return (l = l * r); } 160 template <typename SkNx> SkNx& operator *= (SkNx& l, const SkNx& r) { return (l = l * r); }
161 template <typename SkNx> SkNx& operator /= (SkNx& l, const SkNx& r) { return (l = l / r); } 161 template <typename SkNx> SkNx& operator /= (SkNx& l, const SkNx& r) { return (l = l / r); }
162 162
163 163
164 // Include platform specific specializations if available. 164 // Include platform specific specializations if available.
165 #ifndef SKNX_NO_SIMD 165 #ifndef SKNX_NO_SIMD
166 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 166 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
167 #include "../opts/SkNx_sse.h" 167 #include "../opts/SkNx_sse.h"
168 #elif defined(SK_ARM_HAS_NEON) 168 #elif defined(SK_ARM_HAS_NEON)
169 #include "../opts/SkNx_neon.h" 169 #include "../opts/SkNx_neon.h"
170 #endif 170 #endif
171 #endif 171 #endif
172 172
173 #undef REQUIRE 173 #undef REQUIRE
174 174
175 typedef SkNf<2, float> Sk2f; 175 typedef SkNf<2, float> Sk2f;
176 typedef SkNf<2, double> Sk2d; 176 typedef SkNf<2, double> Sk2d;
177 typedef SkNf<2, SkScalar> Sk2s; 177 typedef SkNf<2, SkScalar> Sk2s;
178 178
179 typedef SkNf<4, float> Sk4f; 179 typedef SkNf<4, float> Sk4f;
180 typedef SkNf<4, double> Sk4d; 180 typedef SkNf<4, double> Sk4d;
181 typedef SkNf<4, SkScalar> Sk4s; 181 typedef SkNf<4, SkScalar> Sk4s;
182 182
183 typedef SkNi<4, int32_t> Sk4i; 183 typedef SkNi<4, int32_t> Sk4i;
184 184
185 #endif//SkNx_DEFINED 185 #endif//SkNx_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698