Skip to content

Commit 3e64c40

Browse files
author
git apple-llvm automerger
committed
Merge commit '55e6c1901576' from llvm.org/main into next
2 parents 4765a71 + 55e6c19 commit 3e64c40

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ template <size_t Bits> struct DyadicFloat {
3737
int exponent = 0;
3838
MantissaType mantissa = MantissaType(0);
3939

40-
constexpr DyadicFloat() = default;
40+
LIBC_INLINE constexpr DyadicFloat() = default;
4141

4242
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) {
4444
static_assert(FPBits<T>::FRACTION_LEN < Bits);
4545
FPBits<T> x_bits(x);
4646
sign = x_bits.sign();
@@ -49,14 +49,14 @@ template <size_t Bits> struct DyadicFloat {
4949
normalize();
5050
}
5151

52-
constexpr DyadicFloat(Sign s, int e, MantissaType m)
52+
LIBC_INLINE constexpr DyadicFloat(Sign s, int e, MantissaType m)
5353
: sign(s), exponent(e), mantissa(m) {
5454
normalize();
5555
}
5656

5757
// Normalizing the mantissa, bringing the leading 1 bit to the most
5858
// significant bit.
59-
constexpr DyadicFloat &normalize() {
59+
LIBC_INLINE constexpr DyadicFloat &normalize() {
6060
if (!mantissa.is_zero()) {
6161
int shift_length = static_cast<int>(mantissa.clz());
6262
exponent -= shift_length;
@@ -66,14 +66,14 @@ template <size_t Bits> struct DyadicFloat {
6666
}
6767

6868
// 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) {
7070
exponent -= shift_length;
7171
mantissa <<= static_cast<size_t>(shift_length);
7272
return *this;
7373
}
7474

7575
// 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) {
7777
exponent += shift_length;
7878
mantissa >>= static_cast<size_t>(shift_length);
7979
return *this;
@@ -85,7 +85,7 @@ template <size_t Bits> struct DyadicFloat {
8585
typename = cpp::enable_if_t<cpp::is_floating_point_v<T> &&
8686
(FPBits<T>::FRACTION_LEN < Bits),
8787
void>>
88-
explicit operator T() const {
88+
LIBC_INLINE explicit constexpr operator T() const {
8989
if (LIBC_UNLIKELY(mantissa.is_zero()))
9090
return FPBits<T>::zero(sign).get_val();
9191

@@ -176,7 +176,7 @@ template <size_t Bits> struct DyadicFloat {
176176
return r;
177177
}
178178

179-
explicit operator MantissaType() const {
179+
LIBC_INLINE explicit constexpr operator MantissaType() const {
180180
if (mantissa.is_zero())
181181
return 0;
182182

@@ -208,8 +208,8 @@ template <size_t Bits> struct DyadicFloat {
208208
// don't need to normalize the inputs again in this function. If the inputs are
209209
// not normalized, the results might lose precision significantly.
210210
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) {
213213
if (LIBC_UNLIKELY(a.mantissa.is_zero()))
214214
return b;
215215
if (LIBC_UNLIKELY(b.mantissa.is_zero()))
@@ -263,8 +263,8 @@ constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
263263
// don't need to normalize the inputs again in this function. If the inputs are
264264
// not normalized, the results might lose precision significantly.
265265
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) {
268268
DyadicFloat<Bits> result;
269269
result.sign = (a.sign != b.sign) ? Sign::NEG : Sign::POS;
270270
result.exponent = a.exponent + b.exponent + int(Bits);
@@ -285,16 +285,17 @@ constexpr DyadicFloat<Bits> quick_mul(DyadicFloat<Bits> a,
285285

286286
// Simple polynomial approximation.
287287
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) {
291291
return quick_add(c, quick_mul(a, b));
292292
}
293293

294294
// Simple exponentiation implementation for printf. Only handles positive
295295
// exponents, since division isn't implemented.
296296
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) {
298299
DyadicFloat<Bits> result = 1.0;
299300
DyadicFloat<Bits> cur_power = a;
300301

@@ -309,7 +310,8 @@ constexpr DyadicFloat<Bits> pow_n(DyadicFloat<Bits> a, uint32_t power) {
309310
}
310311

311312
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) {
313315
DyadicFloat<Bits> result = a;
314316
result.exponent += pow_2;
315317
return result;

libc/src/__support/UInt.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct BigInt {
157157

158158
LIBC_INLINE constexpr explicit operator bool() const { return !is_zero(); }
159159

160-
LIBC_INLINE BigInt &operator=(const BigInt &other) = default;
160+
LIBC_INLINE constexpr BigInt &operator=(const BigInt &other) = default;
161161

162162
LIBC_INLINE constexpr bool is_zero() const {
163163
for (size_t i = 0; i < WORD_COUNT; ++i) {
@@ -172,7 +172,7 @@ struct BigInt {
172172
LIBC_INLINE constexpr WordType add(const BigInt &x) {
173173
SumCarry<WordType> s{0, 0};
174174
for (size_t i = 0; i < WORD_COUNT; ++i) {
175-
s = add_with_carry_const(val[i], x.val[i], s.carry);
175+
s = add_with_carry(val[i], x.val[i], s.carry);
176176
val[i] = s.sum;
177177
}
178178
return s.carry;
@@ -194,7 +194,7 @@ struct BigInt {
194194
BigInt result;
195195
SumCarry<WordType> s{0, 0};
196196
for (size_t i = 0; i < WORD_COUNT; ++i) {
197-
s = add_with_carry_const(val[i], other.val[i], s.carry);
197+
s = add_with_carry(val[i], other.val[i], s.carry);
198198
result.val[i] = s.sum;
199199
}
200200
return result;
@@ -210,7 +210,7 @@ struct BigInt {
210210
LIBC_INLINE constexpr WordType sub(const BigInt &x) {
211211
DiffBorrow<WordType> d{0, 0};
212212
for (size_t i = 0; i < WORD_COUNT; ++i) {
213-
d = sub_with_borrow_const(val[i], x.val[i], d.borrow);
213+
d = sub_with_borrow(val[i], x.val[i], d.borrow);
214214
val[i] = d.diff;
215215
}
216216
return d.borrow;
@@ -230,7 +230,7 @@ struct BigInt {
230230
BigInt result;
231231
DiffBorrow<WordType> d{0, 0};
232232
for (size_t i = 0; i < WORD_COUNT; ++i) {
233-
d = sub_with_borrow_const(val[i], other.val[i], d.borrow);
233+
d = sub_with_borrow(val[i], other.val[i], d.borrow);
234234
result.val[i] = d.diff;
235235
}
236236
return result;

libc/src/__support/integer_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace LIBC_NAMESPACE {
2121

22-
template <typename T> NumberPair<T> full_mul(T a, T b) {
22+
template <typename T> constexpr NumberPair<T> full_mul(T a, T b) {
2323
NumberPair<T> pa = split(a);
2424
NumberPair<T> pb = split(b);
2525
NumberPair<T> prod;
@@ -43,7 +43,8 @@ template <typename T> NumberPair<T> full_mul(T a, T b) {
4343
}
4444

4545
template <>
46-
LIBC_INLINE NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
46+
LIBC_INLINE constexpr NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a,
47+
uint32_t b) {
4748
uint64_t prod = uint64_t(a) * uint64_t(b);
4849
NumberPair<uint32_t> result;
4950
result.lo = uint32_t(prod);
@@ -53,7 +54,8 @@ LIBC_INLINE NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
5354

5455
#ifdef __SIZEOF_INT128__
5556
template <>
56-
LIBC_INLINE NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a, uint64_t b) {
57+
LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
58+
uint64_t b) {
5759
__uint128_t prod = __uint128_t(a) * __uint128_t(b);
5860
NumberPair<uint64_t> result;
5961
result.lo = uint64_t(prod);

libc/src/__support/number_pair.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
namespace LIBC_NAMESPACE {
1717

1818
template <typename T> struct NumberPair {
19-
T lo;
20-
T hi;
19+
T lo = T(0);
20+
T hi = T(0);
2121
};
2222

2323
template <typename T>

0 commit comments

Comments
 (0)