OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #ifndef SkHalf_DEFINED | 8 #ifndef SkHalf_DEFINED |
9 #define SkHalf_DEFINED | 9 #define SkHalf_DEFINED |
10 | 10 |
11 #include "SkNx.h" | 11 #include "SkNx.h" |
12 #include "SkTypes.h" | 12 #include "SkTypes.h" |
13 | 13 |
14 // 16-bit floating point value | 14 // 16-bit floating point value |
15 // format is 1 bit sign, 5 bits exponent, 10 bits mantissa | 15 // format is 1 bit sign, 5 bits exponent, 10 bits mantissa |
16 // only used for storage | 16 // only used for storage |
17 typedef uint16_t SkHalf; | 17 typedef uint16_t SkHalf; |
18 | 18 |
19 static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-24 (minimum positive n
ormal value) | 19 static constexpr uint16_t SK_HalfMin = 0x0400; // 2^-24 (minimum positive n
ormal value) |
20 static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 | 20 static constexpr uint16_t SK_HalfMax = 0x7bff; // 65504 |
21 static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 | 21 static constexpr uint16_t SK_HalfEpsilon = 0x1400; // 2^-10 |
22 static constexpr uint16_t SK_Half1 = 0x3C00; // 1 | 22 static constexpr uint16_t SK_Half1 = 0x3C00; // 1 |
23 | 23 |
24 // convert between half and single precision floating point | 24 // convert between half and single precision floating point |
25 float SkHalfToFloat(SkHalf h); | 25 float SkHalfToFloat(SkHalf h); |
26 SkHalf SkFloatToHalf(float f); | 26 SkHalf SkFloatToHalf(float f); |
27 | 27 |
28 // Convert between half and single precision floating point, | 28 // Convert between half and single precision floating point, |
29 // assuming inputs and outputs are both finite, and | 29 // assuming inputs and outputs are both finite, and may |
30 // flushing values which would be denormal half floats to zero. | 30 // flush values which would be denormal half floats to zero. |
31 static inline Sk4f SkHalfToFloat_finite_ftz(uint64_t); | 31 static inline Sk4f SkHalfToFloat_finite_ftz(uint64_t); |
32 static inline Sk4h SkFloatToHalf_finite_ftz(const Sk4f&); | 32 static inline Sk4h SkFloatToHalf_finite_ftz(const Sk4f&); |
33 | 33 |
34 // ~~~~~~~~~~~ impl ~~~~~~~~~~~~~~ // | 34 // ~~~~~~~~~~~ impl ~~~~~~~~~~~~~~ // |
35 | 35 |
36 // Like the serial versions in SkHalf.cpp, these are based on | 36 // Like the serial versions in SkHalf.cpp, these are based on |
37 // https://fgiesen.wordpress.com/2012/03/28/half-to-float-done-quic/ | 37 // https://fgiesen.wordpress.com/2012/03/28/half-to-float-done-quic/ |
38 | 38 |
39 // GCC 4.9 lacks the intrinsics to use ARMv8 f16<->f32 instructions, so we use i
nline assembly. | 39 // GCC 4.9 lacks the intrinsics to use ARMv8 f16<->f32 instructions, so we use i
nline assembly. |
40 | 40 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // For normal half floats, adjust the exponent from 127 bias to 15 bias, | 79 // For normal half floats, adjust the exponent from 127 bias to 15 bias, |
80 // then drop the bottom 13 mantissa bits. | 80 // then drop the bottom 13 mantissa bits. |
81 Sk4i norm = (positive - ((127 - 15) << 23)) >> 13; | 81 Sk4i norm = (positive - ((127 - 15) << 23)) >> 13; |
82 | 82 |
83 Sk4i merged = (sign >> 16) | (will_be_norm & norm); | 83 Sk4i merged = (sign >> 16) | (will_be_norm & norm); |
84 return SkNx_cast<uint16_t>(merged); | 84 return SkNx_cast<uint16_t>(merged); |
85 #endif | 85 #endif |
86 } | 86 } |
87 | 87 |
88 #endif | 88 #endif |
OLD | NEW |