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

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

Issue 24159009: Add SkDivMod with a special case for ARM. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: appease gcc on 10.6 Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkBitmap.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 /* 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 * Return a*b/255, rounding any fractional bits. 166 * Return a*b/255, rounding any fractional bits.
167 * Only valid if a and b are unsigned and <= 32767. 167 * Only valid if a and b are unsigned and <= 32767.
168 */ 168 */
169 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) { 169 static inline U8CPU SkMulDiv255Round(U16CPU a, U16CPU b) {
170 SkASSERT(a <= 32767); 170 SkASSERT(a <= 32767);
171 SkASSERT(b <= 32767); 171 SkASSERT(b <= 32767);
172 unsigned prod = SkMulS16(a, b) + 128; 172 unsigned prod = SkMulS16(a, b) + 128;
173 return (prod + (prod >> 8)) >> 8; 173 return (prod + (prod >> 8)) >> 8;
174 } 174 }
175 175
176 /**
177 * Stores numer/denom and numer%denom into div and mod respectively.
178 */
179 template <typename In, typename Out>
180 inline void SkTDivMod(In numer, In denom, Out* div, Out* mod) {
181 #ifdef SK_CPU_ARM
182 // If we wrote this as in the else branch, GCC won't fuse the two into one
183 // divmod call, but rather a div call followed by a divmod. Silly! This
184 // version is just as fast as calling __aeabi_[u]idivmod manually, but with
185 // prettier code.
186 //
187 // This benches as around 2x faster than the code in the else branch.
188 const In d = numer/denom;
189 *div = static_cast<Out>(d);
190 *mod = static_cast<Out>(numer-d*denom);
191 #else
192 // On x86 this will just be a single idiv.
193 *div = static_cast<Out>(numer/denom);
194 *mod = static_cast<Out>(numer%denom);
195 #endif // SK_CPU_ARM
196 }
197
176 #endif 198 #endif
OLDNEW
« no previous file with comments | « bench/MathBench.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698