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

Side by Side Diff: src/core/SkHalf.h

Issue 2276533002: f16<->f32 ftz is an optional thing for speed. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 months 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 | « no previous file | tests/Float16Test.cpp » ('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 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
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
OLDNEW
« no previous file with comments | « no previous file | tests/Float16Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698