[libc] [llvm] [libc] Refactor `BigInt` (PR #86137)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 21:20:21 PDT 2024
================
@@ -244,18 +244,30 @@ LIBC_INLINE constexpr bool is_negative(cpp::array<word, N> &array) {
enum Direction { LEFT, RIGHT };
// A bitwise shift on an array of elements.
+// TODO: Make the result UB when 'offset' is greater or equal to the number of
+// bits in 'array'. This will allow for better code performance.
template <Direction direction, bool is_signed, typename word, size_t N>
-LIBC_INLINE constexpr void shift(cpp::array<word, N> &array, size_t offset) {
+LIBC_INLINE constexpr cpp::array<word, N> shift(cpp::array<word, N> array,
+ size_t offset) {
constexpr size_t WORD_BITS = cpp::numeric_limits<word>::digits;
constexpr size_t TOTAL_BITS = N * WORD_BITS;
if (offset == 0)
- return;
- if (offset >= TOTAL_BITS) {
- array = {};
- return;
+ return array;
+ if (offset >= TOTAL_BITS)
----------------
lntue wrote:
Use `LIBC_UNLIKELY` to provide hints for these two exceptional cases?
https://github.com/llvm/llvm-project/pull/86137
More information about the llvm-commits
mailing list