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

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

Issue 1184113003: Thorough tests for saturatedAdd and mulDiv255Round. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fix portable saturatedAdd() Created 5 years, 6 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 | 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_DEFINED 8 #ifndef SkNx_DEFINED
9 #define SkNx_DEFINED 9 #define SkNx_DEFINED
10 10
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 public: 177 public:
178 SkNi() {} 178 SkNi() {}
179 explicit SkNi(T val) : fVal(val) {} 179 explicit SkNi(T val) : fVal(val) {}
180 static SkNi Load(const T vals[1]) { return SkNi(vals[0]); } 180 static SkNi Load(const T vals[1]) { return SkNi(vals[0]); }
181 181
182 void store(T vals[1]) const { vals[0] = fVal; } 182 void store(T vals[1]) const { vals[0] = fVal; }
183 183
184 SkNi saturatedAdd(const SkNi& o) const { 184 SkNi saturatedAdd(const SkNi& o) const {
185 SkASSERT((T)(~0) > 0); // TODO: support signed T 185 SkASSERT((T)(~0) > 0); // TODO: support signed T
186 T sum = fVal + o.fVal; 186 T sum = fVal + o.fVal;
187 return SkNi(sum > fVal ? sum : (T)(~0)); 187 return SkNi(sum < fVal ? (T)(~0) : sum);
188 } 188 }
189 189
190 SkNi operator + (const SkNi& o) const { return SkNi(fVal + o.fVal); } 190 SkNi operator + (const SkNi& o) const { return SkNi(fVal + o.fVal); }
191 SkNi operator - (const SkNi& o) const { return SkNi(fVal - o.fVal); } 191 SkNi operator - (const SkNi& o) const { return SkNi(fVal - o.fVal); }
192 SkNi operator * (const SkNi& o) const { return SkNi(fVal * o.fVal); } 192 SkNi operator * (const SkNi& o) const { return SkNi(fVal * o.fVal); }
193 193
194 SkNi operator << (int bits) const { return SkNi(fVal << bits); } 194 SkNi operator << (int bits) const { return SkNi(fVal << bits); }
195 SkNi operator >> (int bits) const { return SkNi(fVal >> bits); } 195 SkNi operator >> (int bits) const { return SkNi(fVal >> bits); }
196 196
197 static SkNi Min(const SkNi& a, const SkNi& b) { return SkNi(SkTMin(a.fVal, b .fVal)); } 197 static SkNi Min(const SkNi& a, const SkNi& b) { return SkNi(SkTMin(a.fVal, b .fVal)); }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 typedef SkNi<4, uint16_t> Sk4h; 282 typedef SkNi<4, uint16_t> Sk4h;
283 typedef SkNi<8, uint16_t> Sk8h; 283 typedef SkNi<8, uint16_t> Sk8h;
284 typedef SkNi<16, uint16_t> Sk16h; 284 typedef SkNi<16, uint16_t> Sk16h;
285 285
286 typedef SkNi<16, uint8_t> Sk16b; 286 typedef SkNi<16, uint8_t> Sk16b;
287 287
288 typedef SkNi<4, int32_t> Sk4i; 288 typedef SkNi<4, int32_t> Sk4i;
289 typedef SkNi<4, uint32_t> Sk4u; 289 typedef SkNi<4, uint32_t> Sk4u;
290 290
291 #endif//SkNx_DEFINED 291 #endif//SkNx_DEFINED
OLDNEW
« no previous file with comments | « no previous file | tests/SkNxTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698