@@ -37,10 +37,10 @@ template <size_t Bits> struct DyadicFloat {
37
37
int exponent = 0 ;
38
38
MantissaType mantissa = MantissaType(0 );
39
39
40
- constexpr DyadicFloat () = default;
40
+ LIBC_INLINE constexpr DyadicFloat () = default;
41
41
42
42
template <typename T, cpp::enable_if_t <cpp::is_floating_point_v<T>, int > = 0 >
43
- DyadicFloat (T x) {
43
+ LIBC_INLINE constexpr DyadicFloat (T x) {
44
44
static_assert (FPBits<T>::FRACTION_LEN < Bits);
45
45
FPBits<T> x_bits (x);
46
46
sign = x_bits.sign ();
@@ -49,14 +49,14 @@ template <size_t Bits> struct DyadicFloat {
49
49
normalize ();
50
50
}
51
51
52
- constexpr DyadicFloat (Sign s, int e, MantissaType m)
52
+ LIBC_INLINE constexpr DyadicFloat (Sign s, int e, MantissaType m)
53
53
: sign(s), exponent(e), mantissa(m) {
54
54
normalize ();
55
55
}
56
56
57
57
// Normalizing the mantissa, bringing the leading 1 bit to the most
58
58
// significant bit.
59
- constexpr DyadicFloat &normalize () {
59
+ LIBC_INLINE constexpr DyadicFloat &normalize () {
60
60
if (!mantissa.is_zero ()) {
61
61
int shift_length = static_cast <int >(mantissa.clz ());
62
62
exponent -= shift_length;
@@ -66,14 +66,14 @@ template <size_t Bits> struct DyadicFloat {
66
66
}
67
67
68
68
// Used for aligning exponents. Output might not be normalized.
69
- DyadicFloat &shift_left (int shift_length) {
69
+ LIBC_INLINE constexpr DyadicFloat &shift_left (int shift_length) {
70
70
exponent -= shift_length;
71
71
mantissa <<= static_cast <size_t >(shift_length);
72
72
return *this ;
73
73
}
74
74
75
75
// Used for aligning exponents. Output might not be normalized.
76
- DyadicFloat &shift_right (int shift_length) {
76
+ LIBC_INLINE constexpr DyadicFloat &shift_right (int shift_length) {
77
77
exponent += shift_length;
78
78
mantissa >>= static_cast <size_t >(shift_length);
79
79
return *this ;
@@ -85,7 +85,7 @@ template <size_t Bits> struct DyadicFloat {
85
85
typename = cpp::enable_if_t <cpp::is_floating_point_v<T> &&
86
86
(FPBits<T>::FRACTION_LEN < Bits),
87
87
void >>
88
- explicit operator T () const {
88
+ LIBC_INLINE explicit constexpr operator T () const {
89
89
if (LIBC_UNLIKELY (mantissa.is_zero ()))
90
90
return FPBits<T>::zero (sign).get_val ();
91
91
@@ -176,7 +176,7 @@ template <size_t Bits> struct DyadicFloat {
176
176
return r;
177
177
}
178
178
179
- explicit operator MantissaType () const {
179
+ LIBC_INLINE explicit constexpr operator MantissaType () const {
180
180
if (mantissa.is_zero ())
181
181
return 0 ;
182
182
@@ -208,8 +208,8 @@ template <size_t Bits> struct DyadicFloat {
208
208
// don't need to normalize the inputs again in this function. If the inputs are
209
209
// not normalized, the results might lose precision significantly.
210
210
template <size_t Bits>
211
- constexpr DyadicFloat<Bits> quick_add (DyadicFloat<Bits> a,
212
- DyadicFloat<Bits> b) {
211
+ LIBC_INLINE constexpr DyadicFloat<Bits> quick_add (DyadicFloat<Bits> a,
212
+ DyadicFloat<Bits> b) {
213
213
if (LIBC_UNLIKELY (a.mantissa .is_zero ()))
214
214
return b;
215
215
if (LIBC_UNLIKELY (b.mantissa .is_zero ()))
@@ -263,8 +263,8 @@ constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
263
263
// don't need to normalize the inputs again in this function. If the inputs are
264
264
// not normalized, the results might lose precision significantly.
265
265
template <size_t Bits>
266
- constexpr DyadicFloat<Bits> quick_mul (DyadicFloat<Bits> a,
267
- DyadicFloat<Bits> b) {
266
+ LIBC_INLINE constexpr DyadicFloat<Bits> quick_mul (DyadicFloat<Bits> a,
267
+ DyadicFloat<Bits> b) {
268
268
DyadicFloat<Bits> result;
269
269
result.sign = (a.sign != b.sign ) ? Sign::NEG : Sign::POS;
270
270
result.exponent = a.exponent + b.exponent + int (Bits);
@@ -285,16 +285,17 @@ constexpr DyadicFloat<Bits> quick_mul(DyadicFloat<Bits> a,
285
285
286
286
// Simple polynomial approximation.
287
287
template <size_t Bits>
288
- constexpr DyadicFloat<Bits> multiply_add ( const DyadicFloat<Bits> &a,
289
- const DyadicFloat<Bits> &b,
290
- const DyadicFloat<Bits> &c) {
288
+ LIBC_INLINE constexpr DyadicFloat<Bits>
289
+ multiply_add ( const DyadicFloat<Bits> &a, const DyadicFloat<Bits> &b,
290
+ const DyadicFloat<Bits> &c) {
291
291
return quick_add (c, quick_mul (a, b));
292
292
}
293
293
294
294
// Simple exponentiation implementation for printf. Only handles positive
295
295
// exponents, since division isn't implemented.
296
296
template <size_t Bits>
297
- constexpr DyadicFloat<Bits> pow_n (DyadicFloat<Bits> a, uint32_t power) {
297
+ LIBC_INLINE constexpr DyadicFloat<Bits> pow_n (DyadicFloat<Bits> a,
298
+ uint32_t power) {
298
299
DyadicFloat<Bits> result = 1.0 ;
299
300
DyadicFloat<Bits> cur_power = a;
300
301
@@ -309,7 +310,8 @@ constexpr DyadicFloat<Bits> pow_n(DyadicFloat<Bits> a, uint32_t power) {
309
310
}
310
311
311
312
template <size_t Bits>
312
- constexpr DyadicFloat<Bits> mul_pow_2 (DyadicFloat<Bits> a, int32_t pow_2) {
313
+ LIBC_INLINE constexpr DyadicFloat<Bits> mul_pow_2 (DyadicFloat<Bits> a,
314
+ int32_t pow_2) {
313
315
DyadicFloat<Bits> result = a;
314
316
result.exponent += pow_2;
315
317
return result;
0 commit comments