[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / number_pair.h
blobdc875d3141574adee81692ba55d507f3ad600207
1 //===-- Utilities for pairs of numbers. -------------------------*- C++ -*-===//
2 //
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
6 //
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"
15 #include <stddef.h>
17 namespace __llvm_libc {
19 DEFINE_NAMED_PAIR_TEMPLATE(NumberPair, lo, hi);
21 template <typename T>
22 cpp::enable_if_t<cpp::is_integral_v<T> && cpp::is_unsigned_v<T>, NumberPair<T>>
23 split(T a) {
24 constexpr size_t HALF_BIT_WIDTH = sizeof(T) * 4;
25 constexpr T LOWER_HALF_MASK = (T(1) << HALF_BIT_WIDTH) - T(1);
26 NumberPair<T> result;
27 result.lo = a & LOWER_HALF_MASK;
28 result.hi = a >> HALF_BIT_WIDTH;
29 return result;
32 } // namespace __llvm_libc
34 #endif // LLVM_LIBC_SRC_SUPPORT_NUMBER_PAIR_H