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

Side by Side Diff: include/core/SkMath.h

Issue 1271533002: Make SkIsPow2 templated (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: don't rename Created 5 years, 4 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 | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkMath_DEFINED 10 #ifndef SkMath_DEFINED
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 */ 143 */
144 static inline int SkNextLog2(uint32_t value) { 144 static inline int SkNextLog2(uint32_t value) {
145 SkASSERT(value != 0); 145 SkASSERT(value != 0);
146 return 32 - SkCLZ(value - 1); 146 return 32 - SkCLZ(value - 1);
147 } 147 }
148 148
149 /** 149 /**
150 * Returns true if value is a power of 2. Does not explicitly check for 150 * Returns true if value is a power of 2. Does not explicitly check for
151 * value <= 0. 151 * value <= 0.
152 */ 152 */
153 static inline bool SkIsPow2(int value) { 153 template <typename T> inline bool SkIsPow2(T value) {
154 return (value & (value - 1)) == 0; 154 return (value & (value - 1)) == 0;
155 } 155 }
156 156
157 /////////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////////
158 158
159 /** 159 /**
160 * SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t. 160 * SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t.
161 * With this requirement, we can generate faster instructions on some 161 * With this requirement, we can generate faster instructions on some
162 * architectures. 162 * architectures.
163 */ 163 */
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 *div = static_cast<Out>(d); 223 *div = static_cast<Out>(d);
224 *mod = static_cast<Out>(numer-d*denom); 224 *mod = static_cast<Out>(numer-d*denom);
225 #else 225 #else
226 // On x86 this will just be a single idiv. 226 // On x86 this will just be a single idiv.
227 *div = static_cast<Out>(numer/denom); 227 *div = static_cast<Out>(numer/denom);
228 *mod = static_cast<Out>(numer%denom); 228 *mod = static_cast<Out>(numer%denom);
229 #endif 229 #endif
230 } 230 }
231 231
232 #endif 232 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698