[libc] Add proxy header for float.h. (#93504)
This is the continuation of https://github.com/llvm/llvm-project/pull/88674. Fixes #88433, #90496. --------- Co-authored-by: aniplcc <aniplccode@gmail.com>
This commit is contained in:
parent
c179d50fd3
commit
4486fcba75
@ -87,4 +87,14 @@ add_proxy_header_library(
|
||||
libc.include.llvm-libc-macros.time_macros
|
||||
)
|
||||
|
||||
add_proxy_header_library(
|
||||
float_macros
|
||||
HDRS
|
||||
float_macros.h
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-macros.float_macros
|
||||
FULL_BUILD_DEPENDS
|
||||
libc.include.float
|
||||
)
|
||||
|
||||
add_subdirectory(types)
|
||||
|
||||
22
libc/hdr/float_macros.h
Normal file
22
libc/hdr/float_macros.h
Normal file
@ -0,0 +1,22 @@
|
||||
//===-- Definition of macros from math.h ----------------------------------===//
|
||||
//
|
||||
// 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_HDR_FLOAT_MACROS_H
|
||||
#define LLVM_LIBC_HDR_FLOAT_MACROS_H
|
||||
|
||||
#ifdef LIBC_FULL_BUILD
|
||||
|
||||
#include "include/llvm-libc-macros/float-macros.h"
|
||||
|
||||
#else // Overlay mode
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#endif // LLVM_LIBC_FULL_BUILD
|
||||
|
||||
#endif // LLVM_LIBC_HDR_FLOAT_MACROS_H
|
||||
@ -9,21 +9,6 @@
|
||||
#ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H
|
||||
#define LLVM_LIBC_MACROS_FLOAT_MACROS_H
|
||||
|
||||
// Suppress `#include_next is a language extension` warnings.
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wgnu-include-next"
|
||||
#pragma clang diagnostic ignored "-Winclude-next-absolute-path"
|
||||
#else // gcc
|
||||
#pragma GCC system_header
|
||||
#endif //__clang__
|
||||
|
||||
#include_next <float.h>
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif //__clang__
|
||||
|
||||
#ifndef FLT_RADIX
|
||||
#define FLT_RADIX __FLT_RADIX__
|
||||
#endif // FLT_RADIX
|
||||
@ -32,9 +17,13 @@
|
||||
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
|
||||
#endif // FLT_EVAL_METHOD
|
||||
|
||||
#ifndef DECIMAL_DIG
|
||||
#define DECIMAL_DIG __DECIMAL_DIG__
|
||||
#endif // DECIMAL_DIG
|
||||
#ifndef FLT_ROUNDS
|
||||
#if __has_builtin(__builtin_flt_rounds)
|
||||
#define FLT_ROUNDS __builtin_flt_rounds()
|
||||
#else
|
||||
#define FLT_ROUNDS 1
|
||||
#endif
|
||||
#endif // FLT_ROUNDS
|
||||
|
||||
#ifndef FLT_DECIMAL_DIG
|
||||
#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
|
||||
@ -48,6 +37,10 @@
|
||||
#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
|
||||
#endif // LDBL_DECIMAL_DIG
|
||||
|
||||
#ifndef DECIMAL_DIG
|
||||
#define DECIMAL_DIG __DECIMAL_DIG__
|
||||
#endif // DECIMAL_DIG
|
||||
|
||||
#ifndef FLT_DIG
|
||||
#define FLT_DIG __FLT_DIG__
|
||||
#endif // FLT_DIG
|
||||
@ -97,15 +90,15 @@
|
||||
#endif // LDBL_MAX
|
||||
|
||||
#ifndef FLT_TRUE_MIN
|
||||
#define FLT_TRUE_MIN __FLT_TRUE_MIN__
|
||||
#define FLT_TRUE_MIN __FLT_DENORM_MIN__
|
||||
#endif // FLT_TRUE_MIN
|
||||
|
||||
#ifndef DBL_TRUE_MIN
|
||||
#define DBL_TRUE_MIN __DBL_TRUE_MIN__
|
||||
#define DBL_TRUE_MIN __DBL_DENORM_MIN__
|
||||
#endif // DBL_TRUE_MIN
|
||||
|
||||
#ifndef LDBL_TRUE_MIN
|
||||
#define LDBL_TRUE_MIN __LDBL_TRUE_MIN__
|
||||
#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
|
||||
#endif // LDBL_TRUE_MIN
|
||||
|
||||
#ifndef FLT_EPSILON
|
||||
|
||||
@ -33,6 +33,6 @@ add_header_library(
|
||||
.compiler
|
||||
.cpu_features
|
||||
.os
|
||||
libc.include.llvm-libc-macros.float_macros
|
||||
libc.hdr.float_macros
|
||||
libc.include.llvm-libc-types.float128
|
||||
)
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
|
||||
|
||||
#include "include/llvm-libc-macros/float-macros.h" // LDBL_MANT_DIG
|
||||
#include "hdr/float_macros.h" // LDBL_MANT_DIG
|
||||
#include "include/llvm-libc-types/float128.h" // float128
|
||||
#include "src/__support/macros/properties/architectures.h"
|
||||
#include "src/__support/macros/properties/compiler.h"
|
||||
|
||||
@ -2933,6 +2933,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../scalbn.h
|
||||
DEPENDS
|
||||
libc.hdr.float_macros
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O3
|
||||
@ -2945,6 +2946,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../scalbnf.h
|
||||
DEPENDS
|
||||
libc.hdr.float_macros
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O3
|
||||
@ -2957,6 +2959,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../scalbnl.h
|
||||
DEPENDS
|
||||
libc.hdr.float_macros
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
-O3
|
||||
@ -2969,6 +2972,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../scalbnf128.h
|
||||
DEPENDS
|
||||
libc.hdr.float_macros
|
||||
libc.src.__support.macros.properties.types
|
||||
libc.src.__support.FPUtil.manipulation_functions
|
||||
COMPILE_OPTIONS
|
||||
|
||||
@ -7,19 +7,18 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/scalbn.h"
|
||||
#include "hdr/float_macros.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#if FLT_RADIX != 2
|
||||
#error "FLT_RADIX != 2 is not supported."
|
||||
#endif
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(double, scalbn, (double x, int n)) {
|
||||
#if !defined(__FLT_RADIX__)
|
||||
#error __FLT_RADIX__ undefined.
|
||||
#elif __FLT_RADIX__ != 2
|
||||
#error __FLT_RADIX__!=2, unimplemented.
|
||||
#else
|
||||
return fputil::ldexp(x, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@ -7,19 +7,18 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/scalbnf.h"
|
||||
#include "hdr/float_macros.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#if FLT_RADIX != 2
|
||||
#error "FLT_RADIX != 2 is not supported."
|
||||
#endif
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, scalbnf, (float x, int n)) {
|
||||
#if !defined(__FLT_RADIX__)
|
||||
#error __FLT_RADIX__ undefined.
|
||||
#elif __FLT_RADIX__ != 2
|
||||
#error __FLT_RADIX__!=2, unimplemented.
|
||||
#else
|
||||
return fputil::ldexp(x, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@ -7,21 +7,18 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/scalbnf128.h"
|
||||
#include "hdr/float_macros.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#if FLT_RADIX != 2
|
||||
#error "FLT_RADIX != 2 is not supported."
|
||||
#endif
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float128, scalbnf128, (float128 x, int n)) {
|
||||
// TODO: should be switched to use `FLT_RADIX` in hdr/float_macros.h" instead
|
||||
// see: https://github.com/llvm/llvm-project/issues/90496
|
||||
#if !defined(__FLT_RADIX__)
|
||||
#error __FLT_RADIX__ undefined.
|
||||
#elif __FLT_RADIX__ != 2
|
||||
#error __FLT_RADIX__!=2, unimplemented.
|
||||
#else
|
||||
return fputil::ldexp(x, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@ -7,19 +7,18 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/scalbnl.h"
|
||||
#include "hdr/float_macros.h"
|
||||
#include "src/__support/FPUtil/ManipulationFunctions.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#if FLT_RADIX != 2
|
||||
#error "FLT_RADIX != 2 is not supported."
|
||||
#endif
|
||||
|
||||
namespace LIBC_NAMESPACE {
|
||||
|
||||
LLVM_LIBC_FUNCTION(long double, scalbnl, (long double x, int n)) {
|
||||
#if !defined(__FLT_RADIX__)
|
||||
#error __FLT_RADIX__ undefined.
|
||||
#elif __FLT_RADIX__ != 2
|
||||
#error __FLT_RADIX__!=2, unimplemented.
|
||||
#else
|
||||
return fputil::ldexp(x, n);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE
|
||||
|
||||
@ -127,6 +127,11 @@ libc_support_library(
|
||||
hdrs = ["hdr/time_macros.h"],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "hdr_float_macros",
|
||||
hdrs = ["hdr/float_macros.h"],
|
||||
)
|
||||
|
||||
############################ Type Proxy Header Files ###########################
|
||||
|
||||
libc_support_library(
|
||||
@ -189,7 +194,7 @@ libc_support_library(
|
||||
":__support_macros_properties_compiler",
|
||||
":__support_macros_properties_cpu_features",
|
||||
":__support_macros_properties_os",
|
||||
":llvm_libc_macros_float_macros",
|
||||
":hdr_float_macros",
|
||||
":llvm_libc_types_float128",
|
||||
],
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user