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

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

Issue 1503423003: ubsan shift fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add cast to work around win compiler Created 5 years 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 | include/core/SkTypes.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 #define SkFixedAbs(x) SkAbs32(x) 82 #define SkFixedAbs(x) SkAbs32(x)
83 #define SkFixedAve(a, b) (((a) + (b)) >> 1) 83 #define SkFixedAve(a, b) (((a) + (b)) >> 1)
84 84
85 // Blink layout tests are baselined to Clang optimizing through undefined behavi or in SkDivBits. 85 // Blink layout tests are baselined to Clang optimizing through undefined behavi or in SkDivBits.
86 #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB) 86 #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB)
87 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 87 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
88 #else 88 #else
89 // TODO(reed): this clamp shouldn't be needed. Use SkToS32(). 89 // TODO(reed): this clamp shouldn't be needed. Use SkToS32().
90 #define SkFixedDiv(numer, denom) \ 90 #define SkFixedDiv(numer, denom) \
91 SkTPin<int32_t>(((int64_t)numer << 16) / denom, SK_MinS32, SK_MaxS32) 91 SkTPin<int32_t>((int32_t)(SkLeftShift((int64_t)numer, 16) / denom), SK_M inS32, SK_MaxS32)
92 #endif 92 #endif
93 93
94 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 94 //////////////////////////////////////////////////////////////////////////////// //////////////////////
95 // Now look for ASM overrides for our portable versions (should consider putting this in its own file) 95 // Now look for ASM overrides for our portable versions (should consider putting this in its own file)
96 96
97 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) { 97 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) {
98 return (SkFixed)((int64_t)a * b >> 16); 98 return (SkFixed)((int64_t)a * b >> 16);
99 } 99 }
100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) 100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
101 101
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 #define SkFixedMul(x, y) SkFixedMul_arm(x, y) 138 #define SkFixedMul(x, y) SkFixedMul_arm(x, y)
139 139
140 #undef SkFloatToFixed 140 #undef SkFloatToFixed
141 #define SkFloatToFixed(x) SkFloatToFixed_arm(x) 141 #define SkFloatToFixed(x) SkFloatToFixed_arm(x)
142 #endif 142 #endif
143 143
144 /////////////////////////////////////////////////////////////////////////////// 144 ///////////////////////////////////////////////////////////////////////////////
145 145
146 typedef int64_t SkFixed3232; // 32.32 146 typedef int64_t SkFixed3232; // 32.32
147 147
148 #define SkIntToFixed3232(x) ((SkFixed3232)(x) << 32) 148 #define SkIntToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 32))
149 #define SkFixed3232ToInt(x) ((int)((x) >> 32)) 149 #define SkFixed3232ToInt(x) ((int)((x) >> 32))
150 #define SkFixedToFixed3232(x) ((SkFixed3232)(x) << 16) 150 #define SkFixedToFixed3232(x) (SkLeftShift((SkFixed3232)(x), 16))
151 #define SkFixed3232ToFixed(x) ((SkFixed)((x) >> 16)) 151 #define SkFixed3232ToFixed(x) ((SkFixed)((x) >> 16))
152 #define SkFloatToFixed3232(x) ((SkFixed3232)((x) * (65536.0f * 65536.0f))) 152 #define SkFloatToFixed3232(x) ((SkFixed3232)((x) * (65536.0f * 65536.0f)))
153 153
154 #define SkScalarToFixed3232(x) SkFloatToFixed3232(x) 154 #define SkScalarToFixed3232(x) SkFloatToFixed3232(x)
155 155
156 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
157 157
158 // 64bits wide, with a 16bit bias. Useful when accumulating lots of 16.16 so 158 // 64bits wide, with a 16bit bias. Useful when accumulating lots of 16.16 so
159 // we don't overflow along the way 159 // we don't overflow along the way
160 typedef int64_t Sk48Dot16; 160 typedef int64_t Sk48Dot16;
161 161
162 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16) 162 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16)
163 163
164 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) { 164 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) {
165 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16)) 165 return static_cast<float>(x * 1.5258789e-5); // x * (1.0f / (1 << 16))
166 } 166 }
167 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16))) 167 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16)))
168 168
169 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x) 169 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x)
170 170
171 #endif 171 #endif
OLDNEW
« no previous file with comments | « no previous file | include/core/SkTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698