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

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

Issue 1455163004: Fix UB in SkDivBits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pin Created 5 years, 1 month 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 | « BUILD.public ('k') | tools/dm_flags.json » ('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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16) 75 #define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16)
76 #define SkFixedFloorToInt(x) ((x) >> 16) 76 #define SkFixedFloorToInt(x) ((x) >> 16)
77 77
78 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000) 78 #define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000)
79 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000) 79 #define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
80 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000) 80 #define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
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 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16) 85 // Blink layout tests are baselined to Clang optimizing through undefined behavi or in SkDivBits.
86 #if defined(SK_SUPPORT_LEGACY_DIVBITS_UB)
87 #define SkFixedDiv(numer, denom) SkDivBits(numer, denom, 16)
88 #else
89 // TODO(reed): this clamp shouldn't be needed. Use SkToS32().
90 #define SkFixedDiv(numer, denom) \
91 SkTPin<int32_t>(((int64_t)numer << 16) / denom, SK_MinS32, SK_MaxS32)
92 #endif
86 93
87 //////////////////////////////////////////////////////////////////////////////// ////////////////////// 94 //////////////////////////////////////////////////////////////////////////////// //////////////////////
88 // 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)
89 96
90 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) { 97 inline SkFixed SkFixedMul_longlong(SkFixed a, SkFixed b) {
91 return (SkFixed)((int64_t)a * b >> 16); 98 return (SkFixed)((int64_t)a * b >> 16);
92 } 99 }
93 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b) 100 #define SkFixedMul(a,b) SkFixedMul_longlong(a,b)
94 101
95 102
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16) 162 #define Sk48Dot16FloorToInt(x) static_cast<int>((x) >> 16)
156 163
157 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) { 164 static inline float Sk48Dot16ToScalar(Sk48Dot16 x) {
158 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))
159 } 166 }
160 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16))) 167 #define SkFloatTo48Dot16(x) (static_cast<Sk48Dot16>((x) * (1 << 16)))
161 168
162 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x) 169 #define SkScalarTo48Dot16(x) SkFloatTo48Dot16(x)
163 170
164 #endif 171 #endif
OLDNEW
« no previous file with comments | « BUILD.public ('k') | tools/dm_flags.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698