| 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_DISCARD_DENORMALIZED_FOR_SPEED |
| 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) { |
| 93 return 0; |
| 94 } |
| 95 #else |
| 88 exp = 25; | 96 exp = 25; |
| 97 #endif |
| 89 } | 98 } |
| 90 // int add = 0; | 99 // int add = 0; |
| 91 return value >> exp; | 100 return value >> exp; |
| 92 } | 101 } |
| 93 } | 102 } |
| 94 | 103 |
| 95 // same as (int)floor(float + 0.5) | 104 // same as (int)floor(float + 0.5) |
| 96 int32_t SkFloatBits_toIntRound(int32_t packed) { | 105 int32_t SkFloatBits_toIntRound(int32_t packed) { |
| 97 // curse you negative 0 | 106 // curse you negative 0 |
| 98 if ((packed << 1) == 0) { | 107 if ((packed << 1) == 0) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } else { | 147 } else { |
| 139 value <<= exp; | 148 value <<= exp; |
| 140 } | 149 } |
| 141 // apply the sign after we check for overflow | 150 // apply the sign after we check for overflow |
| 142 return SkApplySign(value, SkExtractSign(packed)); | 151 return SkApplySign(value, SkExtractSign(packed)); |
| 143 } else { | 152 } else { |
| 144 // apply the sign before we right-shift | 153 // apply the sign before we right-shift |
| 145 value = SkApplySign(value, SkExtractSign(packed)); | 154 value = SkApplySign(value, SkExtractSign(packed)); |
| 146 exp = -exp; | 155 exp = -exp; |
| 147 if (exp > 25) { // underflow | 156 if (exp > 25) { // underflow |
| 157 #ifdef SK_DISCARD_DENORMALIZED_FOR_SPEED |
| 158 // The iOS ARM processor discards small denormalized numbers to go faste
r. |
| 159 // The comparision below empirically causes the result to agree with the |
| 160 // tests in MathTest test_float_ceil |
| 161 if (exp > 149) { |
| 162 return 0; |
| 163 } |
| 164 return 0 < value; |
| 165 #else |
| 148 exp = 25; | 166 exp = 25; |
| 167 #endif |
| 149 } | 168 } |
| 150 int add = (1 << exp) - 1; | 169 int add = (1 << exp) - 1; |
| 151 return (value + add) >> exp; | 170 return (value + add) >> exp; |
| 152 } | 171 } |
| 153 } | 172 } |
| 154 | 173 |
| 155 float SkIntToFloatCast(int32_t value) { | 174 float SkIntToFloatCast(int32_t value) { |
| 156 if (0 == value) { | 175 if (0 == value) { |
| 157 return 0; | 176 return 0; |
| 158 } | 177 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 value = SkApplySign(value, sign); | 216 value = SkApplySign(value, sign); |
| 198 | 217 |
| 199 int zeros = SkCLZ(value << 8); | 218 int zeros = SkCLZ(value << 8); |
| 200 value <<= zeros; | 219 value <<= zeros; |
| 201 shift -= zeros; | 220 shift -= zeros; |
| 202 | 221 |
| 203 SkFloatIntUnion data; | 222 SkFloatIntUnion data; |
| 204 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI
G); | 223 data.fSignBitInt = (sign << 31) | (shift << 23) | (value & ~MATISSA_MAGIC_BI
G); |
| 205 return data.fFloat; | 224 return data.fFloat; |
| 206 } | 225 } |
| OLD | NEW |