[libc][NFC] Integrate FloatProperties
into FPBits
(#76506)
`FloatProperties` is always included when `FPBits` is. This will help further refactoring.
This commit is contained in:
parent
d79ccee8dc
commit
c23991478a
@ -26,7 +26,7 @@ add_libc_fuzzer(
|
||||
libc.src.stdlib.strtof
|
||||
libc.src.stdlib.strtod
|
||||
libc.src.stdlib.strtold
|
||||
libc.src.__support.FPUtil.float_properties
|
||||
libc.src.__support.FPUtil.fp_bits
|
||||
)
|
||||
|
||||
add_libc_fuzzer(
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "src/stdlib/strtof.h"
|
||||
#include "src/stdlib/strtold.h"
|
||||
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
|
@ -23,25 +23,18 @@ add_header_library(
|
||||
libc.src.errno.errno
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
float_properties
|
||||
HDRS
|
||||
FloatProperties.h
|
||||
DEPENDS
|
||||
libc.src.__support.macros.properties.float
|
||||
libc.src.__support.uint128
|
||||
libc.src.__support.math_extras
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
fp_bits
|
||||
HDRS
|
||||
FPBits.h
|
||||
DEPENDS
|
||||
.float_properties
|
||||
libc.src.__support.common
|
||||
libc.src.__support.CPP.bit
|
||||
libc.src.__support.CPP.type_traits
|
||||
libc.src.__support.macros.attributes
|
||||
libc.src.__support.macros.properties.float
|
||||
libc.src.__support.math_extras
|
||||
libc.src.__support.uint128
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
@ -49,7 +42,6 @@ add_header_library(
|
||||
HDRS
|
||||
fpbits_str.h
|
||||
DEPENDS
|
||||
.float_properties
|
||||
.fp_bits
|
||||
libc.src.__support.CPP.bit
|
||||
libc.src.__support.CPP.type_traits
|
||||
@ -230,7 +222,6 @@ add_header_library(
|
||||
HDRS
|
||||
dyadic_float.h
|
||||
DEPENDS
|
||||
.float_properties
|
||||
.fp_bits
|
||||
.multiply_add
|
||||
libc.src.__support.common
|
||||
|
@ -13,14 +13,199 @@
|
||||
#include "src/__support/CPP/type_traits.h"
|
||||
#include "src/__support/UInt128.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/attributes.h" // LIBC_INLINE
|
||||
#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
|
||||
#include "src/__support/macros/properties/float.h" // LIBC_COMPILER_HAS_FLOAT128
|
||||
#include "src/__support/math_extras.h" // mask_trailing_ones
|
||||
|
||||
#include "FloatProperties.h"
|
||||
#include <stdint.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
namespace fputil {
|
||||
|
||||
// The supported floating point types.
|
||||
enum class FPType {
|
||||
IEEE754_Binary16,
|
||||
IEEE754_Binary32,
|
||||
IEEE754_Binary64,
|
||||
IEEE754_Binary128,
|
||||
X86_Binary80,
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// The type of encoding for supported floating point types.
|
||||
enum class FPEncoding {
|
||||
IEEE754,
|
||||
X86_ExtendedPrecision,
|
||||
};
|
||||
|
||||
template <FPType> struct FPBaseProperties {};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary16> {
|
||||
using StorageType = uint16_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 16;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 10;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 5;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary32> {
|
||||
using StorageType = uint32_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 32;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 23;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 8;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary64> {
|
||||
using StorageType = uint64_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 64;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 52;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 11;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary128> {
|
||||
using StorageType = UInt128;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 128;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::X86_Binary80> {
|
||||
using StorageType = UInt128;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 80;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING =
|
||||
FPEncoding::X86_ExtendedPrecision;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <FPType fp_type>
|
||||
struct FPProperties : public internal::FPBaseProperties<fp_type> {
|
||||
private:
|
||||
using UP = internal::FPBaseProperties<fp_type>;
|
||||
|
||||
public:
|
||||
// The number of bits to represent sign. For documentation purpose, always 1.
|
||||
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
|
||||
using UP::EXP_LEN; // The number of bits for the *exponent* part
|
||||
using UP::SIG_LEN; // The number of bits for the *significand* part
|
||||
using UP::TOTAL_LEN; // For convenience, the sum of `SIG_LEN`, `EXP_LEN`,
|
||||
// and `SIGN_LEN`.
|
||||
static_assert(SIGN_LEN + EXP_LEN + SIG_LEN == TOTAL_LEN);
|
||||
|
||||
// An unsigned integer that is wide enough to contain all of the floating
|
||||
// point bits.
|
||||
using StorageType = typename UP::StorageType;
|
||||
|
||||
// The number of bits in StorageType.
|
||||
LIBC_INLINE_VAR static constexpr int STORAGE_LEN =
|
||||
sizeof(StorageType) * CHAR_BIT;
|
||||
static_assert(STORAGE_LEN >= TOTAL_LEN);
|
||||
|
||||
// The exponent bias. Always positive.
|
||||
LIBC_INLINE_VAR static constexpr int32_t EXP_BIAS =
|
||||
(1U << (EXP_LEN - 1U)) - 1U;
|
||||
static_assert(EXP_BIAS > 0);
|
||||
|
||||
protected:
|
||||
// The shift amount to get the *significand* part to the least significant
|
||||
// bit. Always `0` but kept for consistency.
|
||||
LIBC_INLINE_VAR static constexpr int SIG_MASK_SHIFT = 0;
|
||||
// The shift amount to get the *exponent* part to the least significant bit.
|
||||
LIBC_INLINE_VAR static constexpr int EXP_MASK_SHIFT = SIG_LEN;
|
||||
// The shift amount to get the *sign* part to the least significant bit.
|
||||
LIBC_INLINE_VAR static constexpr int SIGN_MASK_SHIFT = SIG_LEN + EXP_LEN;
|
||||
|
||||
// The bit pattern that keeps only the *significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIG_MASK =
|
||||
mask_trailing_ones<StorageType, SIG_LEN>() << SIG_MASK_SHIFT;
|
||||
|
||||
public:
|
||||
// The bit pattern that keeps only the *exponent* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType EXP_MASK =
|
||||
mask_trailing_ones<StorageType, EXP_LEN>() << EXP_MASK_SHIFT;
|
||||
// The bit pattern that keeps only the *sign* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIGN_MASK =
|
||||
mask_trailing_ones<StorageType, SIGN_LEN>() << SIGN_MASK_SHIFT;
|
||||
// The bit pattern that keeps only the *exponent + significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType EXP_SIG_MASK =
|
||||
mask_trailing_ones<StorageType, EXP_LEN + SIG_LEN>();
|
||||
// The bit pattern that keeps only the *sign + exponent + significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType FP_MASK =
|
||||
mask_trailing_ones<StorageType, TOTAL_LEN>();
|
||||
|
||||
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
|
||||
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
|
||||
|
||||
private:
|
||||
LIBC_INLINE static constexpr StorageType bit_at(int position) {
|
||||
return StorageType(1) << position;
|
||||
}
|
||||
|
||||
public:
|
||||
// The number of bits after the decimal dot when the number is in normal form.
|
||||
LIBC_INLINE_VAR static constexpr int FRACTION_LEN =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision ? SIG_LEN - 1
|
||||
: SIG_LEN;
|
||||
LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_PRECISION =
|
||||
FRACTION_LEN + 1;
|
||||
LIBC_INLINE_VAR static constexpr StorageType FRACTION_MASK =
|
||||
mask_trailing_ones<StorageType, FRACTION_LEN>();
|
||||
|
||||
protected:
|
||||
// If a number x is a NAN, then it is a quiet NAN if:
|
||||
// QUIET_NAN_MASK & bits(x) != 0
|
||||
LIBC_INLINE_VAR static constexpr StorageType QUIET_NAN_MASK =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
|
||||
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
|
||||
: bit_at(SIG_LEN - 1); // 0b1000...
|
||||
|
||||
// If a number x is a NAN, then it is a signalling NAN if:
|
||||
// SIGNALING_NAN_MASK & bits(x) != 0
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIGNALING_NAN_MASK =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
|
||||
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
|
||||
: bit_at(SIG_LEN - 2); // 0b0100...
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename FP> LIBC_INLINE static constexpr FPType get_fp_type() {
|
||||
if constexpr (cpp::is_same_v<FP, float> && __FLT_MANT_DIG__ == 24)
|
||||
return FPType::IEEE754_Binary32;
|
||||
else if constexpr (cpp::is_same_v<FP, double> && __DBL_MANT_DIG__ == 53)
|
||||
return FPType::IEEE754_Binary64;
|
||||
else if constexpr (cpp::is_same_v<FP, long double>) {
|
||||
if constexpr (__LDBL_MANT_DIG__ == 53)
|
||||
return FPType::IEEE754_Binary64;
|
||||
else if constexpr (__LDBL_MANT_DIG__ == 64)
|
||||
return FPType::X86_Binary80;
|
||||
else if constexpr (__LDBL_MANT_DIG__ == 113)
|
||||
return FPType::IEEE754_Binary128;
|
||||
}
|
||||
#if defined(LIBC_COMPILER_HAS_C23_FLOAT16)
|
||||
else if constexpr (cpp::is_same_v<FP, _Float16>)
|
||||
return FPType::IEEE754_Binary16;
|
||||
#endif
|
||||
#if defined(LIBC_COMPILER_HAS_C23_FLOAT128)
|
||||
else if constexpr (cpp::is_same_v<FP, _Float128>)
|
||||
return FPType::IEEE754_Binary128;
|
||||
#endif
|
||||
#if defined(LIBC_COMPILER_HAS_FLOAT128_EXTENSION)
|
||||
else if constexpr (cpp::is_same_v<FP, __float128>)
|
||||
return FPType::IEEE754_Binary128;
|
||||
#endif
|
||||
else
|
||||
static_assert(cpp::always_false<FP>, "Unsupported type");
|
||||
}
|
||||
|
||||
template <typename FP>
|
||||
struct FloatProperties : public FPProperties<get_fp_type<FP>()> {};
|
||||
|
||||
namespace internal {
|
||||
|
||||
// This is a temporary class to unify common methods and properties between
|
||||
|
@ -1,211 +0,0 @@
|
||||
//===-- Properties of floating point numbers --------------------*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOATPROPERTIES_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOATPROPERTIES_H
|
||||
|
||||
#include "src/__support/UInt128.h"
|
||||
#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
|
||||
#include "src/__support/macros/properties/float.h" // LIBC_COMPILER_HAS_FLOAT128
|
||||
#include "src/__support/math_extras.h" // mask_trailing_ones
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
namespace fputil {
|
||||
|
||||
// The supported floating point types.
|
||||
enum class FPType {
|
||||
IEEE754_Binary16,
|
||||
IEEE754_Binary32,
|
||||
IEEE754_Binary64,
|
||||
IEEE754_Binary128,
|
||||
X86_Binary80,
|
||||
};
|
||||
|
||||
// For now 'FPEncoding', 'FPBaseProperties' and 'FPCommonProperties' are
|
||||
// implementation details.
|
||||
namespace internal {
|
||||
|
||||
// The type of encoding for supported floating point types.
|
||||
enum class FPEncoding {
|
||||
IEEE754,
|
||||
X86_ExtendedPrecision,
|
||||
};
|
||||
|
||||
template <FPType> struct FPBaseProperties {};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary16> {
|
||||
using StorageType = uint16_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 16;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 10;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 5;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary32> {
|
||||
using StorageType = uint32_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 32;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 23;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 8;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary64> {
|
||||
using StorageType = uint64_t;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 64;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 52;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 11;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::IEEE754_Binary128> {
|
||||
using StorageType = UInt128;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 128;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING = FPEncoding::IEEE754;
|
||||
};
|
||||
|
||||
template <> struct FPBaseProperties<FPType::X86_Binary80> {
|
||||
using StorageType = UInt128;
|
||||
LIBC_INLINE_VAR static constexpr int TOTAL_LEN = 80;
|
||||
LIBC_INLINE_VAR static constexpr int SIG_LEN = 64;
|
||||
LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
|
||||
LIBC_INLINE_VAR static constexpr auto ENCODING =
|
||||
FPEncoding::X86_ExtendedPrecision;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <FPType fp_type>
|
||||
struct FPProperties : public internal::FPBaseProperties<fp_type> {
|
||||
private:
|
||||
using UP = internal::FPBaseProperties<fp_type>;
|
||||
|
||||
public:
|
||||
// The number of bits to represent sign. For documentation purpose, always 1.
|
||||
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
|
||||
using UP::EXP_LEN; // The number of bits for the *exponent* part
|
||||
using UP::SIG_LEN; // The number of bits for the *significand* part
|
||||
using UP::TOTAL_LEN; // For convenience, the sum of `SIG_LEN`, `EXP_LEN`,
|
||||
// and `SIGN_LEN`.
|
||||
static_assert(SIGN_LEN + EXP_LEN + SIG_LEN == TOTAL_LEN);
|
||||
|
||||
// An unsigned integer that is wide enough to contain all of the floating
|
||||
// point bits.
|
||||
using StorageType = typename UP::StorageType;
|
||||
|
||||
// The number of bits in StorageType.
|
||||
LIBC_INLINE_VAR static constexpr int STORAGE_LEN =
|
||||
sizeof(StorageType) * CHAR_BIT;
|
||||
static_assert(STORAGE_LEN >= TOTAL_LEN);
|
||||
|
||||
// The exponent bias. Always positive.
|
||||
LIBC_INLINE_VAR static constexpr int32_t EXP_BIAS =
|
||||
(1U << (EXP_LEN - 1U)) - 1U;
|
||||
static_assert(EXP_BIAS > 0);
|
||||
|
||||
protected:
|
||||
// The shift amount to get the *significand* part to the least significant
|
||||
// bit. Always `0` but kept for consistency.
|
||||
LIBC_INLINE_VAR static constexpr int SIG_MASK_SHIFT = 0;
|
||||
// The shift amount to get the *exponent* part to the least significant bit.
|
||||
LIBC_INLINE_VAR static constexpr int EXP_MASK_SHIFT = SIG_LEN;
|
||||
// The shift amount to get the *sign* part to the least significant bit.
|
||||
LIBC_INLINE_VAR static constexpr int SIGN_MASK_SHIFT = SIG_LEN + EXP_LEN;
|
||||
|
||||
// The bit pattern that keeps only the *significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIG_MASK =
|
||||
mask_trailing_ones<StorageType, SIG_LEN>() << SIG_MASK_SHIFT;
|
||||
|
||||
public:
|
||||
// The bit pattern that keeps only the *exponent* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType EXP_MASK =
|
||||
mask_trailing_ones<StorageType, EXP_LEN>() << EXP_MASK_SHIFT;
|
||||
// The bit pattern that keeps only the *sign* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIGN_MASK =
|
||||
mask_trailing_ones<StorageType, SIGN_LEN>() << SIGN_MASK_SHIFT;
|
||||
// The bit pattern that keeps only the *exponent + significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType EXP_SIG_MASK =
|
||||
mask_trailing_ones<StorageType, EXP_LEN + SIG_LEN>();
|
||||
// The bit pattern that keeps only the *sign + exponent + significand* part.
|
||||
LIBC_INLINE_VAR static constexpr StorageType FP_MASK =
|
||||
mask_trailing_ones<StorageType, TOTAL_LEN>();
|
||||
|
||||
static_assert((SIG_MASK & EXP_MASK & SIGN_MASK) == 0, "masks disjoint");
|
||||
static_assert((SIG_MASK | EXP_MASK | SIGN_MASK) == FP_MASK, "masks cover");
|
||||
|
||||
private:
|
||||
LIBC_INLINE static constexpr StorageType bit_at(int position) {
|
||||
return StorageType(1) << position;
|
||||
}
|
||||
|
||||
public:
|
||||
// The number of bits after the decimal dot when the number is in normal form.
|
||||
LIBC_INLINE_VAR static constexpr int FRACTION_LEN =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision ? SIG_LEN - 1
|
||||
: SIG_LEN;
|
||||
LIBC_INLINE_VAR static constexpr uint32_t MANTISSA_PRECISION =
|
||||
FRACTION_LEN + 1;
|
||||
LIBC_INLINE_VAR static constexpr StorageType FRACTION_MASK =
|
||||
mask_trailing_ones<StorageType, FRACTION_LEN>();
|
||||
|
||||
protected:
|
||||
// If a number x is a NAN, then it is a quiet NAN if:
|
||||
// QUIET_NAN_MASK & bits(x) != 0
|
||||
LIBC_INLINE_VAR static constexpr StorageType QUIET_NAN_MASK =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
|
||||
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 2) // 0b1100...
|
||||
: bit_at(SIG_LEN - 1); // 0b1000...
|
||||
|
||||
// If a number x is a NAN, then it is a signalling NAN if:
|
||||
// SIGNALING_NAN_MASK & bits(x) != 0
|
||||
LIBC_INLINE_VAR static constexpr StorageType SIGNALING_NAN_MASK =
|
||||
UP::ENCODING == internal::FPEncoding::X86_ExtendedPrecision
|
||||
? bit_at(SIG_LEN - 1) | bit_at(SIG_LEN - 3) // 0b1010...
|
||||
: bit_at(SIG_LEN - 2); // 0b0100...
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename FP> LIBC_INLINE static constexpr FPType get_fp_type() {
|
||||
if constexpr (cpp::is_same_v<FP, float> && __FLT_MANT_DIG__ == 24)
|
||||
return FPType::IEEE754_Binary32;
|
||||
else if constexpr (cpp::is_same_v<FP, double> && __DBL_MANT_DIG__ == 53)
|
||||
return FPType::IEEE754_Binary64;
|
||||
else if constexpr (cpp::is_same_v<FP, long double>) {
|
||||
if constexpr (__LDBL_MANT_DIG__ == 53)
|
||||
return FPType::IEEE754_Binary64;
|
||||
else if constexpr (__LDBL_MANT_DIG__ == 64)
|
||||
return FPType::X86_Binary80;
|
||||
else if constexpr (__LDBL_MANT_DIG__ == 113)
|
||||
return FPType::IEEE754_Binary128;
|
||||
}
|
||||
#if defined(LIBC_COMPILER_HAS_C23_FLOAT16)
|
||||
else if constexpr (cpp::is_same_v<FP, _Float16>)
|
||||
return FPType::IEEE754_Binary16;
|
||||
#endif
|
||||
#if defined(LIBC_COMPILER_HAS_C23_FLOAT128)
|
||||
else if constexpr (cpp::is_same_v<FP, _Float128>)
|
||||
return FPType::IEEE754_Binary128;
|
||||
#endif
|
||||
#if defined(LIBC_COMPILER_HAS_FLOAT128_EXTENSION)
|
||||
else if constexpr (cpp::is_same_v<FP, __float128>)
|
||||
return FPType::IEEE754_Binary128;
|
||||
#endif
|
||||
else
|
||||
static_assert(cpp::always_false<FP>, "Unsupported type");
|
||||
}
|
||||
|
||||
template <typename FP>
|
||||
struct FloatProperties : public FPProperties<get_fp_type<FP>()> {};
|
||||
|
||||
} // namespace fputil
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOATPROPERTIES_H
|
@ -10,7 +10,6 @@
|
||||
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_MANIPULATIONFUNCTIONS_H
|
||||
|
||||
#include "FPBits.h"
|
||||
#include "FloatProperties.h"
|
||||
#include "NearestIntegerOperations.h"
|
||||
#include "NormalFloat.h"
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_DYADIC_FLOAT_H
|
||||
|
||||
#include "FPBits.h"
|
||||
#include "FloatProperties.h"
|
||||
#include "multiply_add.h"
|
||||
#include "src/__support/CPP/type_traits.h"
|
||||
#include "src/__support/UInt.h"
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "src/__support/CPP/string.h"
|
||||
#include "src/__support/CPP/type_traits.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/integer_to_string.h"
|
||||
#include "src/__support/macros/attributes.h"
|
||||
|
||||
|
@ -23,7 +23,6 @@ add_header_library(
|
||||
libc.src.__support.CPP.bit
|
||||
libc.src.__support.CPP.type_traits
|
||||
libc.src.__support.FPUtil.fenv_impl
|
||||
libc.src.__support.FPUtil.float_properties
|
||||
libc.src.__support.FPUtil.fp_bits
|
||||
libc.src.__support.FPUtil.rounding_mode
|
||||
libc.src.__support.macros.optimization
|
||||
@ -39,7 +38,6 @@ add_header_library(
|
||||
libc.src.__support.CPP.bit
|
||||
libc.src.__support.CPP.type_traits
|
||||
libc.src.__support.FPUtil.fenv_impl
|
||||
libc.src.__support.FPUtil.float_properties
|
||||
libc.src.__support.FPUtil.fp_bits
|
||||
libc.src.__support.FPUtil.rounding_mode
|
||||
libc.src.__support.macros.optimization
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "src/__support/CPP/type_traits.h"
|
||||
#include "src/__support/FPUtil/FEnvImpl.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/FPUtil/rounding_mode.h"
|
||||
#include "src/__support/UInt128.h"
|
||||
#include "src/__support/macros/attributes.h" // LIBC_INLINE
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "src/__support/CPP/string_view.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/FPUtil/rounding_mode.h"
|
||||
#include "src/__support/float_to_string.h"
|
||||
#include "src/__support/integer_to_string.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
#include "src/__support/UInt128.h"
|
||||
#include "src/__support/str_to_float.h"
|
||||
#include "src/errno/libc_errno.h"
|
||||
|
@ -12,7 +12,6 @@ if(LIBC_TESTS_CAN_USE_MPFR)
|
||||
libc.src.__support.CPP.string_view
|
||||
libc.src.__support.CPP.type_traits
|
||||
libc.src.__support.FPUtil.fp_bits
|
||||
libc.src.__support.FPUtil.float_properties
|
||||
libc.src.__support.FPUtil.fpbits_str
|
||||
LibcTest.unit
|
||||
)
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "src/__support/CPP/string.h"
|
||||
#include "src/__support/CPP/string_view.h"
|
||||
#include "src/__support/FPUtil/FPBits.h"
|
||||
#include "src/__support/FPUtil/FloatProperties.h"
|
||||
#include "src/__support/FPUtil/fpbits_str.h"
|
||||
#include "test/UnitTest/FPMatcher.h"
|
||||
|
||||
|
@ -658,17 +658,6 @@ libc_support_library(
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_fputil_float_properties",
|
||||
hdrs = ["src/__support/FPUtil/FloatProperties.h"],
|
||||
deps = [
|
||||
":__support_macros_attributes",
|
||||
":__support_macros_properties_float",
|
||||
":__support_math_extras",
|
||||
":__support_uint128",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_fputil_fp_bits",
|
||||
hdrs = ["src/__support/FPUtil/FPBits.h"],
|
||||
@ -677,8 +666,9 @@ libc_support_library(
|
||||
":__support_common",
|
||||
":__support_cpp_bit",
|
||||
":__support_cpp_type_traits",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_macros_attributes",
|
||||
":__support_macros_properties_float",
|
||||
":__support_math_extras",
|
||||
":__support_uint128",
|
||||
],
|
||||
)
|
||||
@ -690,7 +680,6 @@ libc_support_library(
|
||||
":__support_common",
|
||||
":__support_cpp_string",
|
||||
":__support_cpp_type_traits",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_fputil_fp_bits",
|
||||
":__support_integer_to_string",
|
||||
":__support_uint128",
|
||||
@ -801,7 +790,6 @@ libc_support_library(
|
||||
":__support_cpp_bit",
|
||||
":__support_cpp_type_traits",
|
||||
":__support_fputil_fenv_impl",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_fputil_fp_bits",
|
||||
":__support_fputil_rounding_mode",
|
||||
":__support_macros_attributes",
|
||||
@ -880,7 +868,6 @@ libc_support_library(
|
||||
hdrs = ["src/__support/FPUtil/dyadic_float.h"],
|
||||
deps = [
|
||||
":__support_common",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_fputil_fp_bits",
|
||||
":__support_fputil_multiply_add",
|
||||
":__support_macros_optimization",
|
||||
@ -2782,7 +2769,6 @@ libc_support_library(
|
||||
":__support_cpp_string_view",
|
||||
":__support_float_to_string",
|
||||
":__support_fputil_fenv_impl",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_fputil_fp_bits",
|
||||
":__support_fputil_rounding_mode",
|
||||
":__support_integer_to_string",
|
||||
|
@ -139,7 +139,6 @@ def libc_math_function(
|
||||
":__support_fputil_division_and_remainder_operations",
|
||||
":__support_fputil_fenv_impl",
|
||||
":__support_fputil_fp_bits",
|
||||
":__support_fputil_float_properties",
|
||||
":__support_fputil_hypot",
|
||||
":__support_fputil_manipulation_functions",
|
||||
":__support_fputil_nearest_integer_operations",
|
||||
|
@ -49,7 +49,7 @@ libc_test(
|
||||
"str_to_long_double_test.cpp",
|
||||
],
|
||||
deps = [
|
||||
"//libc:__support_fputil_float_properties",
|
||||
"//libc:__support_fputil_fp_bits",
|
||||
"//libc:__support_str_to_float",
|
||||
"//libc:__support_uint128",
|
||||
],
|
||||
|
@ -27,7 +27,6 @@ def math_test(name, hdrs = [], deps = [], **kwargs):
|
||||
deps = [
|
||||
"//libc:__support_fputil_basic_operations",
|
||||
"//libc:__support_fputil_fenv_impl",
|
||||
"//libc:__support_fputil_float_properties",
|
||||
"//libc:__support_fputil_fp_bits",
|
||||
"//libc:__support_fputil_manipulation_functions",
|
||||
"//libc:__support_fputil_nearest_integer_operations",
|
||||
|
@ -44,7 +44,6 @@ libc_support_library(
|
||||
"//libc:__support_cpp_string",
|
||||
"//libc:__support_cpp_string_view",
|
||||
"//libc:__support_cpp_type_traits",
|
||||
"//libc:__support_fputil_float_properties",
|
||||
"//libc:__support_fputil_fp_bits",
|
||||
"//libc:__support_fputil_fpbits_str",
|
||||
"//libc/test/UnitTest:fp_test_helpers",
|
||||
|
Loading…
x
Reference in New Issue
Block a user