OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 #include "SkFloatBits.h" | 8 #include "SkFloatBits.h" |
9 #include "SkMathPriv.h" | 9 #include "SkMathPriv.h" |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } else { | 78 } else { |
79 value <<= exp; | 79 value <<= exp; |
80 } | 80 } |
81 // apply the sign after we check for overflow | 81 // apply the sign after we check for overflow |
82 return SkApplySign(value, SkExtractSign(packed)); | 82 return SkApplySign(value, SkExtractSign(packed)); |
83 } else { | 83 } else { |
84 // apply the sign before we right-shift | 84 // apply the sign before we right-shift |
85 value = SkApplySign(value, SkExtractSign(packed)); | 85 value = SkApplySign(value, SkExtractSign(packed)); |
86 exp = -exp; | 86 exp = -exp; |
87 if (exp > 25) { // underflow | 87 if (exp > 25) { // underflow |
88 #ifdef SK_FAST_UNDERFLOW_BEHAVIOR | |
89 // The iOS ARM processor discards small denormalized numbers to go faste r. | |
90 // The comparision below empirically causes the result to agree with the | |
91 // tests in MathTest test_float_floor | |
92 if (exp > 149) return 0; | |
reed1
2014/07/10 21:40:05
nit: {} and indentation
if (exp > 149) {
retu
caryclark
2014/07/11 12:57:19
Done.
| |
93 #else | |
88 exp = 25; | 94 exp = 25; |
95 #endif | |
89 } | 96 } |
90 // int add = 0; | 97 // int add = 0; |
91 return value >> exp; | 98 return value >> exp; |
92 } | 99 } |
93 } | 100 } |
94 | 101 |
95 // same as (int)floor(float + 0.5) | 102 // same as (int)floor(float + 0.5) |
96 int32_t SkFloatBits_toIntRound(int32_t packed) { | 103 int32_t SkFloatBits_toIntRound(int32_t packed) { |
97 // curse you negative 0 | 104 // curse you negative 0 |
98 if ((packed << 1) == 0) { | 105 if ((packed << 1) == 0) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 } else { | 145 } else { |
139 value <<= exp; | 146 value <<= exp; |
140 } | 147 } |
141 // apply the sign after we check for overflow | 148 // apply the sign after we check for overflow |
142 return SkApplySign(value, SkExtractSign(packed)); | 149 return SkApplySign(value, SkExtractSign(packed)); |
143 } else { | 150 } else { |
144 // apply the sign before we right-shift | 151 // apply the sign before we right-shift |
145 value = SkApplySign(value, SkExtractSign(packed)); | 152 value = SkApplySign(value, SkExtractSign(packed)); |
146 exp = -exp; | 153 exp = -exp; |
147 if (exp > 25) { // underflow | 154 if (exp > 25) { // underflow |
155 #ifdef SK_FAST_UNDERFLOW_BEHAVIOR | |
156 // The iOS ARM processor discards small denormalized numbers to go faste r. | |
157 // The comparision below empirically causes the result to agree with the | |
158 // tests in MathTest test_float_ceil | |
159 if (exp > 149) return 0; | |
160 return 0 < value; | |
161 #else | |
148 exp = 25; | 162 exp = 25; |
163 #endif | |
149 } | 164 } |
150 int add = (1 << exp) - 1; | 165 int add = (1 << exp) - 1; |
151 return (value + add) >> exp; | 166 return (value + add) >> exp; |
152 } | 167 } |
153 } | 168 } |
154 | 169 |
155 float SkIntToFloatCast(int32_t value) { | 170 float SkIntToFloatCast(int32_t value) { |
156 if (0 == value) { | 171 if (0 == value) { |
157 return 0; | 172 return 0; |
158 } | 173 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 value = SkApplySign(value, sign); | 212 value = SkApplySign(value, sign); |
198 | 213 |
199 int zeros = SkCLZ(value << 8); | 214 int zeros = SkCLZ(value << 8); |
200 value <<= zeros; | 215 value <<= zeros; |
201 shift -= zeros; | 216 shift -= zeros; |
202 | 217 |
203 SkFloatIntUnion data; | 218 SkFloatIntUnion data; |
204 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI G); | 219 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI G); |
205 return data.fFloat; | 220 return data.fFloat; |
206 } | 221 } |
OLD | NEW |