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

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

Issue 349663005: always use 64 bit long for fixed mul (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 | « gyp/common_conditions.gypi ('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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 SkFixed_DEFINED 8 #ifndef SkFixed_DEFINED
9 #define SkFixed_DEFINED 9 #define SkFixed_DEFINED
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) 71 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16)
72 #define SkFixedFloorToInt(x) ((x) >> 16) 72 #define SkFixedFloorToInt(x) ((x) >> 16)
73 73
74 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000) 74 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000)
75 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) 75 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
76 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) 76 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
77 77
78 #define SkFixedAbs(x) SkAbs32(x) 78 #define SkFixedAbs(x) SkAbs32(x)
79 #define SkFixedAve(a, b) (((a) + (b)) >> 1) 79 #define SkFixedAve(a, b) (((a) + (b)) >> 1)
80 80
81 SkFixed SkFixedMul_portable(SkFixed, SkFixed);
82
83 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 81 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
84 82
85 /////////////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////////////
86 // TODO: move fixed sin/cos into SkCosineMapper, as that is the only caller 84 // TODO: move fixed sin/cos into SkCosineMapper, as that is the only caller
87 // or rewrite SkCosineMapper to not use it at all 85 // or rewrite SkCosineMapper to not use it at all
88 86
89 SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValueOrNull); 87 SkFixed SkFixedSinCos(SkFixed radians, SkFixed* cosValueOrNull);
90 #define SkFixedSin(radians) SkFixedSinCos(radians, NULL) 88 #define SkFixedSin(radians) SkFixedSinCos(radians, NULL)
91 static inline SkFixed SkFixedCos(SkFixed radians) { 89 static inline SkFixed SkFixedCos(SkFixed radians) {
92 SkFixed cosValue; 90 SkFixed cosValue;
93 (void)SkFixedSinCos(radians, &cosValue); 91 (void)SkFixedSinCos(radians, &cosValue);
94 return cosValue; 92 return cosValue;
95 } 93 }
96 94
95 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b)
96 {
97 return (SkFixed)((int64_t)a * b >> 16);
98 }
99
100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
101
97 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 102 //////////////////////////////////////////////////////////////////////////////// //////////////////////
98 // Now look for ASM overrides for our portable versions (should consider putting this in its own file) 103 // Now look for ASM overrides for our portable versions (should consider putting this in its own file)
99 104
100 #ifdef SkLONGLONG
101 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b)
102 {
103 return (SkFixed)((int64_t)a * b >> 16);
104 }
105 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
106 #endif
107
108 #if defined(SK_CPU_ARM32) 105 #if defined(SK_CPU_ARM32)
109 /* This guy does not handle NaN or other obscurities, but is faster than 106 /* This guy does not handle NaN or other obscurities, but is faster than
110 than (int)(x*65536). When built on Android with -Os, needs forcing 107 than (int)(x*65536). When built on Android with -Os, needs forcing
111 to inline or we lose the speed benefit. 108 to inline or we lose the speed benefit.
112 */ 109 */
113 SK_ALWAYS_INLINE SkFixed SkFloatToFixed_arm(float x) 110 SK_ALWAYS_INLINE SkFixed SkFloatToFixed_arm(float x)
114 { 111 {
115 int32_t y, z; 112 int32_t y, z;
116 asm("movs %1, %3, lsl #1 \n" 113 asm("movs %1, %3, lsl #1 \n"
117 "mov %2, #0x8E \n" 114 "mov %2, #0x8E \n"
(...skipping 21 matching lines...) Expand all
139 ); 136 );
140 return x; 137 return x;
141 } 138 }
142 #undef SkFixedMul 139 #undef SkFixedMul
143 #define SkFixedMul(x, y) SkFixedMul_arm(x, y) 140 #define SkFixedMul(x, y) SkFixedMul_arm(x, y)
144 141
145 #undef SkFloatToFixed 142 #undef SkFloatToFixed
146 #define SkFloatToFixed(x) SkFloatToFixed_arm(x) 143 #define SkFloatToFixed(x) SkFloatToFixed_arm(x)
147 #endif 144 #endif
148 145
149 #ifndef SkFixedMul
150 #define SkFixedMul(x, y) SkFixedMul_portable(x, y)
151 #endif
152
153 /////////////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////////////
154 147
155 typedef int64_t SkFixed48; 148 typedef int64_t SkFixed48;
156 149
157 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48) 150 #define SkIntToFixed48(x) ((SkFixed48)(x) << 48)
158 #define SkFixed48ToInt(x) ((int)((x) >> 48)) 151 #define SkFixed48ToInt(x) ((int)((x) >> 48))
159 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32) 152 #define SkFixedToFixed48(x) ((SkFixed48)(x) << 32)
160 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32)) 153 #define SkFixed48ToFixed(x) ((SkFixed)((x) >> 32))
161 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f))) 154 #define SkFloatToFixed48(x) ((SkFixed48)((x) * (65536.0f * 65536.0f * 65536. 0f)))
162 155
163 #define SkScalarToFixed48(x) SkFloatToFixed48(x) 156 #define SkScalarToFixed48(x) SkFloatToFixed48(x)
164 157
165 #endif 158 #endif
OLDNEW
« no previous file with comments | « gyp/common_conditions.gypi ('k') | include/core/SkPostConfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698