1 //===-- Utilities for pairs of numbers. -------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_NUMBER_PAIR_H
10 #define LLVM_LIBC_SRC_SUPPORT_NUMBER_PAIR_H
12 #include "CPP/type_traits.h"
13 #include "named_pair.h"
17 namespace __llvm_libc
{
19 DEFINE_NAMED_PAIR_TEMPLATE(NumberPair
, lo
, hi
);
22 cpp::enable_if_t
<cpp::is_integral_v
<T
> && cpp::is_unsigned_v
<T
>, NumberPair
<T
>>
24 constexpr size_t HALF_BIT_WIDTH
= sizeof(T
) * 4;
25 constexpr T LOWER_HALF_MASK
= (T(1) << HALF_BIT_WIDTH
) - T(1);
27 result
.lo
= a
& LOWER_HALF_MASK
;
28 result
.hi
= a
>> HALF_BIT_WIDTH
;
32 } // namespace __llvm_libc
34 #endif // LLVM_LIBC_SRC_SUPPORT_NUMBER_PAIR_H