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

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

Issue 18539004: ARM Skia NEON patches - 04 - Clean SkFixed / SkLONGLONG (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove SkLONGLONG + use int64_t where there was an existing long long SkFixed implementation Created 7 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 | Annotate | Revision Log
« no previous file with comments | « include/core/Sk64.h ('k') | include/core/SkPostConfig.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 /* 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 SkFixed_DEFINED 10 #ifndef SkFixed_DEFINED
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) 113 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
114 114
115 // DEPRECATED 115 // DEPRECATED
116 #define SkFixedFloor(x) SkFixedFloorToInt(x) 116 #define SkFixedFloor(x) SkFixedFloorToInt(x)
117 #define SkFixedCeil(x) SkFixedCeilToInt(x) 117 #define SkFixedCeil(x) SkFixedCeilToInt(x)
118 #define SkFixedRound(x) SkFixedRoundToInt(x) 118 #define SkFixedRound(x) SkFixedRoundToInt(x)
119 119
120 #define SkFixedAbs(x) SkAbs32(x) 120 #define SkFixedAbs(x) SkAbs32(x)
121 #define SkFixedAve(a, b) (((a) + (b)) >> 1) 121 #define SkFixedAve(a, b) (((a) + (b)) >> 1)
122 122
123 SkFixed SkFixedMul_portable(SkFixed, SkFixed);
124 SkFract SkFractMul_portable(SkFract, SkFract);
125 inline SkFixed SkFixedSquare_portable(SkFixed value)
126 {
127 uint32_t a = SkAbs32(value);
128 uint32_t ah = a >> 16;
129 uint32_t al = a & 0xFFFF;
130 SkFixed result = ah * a + al * ah + (al * al >> 16);
131 if (result >= 0)
132 return result;
133 else // Overflow.
134 return SK_FixedMax;
135 }
136
137 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 123 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
138 SkFixed SkFixedDivInt(int32_t numer, int32_t denom); 124 SkFixed SkFixedDivInt(int32_t numer, int32_t denom);
139 SkFixed SkFixedMod(SkFixed numer, SkFixed denom); 125 SkFixed SkFixedMod(SkFixed numer, SkFixed denom);
140 #define SkFixedInvert(n) SkDivBits(SK_Fixed1, n, 16) 126 #define SkFixedInvert(n) SkDivBits(SK_Fixed1, n, 16)
141 SkFixed SkFixedFastInvert(SkFixed n); 127 SkFixed SkFixedFastInvert(SkFixed n);
142 #define SkFixedSqrt(n) SkSqrtBits(n, 23) 128 #define SkFixedSqrt(n) SkSqrtBits(n, 23)
143 SkFixed SkFixedMean(SkFixed a, SkFixed b); //*< returns sqrt(x*y) 129 SkFixed SkFixedMean(SkFixed a, SkFixed b); //*< returns sqrt(x*y)
144 int SkFixedMulCommon(SkFixed, int , int bias); // internal used by SkFixedMulFl oor, SkFixedMulCeil, SkFixedMulRound 130 int SkFixedMulCommon(SkFixed, int , int bias); // internal used by SkFixedMulFl oor, SkFixedMulCeil, SkFixedMulRound
145 131
146 #define SkFractDiv(numer, denom) SkDivBits(numer, denom, 30) 132 #define SkFractDiv(numer, denom) SkDivBits(numer, denom, 30)
(...skipping 15 matching lines...) Expand all
162 SkFixed SkFixedLog(SkFixed); 148 SkFixed SkFixedLog(SkFixed);
163 149
164 #define SK_FixedNearlyZero (SK_Fixed1 >> 12) 150 #define SK_FixedNearlyZero (SK_Fixed1 >> 12)
165 151
166 inline bool SkFixedNearlyZero(SkFixed x, SkFixed tolerance = SK_FixedNearlyZero) 152 inline bool SkFixedNearlyZero(SkFixed x, SkFixed tolerance = SK_FixedNearlyZero)
167 { 153 {
168 SkASSERT(tolerance > 0); 154 SkASSERT(tolerance > 0);
169 return SkAbs32(x) < tolerance; 155 return SkAbs32(x) < tolerance;
170 } 156 }
171 157
158 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b)
159 {
160 return (SkFixed)((int64_t)a * b >> 16);
161 }
162
163 inline SkFract SkFractMul_longlong(SkFract a, SkFract b)
164 {
165 return (SkFract)((int64_t)a * b >> 30);
166 }
167
168 inline SkFixed SkFixedSquare_longlong(SkFixed value)
169 {
170 return (SkFixed)((int64_t)value * value >> 16);
171 }
172
173 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
174 #define SkFractMul(a,b) SkFractMul_longlong(a,b)
175 #define SkFixedSquare(a) SkFixedSquare_longlong(a)
176
172 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 177 //////////////////////////////////////////////////////////////////////////////// //////////////////////
173 // Now look for ASM overrides for our portable versions (should consider putting this in its own file) 178 // Now look for ASM overrides for our portable versions (should consider putting this in its own file)
174 179
175 #ifdef SkLONGLONG
176 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b)
177 {
178 return (SkFixed)((SkLONGLONG)a * b >> 16);
179 }
180 inline SkFract SkFractMul_longlong(SkFract a, SkFract b)
181 {
182 return (SkFract)((SkLONGLONG)a * b >> 30);
183 }
184 inline SkFixed SkFixedSquare_longlong(SkFixed value)
185 {
186 return (SkFixed)((SkLONGLONG)value * value >> 16);
187 }
188 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
189 #define SkFractMul(a,b) SkFractMul_longlong(a,b)
190 #define SkFixedSquare(a) SkFixedSquare_longlong(a)
191 #endif
192
193 #if defined(SK_CPU_ARM) 180 #if defined(SK_CPU_ARM)
194 /* This guy does not handle NaN or other obscurities, but is faster than 181 /* This guy does not handle NaN or other obscurities, but is faster than
195 than (int)(x*65536) 182 than (int)(x*65536)
196 */ 183 */
197 inline SkFixed SkFloatToFixed_arm(float x) 184 inline SkFixed SkFloatToFixed_arm(float x)
198 { 185 {
199 register int32_t y, z; 186 register int32_t y, z;
200 asm("movs %1, %3, lsl #1 \n" 187 asm("movs %1, %3, lsl #1 \n"
201 "mov %2, #0x8E \n" 188 "mov %2, #0x8E \n"
202 "sub %1, %2, %1, lsr #24 \n" 189 "sub %1, %2, %1, lsr #24 \n"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 242
256 #undef SkFloatToFixed 243 #undef SkFloatToFixed
257 #define SkFloatToFixed(x) SkFloatToFixed_arm(x) 244 #define SkFloatToFixed(x) SkFloatToFixed_arm(x)
258 #endif 245 #endif
259 246
260 /////////////////////// Now define our macros to the portable versions if they w eren't overridden 247 /////////////////////// Now define our macros to the portable versions if they w eren't overridden
261 248
262 #ifndef SkFixedSquare 249 #ifndef SkFixedSquare
263 #define SkFixedSquare(x) SkFixedSquare_portable(x) 250 #define SkFixedSquare(x) SkFixedSquare_portable(x)
264 #endif 251 #endif
265 #ifndef SkFixedMul
266 #define SkFixedMul(x, y) SkFixedMul_portable(x, y)
267 #endif
268 #ifndef SkFractMul
269 #define SkFractMul(x, y) SkFractMul_portable(x, y)
270 #endif
271 #ifndef SkFixedMulAdd 252 #ifndef SkFixedMulAdd
272 #define SkFixedMulAdd(x, y, a) (SkFixedMul(x, y) + (a)) 253 #define SkFixedMulAdd(x, y, a) (SkFixedMul(x, y) + (a))
273 #endif 254 #endif
274 255
275 /////////////////////////////////////////////////////////////////////////////// 256 ///////////////////////////////////////////////////////////////////////////////
276 257
277 typedef int64_t SkFixed48; 258 typedef int64_t SkFixed48;
278 259
279 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48) 260 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48)
280 #define SkFixed48ToInt(x) ((int)((x) >> 48)) 261 #define SkFixed48ToInt(x) ((int)((x) >> 48))
281 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32) 262 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32)
282 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32)) 263 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32))
283 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f))) 264 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f)))
284 265
285 #ifdef SK_SCALAR_IS_FLOAT 266 #ifdef SK_SCALAR_IS_FLOAT
286 #define SkScalarToFixed48(x) SkFloatToFixed48(x) 267 #define SkScalarToFixed48(x) SkFloatToFixed48(x)
287 #else 268 #else
288 #define SkScalarToFixed48(x) SkFixedToFixed48(x) 269 #define SkScalarToFixed48(x) SkFixedToFixed48(x)
289 #endif 270 #endif
290 271
291 #endif 272 #endif
OLDNEW
« no previous file with comments | « include/core/Sk64.h ('k') | include/core/SkPostConfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698