forked from OSchip/llvm-project
Revert "[libc][NFC] Use STL case for bit"
This reverts commit 7ba14b8611
.
This commit is contained in:
parent
7ba14b8611
commit
175560fc21
|
@ -9,7 +9,7 @@
|
||||||
#ifndef LLVM_LIBC_SUPPORT_CPP_BIT_H
|
#ifndef LLVM_LIBC_SUPPORT_CPP_BIT_H
|
||||||
#define LLVM_LIBC_SUPPORT_CPP_BIT_H
|
#define LLVM_LIBC_SUPPORT_CPP_BIT_H
|
||||||
|
|
||||||
namespace __llvm_libc::cpp {
|
namespace __llvm_libc {
|
||||||
|
|
||||||
#if defined __has_builtin
|
#if defined __has_builtin
|
||||||
#if __has_builtin(__builtin_bit_cast)
|
#if __has_builtin(__builtin_bit_cast)
|
||||||
|
@ -43,6 +43,6 @@ template <class To, class From> constexpr To bit_cast(const From &from) {
|
||||||
#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
|
#endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace __llvm_libc::cpp
|
} // namespace __llvm_libc
|
||||||
|
|
||||||
#endif // LLVM_LIBC_SUPPORT_CPP_BIT_H
|
#endif // LLVM_LIBC_SUPPORT_CPP_BIT_H
|
|
@ -29,7 +29,7 @@ add_header_library(
|
||||||
add_header_library(
|
add_header_library(
|
||||||
bit
|
bit
|
||||||
HDRS
|
HDRS
|
||||||
bit.h
|
Bit.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_header_library(
|
add_header_library(
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "PlatformDefs.h"
|
#include "PlatformDefs.h"
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
#include "src/__support/FPUtil/builtin_wrappers.h"
|
#include "src/__support/FPUtil/builtin_wrappers.h"
|
||||||
#include "src/__support/common.h"
|
#include "src/__support/common.h"
|
||||||
|
@ -104,7 +104,8 @@ template <typename T> struct FPBits {
|
||||||
// We don't want accidental type promotions/conversions, so we require exact
|
// We don't want accidental type promotions/conversions, so we require exact
|
||||||
// type match.
|
// type match.
|
||||||
template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
|
template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
|
||||||
constexpr explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {}
|
constexpr explicit FPBits(XType x)
|
||||||
|
: bits(__llvm_libc::bit_cast<UIntType>(x)) {}
|
||||||
|
|
||||||
template <typename XType,
|
template <typename XType,
|
||||||
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
|
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
|
||||||
|
@ -112,9 +113,9 @@ template <typename T> struct FPBits {
|
||||||
|
|
||||||
FPBits() : bits(0) {}
|
FPBits() : bits(0) {}
|
||||||
|
|
||||||
T get_val() const { return cpp::bit_cast<T>(bits); }
|
T get_val() const { return __llvm_libc::bit_cast<T>(bits); }
|
||||||
|
|
||||||
void set_val(T value) { bits = cpp::bit_cast<UIntType>(value); }
|
void set_val(T value) { bits = __llvm_libc::bit_cast<UIntType>(value); }
|
||||||
|
|
||||||
explicit operator T() const { return get_val(); }
|
explicit operator T() const { return get_val(); }
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
#include "FEnvImpl.h"
|
#include "FEnvImpl.h"
|
||||||
#include "FPBits.h"
|
#include "FPBits.h"
|
||||||
#include "builtin_wrappers.h"
|
#include "builtin_wrappers.h"
|
||||||
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/UInt128.h"
|
#include "src/__support/CPP/UInt128.h"
|
||||||
#include "src/__support/CPP/bit.h"
|
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
|
|
||||||
namespace __llvm_libc {
|
namespace __llvm_libc {
|
||||||
|
@ -248,7 +248,7 @@ static inline T hypot(T x, T y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
y_new |= static_cast<UIntType>(out_exp) << MantissaWidth<T>::VALUE;
|
y_new |= static_cast<UIntType>(out_exp) << MantissaWidth<T>::VALUE;
|
||||||
return cpp::bit_cast<T>(y_new);
|
return __llvm_libc::bit_cast<T>(y_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fputil
|
} // namespace fputil
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "NormalFloat.h"
|
#include "NormalFloat.h"
|
||||||
#include "PlatformDefs.h"
|
#include "PlatformDefs.h"
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
@ -165,7 +165,7 @@ static inline T nextafter(T from, T to) {
|
||||||
int_val = (to_bits.uintval() & sign_mask) + UIntType(1);
|
int_val = (to_bits.uintval() & sign_mask) + UIntType(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cpp::bit_cast<T>(int_val);
|
return __llvm_libc::bit_cast<T>(int_val);
|
||||||
// TODO: Raise floating point exceptions as required by the standard.
|
// TODO: Raise floating point exceptions as required by the standard.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H
|
#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H
|
||||||
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H
|
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H
|
||||||
|
|
||||||
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/UInt128.h"
|
#include "src/__support/CPP/UInt128.h"
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
#include "src/__support/FPUtil/FEnvImpl.h"
|
#include "src/__support/FPUtil/FEnvImpl.h"
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_SQRT_H
|
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_SQRT_H
|
||||||
|
|
||||||
#include "sqrt_80_bit_long_double.h"
|
#include "sqrt_80_bit_long_double.h"
|
||||||
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/UInt128.h"
|
#include "src/__support/CPP/UInt128.h"
|
||||||
#include "src/__support/CPP/bit.h"
|
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
#include "src/__support/FPUtil/FEnvImpl.h"
|
#include "src/__support/FPUtil/FEnvImpl.h"
|
||||||
#include "src/__support/FPUtil/FPBits.h"
|
#include "src/__support/FPUtil/FPBits.h"
|
||||||
|
@ -161,7 +161,7 @@ static inline cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cpp::bit_cast<T>(y);
|
return __llvm_libc::bit_cast<T>(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
|
#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
|
||||||
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
|
#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
|
||||||
|
|
||||||
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/UInt128.h"
|
#include "src/__support/CPP/UInt128.h"
|
||||||
#include "src/__support/CPP/bit.h"
|
|
||||||
#include "src/__support/architectures.h"
|
#include "src/__support/architectures.h"
|
||||||
|
|
||||||
#if !defined(LLVM_LIBC_ARCH_X86)
|
#if !defined(LLVM_LIBC_ARCH_X86)
|
||||||
|
@ -101,7 +101,7 @@ template <> struct FPBits<long double> {
|
||||||
|
|
||||||
template <typename XType,
|
template <typename XType,
|
||||||
cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
|
cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
|
||||||
explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {
|
explicit FPBits(XType x) : bits(__llvm_libc::bit_cast<UIntType>(x)) {
|
||||||
// bits starts uninitialized, and setting it to a long double only
|
// bits starts uninitialized, and setting it to a long double only
|
||||||
// overwrites the first 80 bits. This clears those upper bits.
|
// overwrites the first 80 bits. This clears those upper bits.
|
||||||
bits = bits & ((UIntType(1) << 80) - 1);
|
bits = bits & ((UIntType(1) << 80) - 1);
|
||||||
|
@ -111,7 +111,7 @@ template <> struct FPBits<long double> {
|
||||||
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
|
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
|
||||||
explicit FPBits(XType x) : bits(x) {}
|
explicit FPBits(XType x) : bits(x) {}
|
||||||
|
|
||||||
operator long double() { return cpp::bit_cast<long double>(bits); }
|
operator long double() { return __llvm_libc::bit_cast<long double>(bits); }
|
||||||
|
|
||||||
UIntType uintval() {
|
UIntType uintval() {
|
||||||
// We zero the padding bits as they can contain garbage.
|
// We zero the padding bits as they can contain garbage.
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#error "Invalid include"
|
#error "Invalid include"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/FPUtil/FPBits.h"
|
#include "src/__support/FPUtil/FPBits.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -112,7 +112,7 @@ static inline long double nextafter(long double from, long double to) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cpp::bit_cast<long double>(int_val);
|
return __llvm_libc::bit_cast<long double>(int_val);
|
||||||
// TODO: Raise floating point exceptions as required by the standard.
|
// TODO: Raise floating point exceptions as required by the standard.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef LLVM_LIBC_SRC_MATH_MATH_UTILS_H
|
#ifndef LLVM_LIBC_SRC_MATH_MATH_UTILS_H
|
||||||
#define LLVM_LIBC_SRC_MATH_MATH_UTILS_H
|
#define LLVM_LIBC_SRC_MATH_MATH_UTILS_H
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
#include "src/__support/common.h"
|
#include "src/__support/common.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -20,16 +20,20 @@
|
||||||
namespace __llvm_libc {
|
namespace __llvm_libc {
|
||||||
|
|
||||||
static inline uint32_t as_uint32_bits(float x) {
|
static inline uint32_t as_uint32_bits(float x) {
|
||||||
return cpp::bit_cast<uint32_t>(x);
|
return __llvm_libc::bit_cast<uint32_t>(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t as_uint64_bits(double x) {
|
static inline uint64_t as_uint64_bits(double x) {
|
||||||
return cpp::bit_cast<uint64_t>(x);
|
return __llvm_libc::bit_cast<uint64_t>(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float as_float(uint32_t x) { return cpp::bit_cast<float>(x); }
|
static inline float as_float(uint32_t x) {
|
||||||
|
return __llvm_libc::bit_cast<float>(x);
|
||||||
|
}
|
||||||
|
|
||||||
static inline double as_double(uint64_t x) { return cpp::bit_cast<double>(x); }
|
static inline double as_double(uint64_t x) {
|
||||||
|
return __llvm_libc::bit_cast<double>(x);
|
||||||
|
}
|
||||||
|
|
||||||
static inline uint32_t top12_bits(float x) { return as_uint32_bits(x) >> 20; }
|
static inline uint32_t top12_bits(float x) { return as_uint32_bits(x) >> 20; }
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "src/__support/arg_list.h"
|
#include "src/__support/arg_list.h"
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/FPUtil/FPBits.h"
|
#include "src/__support/FPUtil/FPBits.h"
|
||||||
#include "src/__support/ctype_utils.h"
|
#include "src/__support/ctype_utils.h"
|
||||||
#include "src/__support/str_to_integer.h"
|
#include "src/__support/str_to_integer.h"
|
||||||
|
@ -132,10 +132,9 @@ FormatSection Parser::get_next_section() {
|
||||||
case ('G'):
|
case ('G'):
|
||||||
if (lm != LengthModifier::L)
|
if (lm != LengthModifier::L)
|
||||||
section.conv_val_raw =
|
section.conv_val_raw =
|
||||||
cpp::bit_cast<uint64_t>(GET_ARG_VAL_SIMPLEST(double, conv_index));
|
bit_cast<uint64_t>(GET_ARG_VAL_SIMPLEST(double, conv_index));
|
||||||
else
|
else
|
||||||
section.conv_val_raw =
|
section.conv_val_raw = bit_cast<fputil::FPBits<long double>::UIntType>(
|
||||||
cpp::bit_cast<fputil::FPBits<long double>::UIntType>(
|
|
||||||
GET_ARG_VAL_SIMPLEST(long double, conv_index));
|
GET_ARG_VAL_SIMPLEST(long double, conv_index));
|
||||||
break;
|
break;
|
||||||
#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT
|
#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
|
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
|
||||||
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
|
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/architectures.h"
|
#include "src/__support/architectures.h"
|
||||||
|
|
||||||
#if defined(LLVM_LIBC_ARCH_X86)
|
#if defined(LLVM_LIBC_ARCH_X86)
|
||||||
|
@ -68,18 +68,18 @@ struct M128 {
|
||||||
static uint16_t mask(T value) {
|
static uint16_t mask(T value) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return static_cast<uint16_t>(
|
return static_cast<uint16_t>(
|
||||||
_mm_movemask_epi8(cpp::bit_cast<__m128i>(value)));
|
_mm_movemask_epi8(__llvm_libc::bit_cast<__m128i>(value)));
|
||||||
}
|
}
|
||||||
static uint16_t not_equal_mask(T a, T b) { return mask(a != b); }
|
static uint16_t not_equal_mask(T a, T b) { return mask(a != b); }
|
||||||
static T load(const char *ptr) {
|
static T load(const char *ptr) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return cpp::bit_cast<T>(
|
return __llvm_libc::bit_cast<T>(
|
||||||
_mm_loadu_si128(reinterpret_cast<__m128i_u const *>(ptr)));
|
_mm_loadu_si128(reinterpret_cast<__m128i_u const *>(ptr)));
|
||||||
}
|
}
|
||||||
static void store(char *ptr, T value) {
|
static void store(char *ptr, T value) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return _mm_storeu_si128(reinterpret_cast<__m128i_u *>(ptr),
|
return _mm_storeu_si128(reinterpret_cast<__m128i_u *>(ptr),
|
||||||
cpp::bit_cast<__m128i>(value));
|
__llvm_libc::bit_cast<__m128i>(value));
|
||||||
}
|
}
|
||||||
static T get_splatted_value(const char v) {
|
static T get_splatted_value(const char v) {
|
||||||
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v};
|
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v};
|
||||||
|
@ -95,18 +95,18 @@ struct M256 {
|
||||||
using T = char __attribute__((__vector_size__(SIZE)));
|
using T = char __attribute__((__vector_size__(SIZE)));
|
||||||
static uint32_t mask(T value) {
|
static uint32_t mask(T value) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return _mm256_movemask_epi8(cpp::bit_cast<__m256i>(value));
|
return _mm256_movemask_epi8(__llvm_libc::bit_cast<__m256i>(value));
|
||||||
}
|
}
|
||||||
static uint32_t not_equal_mask(T a, T b) { return mask(a != b); }
|
static uint32_t not_equal_mask(T a, T b) { return mask(a != b); }
|
||||||
static T load(const char *ptr) {
|
static T load(const char *ptr) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return cpp::bit_cast<T>(
|
return __llvm_libc::bit_cast<T>(
|
||||||
_mm256_loadu_si256(reinterpret_cast<__m256i const *>(ptr)));
|
_mm256_loadu_si256(reinterpret_cast<__m256i const *>(ptr)));
|
||||||
}
|
}
|
||||||
static void store(char *ptr, T value) {
|
static void store(char *ptr, T value) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr),
|
return _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr),
|
||||||
cpp::bit_cast<__m256i>(value));
|
__llvm_libc::bit_cast<__m256i>(value));
|
||||||
}
|
}
|
||||||
static T get_splatted_value(const char v) {
|
static T get_splatted_value(const char v) {
|
||||||
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
|
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
|
||||||
|
@ -123,16 +123,16 @@ struct M512 {
|
||||||
using T = char __attribute__((__vector_size__(SIZE)));
|
using T = char __attribute__((__vector_size__(SIZE)));
|
||||||
static uint64_t not_equal_mask(T a, T b) {
|
static uint64_t not_equal_mask(T a, T b) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return _mm512_cmpneq_epi8_mask(cpp::bit_cast<__m512i>(a),
|
return _mm512_cmpneq_epi8_mask(__llvm_libc::bit_cast<__m512i>(a),
|
||||||
cpp::bit_cast<__m512i>(b));
|
__llvm_libc::bit_cast<__m512i>(b));
|
||||||
}
|
}
|
||||||
static T load(const char *ptr) {
|
static T load(const char *ptr) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return cpp::bit_cast<T>(_mm512_loadu_epi8(ptr));
|
return __llvm_libc::bit_cast<T>(_mm512_loadu_epi8(ptr));
|
||||||
}
|
}
|
||||||
static void store(char *ptr, T value) {
|
static void store(char *ptr, T value) {
|
||||||
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
|
||||||
return _mm512_storeu_epi8(ptr, cpp::bit_cast<__m512i>(value));
|
return _mm512_storeu_epi8(ptr, __llvm_libc::bit_cast<__m512i>(value));
|
||||||
}
|
}
|
||||||
static T get_splatted_value(const char v) {
|
static T get_splatted_value(const char v) {
|
||||||
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
|
const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
|
#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
|
||||||
#define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
|
#define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/type_traits.h"
|
#include "src/__support/CPP/type_traits.h"
|
||||||
#include "src/__support/FPUtil/BasicOperations.h"
|
#include "src/__support/FPUtil/BasicOperations.h"
|
||||||
#include "src/__support/FPUtil/FPBits.h"
|
#include "src/__support/FPUtil/FPBits.h"
|
||||||
|
@ -52,54 +52,54 @@ public:
|
||||||
T x = zero;
|
T x = zero;
|
||||||
T result = func(x, T(1));
|
T result = func(x, T(1));
|
||||||
UIntType expected_bits = 1;
|
UIntType expected_bits = 1;
|
||||||
T expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
T expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, T(-1));
|
result = func(x, T(-1));
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
x = neg_zero;
|
x = neg_zero;
|
||||||
result = func(x, 1);
|
result = func(x, 1);
|
||||||
expected_bits = 1;
|
expected_bits = 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, -1);
|
result = func(x, -1);
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
// 'from' is max subnormal value.
|
// 'from' is max subnormal value.
|
||||||
x = __llvm_libc::cpp::bit_cast<T>(max_subnormal);
|
x = __llvm_libc::bit_cast<T>(max_subnormal);
|
||||||
result = func(x, 1);
|
result = func(x, 1);
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(min_normal);
|
expected = __llvm_libc::bit_cast<T>(min_normal);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits = max_subnormal - 1;
|
expected_bits = max_subnormal - 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
x = -x;
|
x = -x;
|
||||||
|
|
||||||
result = func(x, -1);
|
result = func(x, -1);
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits =
|
expected_bits =
|
||||||
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1;
|
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
// 'from' is min subnormal value.
|
// 'from' is min subnormal value.
|
||||||
x = __llvm_libc::cpp::bit_cast<T>(min_subnormal);
|
x = __llvm_libc::bit_cast<T>(min_subnormal);
|
||||||
result = func(x, 1);
|
result = func(x, 1);
|
||||||
expected_bits = min_subnormal + 1;
|
expected_bits = min_subnormal + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
ASSERT_FP_EQ(func(x, 0), 0);
|
ASSERT_FP_EQ(func(x, 0), 0);
|
||||||
|
|
||||||
|
@ -107,35 +107,35 @@ public:
|
||||||
result = func(x, -1);
|
result = func(x, -1);
|
||||||
expected_bits =
|
expected_bits =
|
||||||
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1;
|
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
ASSERT_FP_EQ(func(x, 0), T(-0.0));
|
ASSERT_FP_EQ(func(x, 0), T(-0.0));
|
||||||
|
|
||||||
// 'from' is min normal.
|
// 'from' is min normal.
|
||||||
x = __llvm_libc::cpp::bit_cast<T>(min_normal);
|
x = __llvm_libc::bit_cast<T>(min_normal);
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits = max_subnormal;
|
expected_bits = max_subnormal;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, inf);
|
result = func(x, inf);
|
||||||
expected_bits = min_normal + 1;
|
expected_bits = min_normal + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
x = -x;
|
x = -x;
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
result = func(x, -inf);
|
result = func(x, -inf);
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
|
|
||||||
// 'from' is max normal and 'to' is infinity.
|
// 'from' is max normal and 'to' is infinity.
|
||||||
x = __llvm_libc::cpp::bit_cast<T>(max_normal);
|
x = __llvm_libc::bit_cast<T>(max_normal);
|
||||||
result = func(x, inf);
|
result = func(x, inf);
|
||||||
ASSERT_FP_EQ(result, inf);
|
ASSERT_FP_EQ(result, inf);
|
||||||
|
|
||||||
|
@ -146,14 +146,14 @@ public:
|
||||||
x = inf;
|
x = inf;
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits = max_normal;
|
expected_bits = max_normal;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
ASSERT_FP_EQ(func(x, inf), inf);
|
ASSERT_FP_EQ(func(x, inf), inf);
|
||||||
|
|
||||||
x = neg_inf;
|
x = neg_inf;
|
||||||
result = func(x, 0);
|
result = func(x, 0);
|
||||||
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal;
|
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal;
|
||||||
expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
|
expected = __llvm_libc::bit_cast<T>(expected_bits);
|
||||||
ASSERT_FP_EQ(result, expected);
|
ASSERT_FP_EQ(result, expected);
|
||||||
ASSERT_FP_EQ(func(x, neg_inf), neg_inf);
|
ASSERT_FP_EQ(func(x, neg_inf), neg_inf);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "utils/MPFRWrapper/MPFRUtils.h"
|
#include "utils/MPFRWrapper/MPFRUtils.h"
|
||||||
#include "utils/UnitTest/FPMatcher.h"
|
#include "utils/UnitTest/FPMatcher.h"
|
||||||
#include "utils/UnitTest/Test.h"
|
#include "utils/UnitTest/Test.h"
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
constexpr UIntType COUNT = 1'000'001;
|
constexpr UIntType COUNT = 1'000'001;
|
||||||
constexpr UIntType STEP = HIDDEN_BIT / COUNT;
|
constexpr UIntType STEP = HIDDEN_BIT / COUNT;
|
||||||
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
|
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
|
||||||
T x = cpp::bit_cast<T>(v);
|
T x = __llvm_libc::bit_cast<T>(v);
|
||||||
test_all_rounding_modes(func, x);
|
test_all_rounding_modes(func, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
constexpr UIntType COUNT = 10'000'001;
|
constexpr UIntType COUNT = 10'000'001;
|
||||||
constexpr UIntType STEP = UIntType(-1) / COUNT;
|
constexpr UIntType STEP = UIntType(-1) / COUNT;
|
||||||
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
|
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
|
||||||
T x = cpp::bit_cast<T>(v);
|
T x = __llvm_libc::bit_cast<T>(v);
|
||||||
if (isnan(x) || (x < 0)) {
|
if (isnan(x) || (x < 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "src/__support/CPP/bit.h"
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/arg_list.h"
|
#include "src/__support/arg_list.h"
|
||||||
#include "src/stdio/printf_core/parser.h"
|
#include "src/stdio/printf_core/parser.h"
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ TEST(LlvmLibcPrintfParserTest, EvalThreeArgs) {
|
||||||
expected1.has_conv = true;
|
expected1.has_conv = true;
|
||||||
expected1.raw_len = 2;
|
expected1.raw_len = 2;
|
||||||
expected1.raw_string = str + 2;
|
expected1.raw_string = str + 2;
|
||||||
expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
|
expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
|
||||||
expected1.conv_name = 'f';
|
expected1.conv_name = 'f';
|
||||||
|
|
||||||
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
||||||
|
@ -300,7 +300,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeThreeArgsSequential) {
|
||||||
expected1.has_conv = true;
|
expected1.has_conv = true;
|
||||||
expected1.raw_len = 4;
|
expected1.raw_len = 4;
|
||||||
expected1.raw_string = str + 4;
|
expected1.raw_string = str + 4;
|
||||||
expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
|
expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
|
||||||
expected1.conv_name = 'f';
|
expected1.conv_name = 'f';
|
||||||
|
|
||||||
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
||||||
|
@ -334,7 +334,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeThreeArgsReverse) {
|
||||||
expected1.has_conv = true;
|
expected1.has_conv = true;
|
||||||
expected1.raw_len = 4;
|
expected1.raw_len = 4;
|
||||||
expected1.raw_string = str + 4;
|
expected1.raw_string = str + 4;
|
||||||
expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
|
expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
|
||||||
expected1.conv_name = 'f';
|
expected1.conv_name = 'f';
|
||||||
|
|
||||||
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
ASSERT_FORMAT_EQ(expected1, format_arr[1]);
|
||||||
|
@ -418,7 +418,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeComplexParsing) {
|
||||||
expected5.raw_string = str + 22;
|
expected5.raw_string = str + 22;
|
||||||
expected5.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
|
expected5.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
|
||||||
expected5.min_width = arg4;
|
expected5.min_width = arg4;
|
||||||
expected5.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
|
expected5.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
|
||||||
expected5.conv_name = 'f';
|
expected5.conv_name = 'f';
|
||||||
|
|
||||||
EXPECT_FORMAT_EQ(expected5, format_arr[5]);
|
EXPECT_FORMAT_EQ(expected5, format_arr[5]);
|
||||||
|
@ -434,7 +434,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeComplexParsing) {
|
||||||
expected7.raw_string = str + 31;
|
expected7.raw_string = str + 31;
|
||||||
expected7.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
|
expected7.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
|
||||||
expected7.precision = arg4;
|
expected7.precision = arg4;
|
||||||
expected7.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
|
expected7.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
|
||||||
expected7.conv_name = 'f';
|
expected7.conv_name = 'f';
|
||||||
|
|
||||||
EXPECT_FORMAT_EQ(expected7, format_arr[7]);
|
EXPECT_FORMAT_EQ(expected7, format_arr[7]);
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "src/__support/CPP/ArrayRef.h"
|
#include "src/__support/CPP/ArrayRef.h"
|
||||||
|
#include "src/__support/CPP/Bit.h"
|
||||||
#include "src/__support/CPP/array.h"
|
#include "src/__support/CPP/array.h"
|
||||||
#include "src/__support/CPP/bit.h"
|
|
||||||
#include "src/__support/architectures.h"
|
#include "src/__support/architectures.h"
|
||||||
#include "src/string/memory_utils/backends.h"
|
#include "src/string/memory_utils/backends.h"
|
||||||
#include "utils/UnitTest/Test.h"
|
#include "utils/UnitTest/Test.h"
|
||||||
|
@ -49,17 +49,15 @@ template <typename Backend, size_t Size> struct Conf {
|
||||||
static constexpr size_t SIZE = Size;
|
static constexpr size_t SIZE = Size;
|
||||||
|
|
||||||
static BufferT splat(ubyte value) {
|
static BufferT splat(ubyte value) {
|
||||||
return cpp::bit_cast<BufferT>(Backend::template splat<T>(value));
|
return bit_cast<BufferT>(Backend::template splat<T>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t notEquals(const BufferT &v1, const BufferT &v2) {
|
static uint64_t notEquals(const BufferT &v1, const BufferT &v2) {
|
||||||
return Backend::template notEquals<T>(cpp::bit_cast<T>(v1),
|
return Backend::template notEquals<T>(bit_cast<T>(v1), bit_cast<T>(v2));
|
||||||
cpp::bit_cast<T>(v2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t threeWayCmp(const BufferT &v1, const BufferT &v2) {
|
static int32_t threeWayCmp(const BufferT &v1, const BufferT &v2) {
|
||||||
return Backend::template threeWayCmp<T>(cpp::bit_cast<T>(v1),
|
return Backend::template threeWayCmp<T>(bit_cast<T>(v1), bit_cast<T>(v2));
|
||||||
cpp::bit_cast<T>(v2));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,10 +85,9 @@ using FunctionTypes = testing::TypeList< //
|
||||||
|
|
||||||
TYPED_TEST(LlvmLibcMemoryBackend, splat, FunctionTypes) {
|
TYPED_TEST(LlvmLibcMemoryBackend, splat, FunctionTypes) {
|
||||||
for (auto value : cpp::array<uint8_t, 3>{0u, 1u, 255u}) {
|
for (auto value : cpp::array<uint8_t, 3>{0u, 1u, 255u}) {
|
||||||
alignas(64) const auto stored =
|
alignas(64) const auto stored = ParamType::splat(bit_cast<ubyte>(value));
|
||||||
ParamType::splat(cpp::bit_cast<ubyte>(value));
|
|
||||||
for (size_t i = 0; i < ParamType::SIZE; ++i)
|
for (size_t i = 0; i < ParamType::SIZE; ++i)
|
||||||
EXPECT_EQ(cpp::bit_cast<uint8_t>(stored[i]), value);
|
EXPECT_EQ(bit_cast<uint8_t>(stored[i]), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,14 +129,14 @@ struct LoadStoreConf {
|
||||||
static constexpr size_t SIZE = Size;
|
static constexpr size_t SIZE = Size;
|
||||||
|
|
||||||
static BufferT load(const BufferT &ref) {
|
static BufferT load(const BufferT &ref) {
|
||||||
const auto *ptr = cpp::bit_cast<const T *>(ref.data());
|
const auto *ptr = bit_cast<const T *>(ref.data());
|
||||||
const T value = Backend::template load<T, TS, AS>(ptr);
|
const T value = Backend::template load<T, TS, AS>(ptr);
|
||||||
return cpp::bit_cast<BufferT>(value);
|
return bit_cast<BufferT>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void store(BufferT &ref, const BufferT value) {
|
static void store(BufferT &ref, const BufferT value) {
|
||||||
auto *ptr = cpp::bit_cast<T *>(ref.data());
|
auto *ptr = bit_cast<T *>(ref.data());
|
||||||
Backend::template store<T, TS, AS>(ptr, cpp::bit_cast<T>(value));
|
Backend::template store<T, TS, AS>(ptr, bit_cast<T>(value));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ cc_library(
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "__support_cpp_bit",
|
name = "__support_cpp_bit",
|
||||||
hdrs = ["src/__support/CPP/bit.h"],
|
hdrs = ["src/__support/CPP/Bit.h"],
|
||||||
deps = [":libc_root"],
|
deps = [":libc_root"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue