OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 4153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4164 | 4164 |
4165 template <class Traits> | 4165 template <class Traits> |
4166 typename Traits::ElementType FixedTypedArray<Traits>::from_double( | 4166 typename Traits::ElementType FixedTypedArray<Traits>::from_double( |
4167 double value) { | 4167 double value) { |
4168 return static_cast<ElementType>(DoubleToInt32(value)); | 4168 return static_cast<ElementType>(DoubleToInt32(value)); |
4169 } | 4169 } |
4170 | 4170 |
4171 | 4171 |
4172 template<> inline | 4172 template<> inline |
4173 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_double(double value) { | 4173 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_double(double value) { |
4174 if (value < 0) return 0; | 4174 // Handle NaNs and less than zero values which clamp to zero. |
| 4175 if (!(value > 0)) return 0; |
4175 if (value > 0xFF) return 0xFF; | 4176 if (value > 0xFF) return 0xFF; |
4176 return static_cast<uint8_t>(lrint(value)); | 4177 return static_cast<uint8_t>(lrint(value)); |
4177 } | 4178 } |
4178 | 4179 |
4179 | 4180 |
4180 template<> inline | 4181 template<> inline |
4181 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { | 4182 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { |
4182 return static_cast<float>(value); | 4183 return static_cast<float>(value); |
4183 } | 4184 } |
4184 | 4185 |
(...skipping 3100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7285 #undef READ_SHORT_FIELD | 7286 #undef READ_SHORT_FIELD |
7286 #undef WRITE_SHORT_FIELD | 7287 #undef WRITE_SHORT_FIELD |
7287 #undef READ_BYTE_FIELD | 7288 #undef READ_BYTE_FIELD |
7288 #undef WRITE_BYTE_FIELD | 7289 #undef WRITE_BYTE_FIELD |
7289 #undef NOBARRIER_READ_BYTE_FIELD | 7290 #undef NOBARRIER_READ_BYTE_FIELD |
7290 #undef NOBARRIER_WRITE_BYTE_FIELD | 7291 #undef NOBARRIER_WRITE_BYTE_FIELD |
7291 | 7292 |
7292 } } // namespace v8::internal | 7293 } } // namespace v8::internal |
7293 | 7294 |
7294 #endif // V8_OBJECTS_INL_H_ | 7295 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |