[libc-commits] [libc] [libc] Make add_with_carry and sub_with_borrow constexpr. (PR #81898)
via libc-commits
libc-commits at lists.llvm.org
Thu Feb 15 10:51:12 PST 2024
================
@@ -69,48 +67,68 @@ add_with_carry(T a, T b, T carry_in) {
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
template <>
-LIBC_INLINE SumCarry<unsigned char>
+LIBC_INLINE constexpr SumCarry<unsigned char>
add_with_carry<unsigned char>(unsigned char a, unsigned char b,
unsigned char carry_in) {
- SumCarry<unsigned char> result{0, 0};
- result.sum = __builtin_addcb(a, b, carry_in, &result.carry);
- return result;
+ if (__builtin_is_constant_evaluated()) {
----------------
lntue wrote:
I've checked on godbolt, and seems like it works fine on clang 9.0+ and gcc 11+ in all x86-64, arm32, and riscv-32
https://github.com/llvm/llvm-project/pull/81898
More information about the libc-commits
mailing list