[libc][math] Refactor fdiv family to header-only (#182192)
Refactors the fdiv math family to be header-only. Closes https://github.com/llvm/llvm-project/issues/182191 Target Functions: - fdiv - fdivf128 - fdivl --------- Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
This commit is contained in:
@@ -154,6 +154,9 @@
|
||||
#include "math/fdimf128.h"
|
||||
#include "math/fdimf16.h"
|
||||
#include "math/fdiml.h"
|
||||
#include "math/fdiv.h"
|
||||
#include "math/fdivf128.h"
|
||||
#include "math/fdivl.h"
|
||||
#include "math/ffma.h"
|
||||
#include "math/ffmaf128.h"
|
||||
#include "math/ffmal.h"
|
||||
|
||||
23
libc/shared/math/fdiv.h
Normal file
23
libc/shared/math/fdiv.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//===-- Shared fdiv function ------------------------------------*- 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_SHARED_MATH_FDIV_H
|
||||
#define LLVM_LIBC_SHARED_MATH_FDIV_H
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/fdiv.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::fdiv;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_FDIV_H
|
||||
29
libc/shared/math/fdivf128.h
Normal file
29
libc/shared/math/fdivf128.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//===-- Shared fdivf128 function --------------------------------*- 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_SHARED_MATH_FDIVF128_H
|
||||
#define LLVM_LIBC_SHARED_MATH_FDIVF128_H
|
||||
|
||||
#include "include/llvm-libc-types/float128.h"
|
||||
|
||||
#ifdef LIBC_TYPES_HAS_FLOAT128
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/fdivf128.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::fdivf128;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LIBC_TYPES_HAS_FLOAT128
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_FDIVF128_H
|
||||
23
libc/shared/math/fdivl.h
Normal file
23
libc/shared/math/fdivl.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//===-- Shared fdivl function -----------------------------------*- 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_SHARED_MATH_FDIVL_H
|
||||
#define LLVM_LIBC_SHARED_MATH_FDIVL_H
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/fdivl.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::fdivl;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_FDIVL_H
|
||||
@@ -1546,6 +1546,34 @@ add_header_library(
|
||||
libc.src.__support.macros.config
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
fdiv
|
||||
HDRS
|
||||
fdiv.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.macros.config
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
fdivf128
|
||||
HDRS
|
||||
fdivf128.h
|
||||
DEPENDS
|
||||
libc.include.llvm-libc-types.float128
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.macros.config
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
fdivl
|
||||
HDRS
|
||||
fdivl.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.macros.config
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
ffmaf128
|
||||
HDRS
|
||||
|
||||
25
libc/src/__support/math/fdiv.h
Normal file
25
libc/src/__support/math/fdiv.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//===-- Implementation header for fdiv --------------------------*- 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_MATH_FDIV_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIV_H
|
||||
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace math {
|
||||
|
||||
LIBC_INLINE constexpr float fdiv(double x, double y) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIV_H
|
||||
31
libc/src/__support/math/fdivf128.h
Normal file
31
libc/src/__support/math/fdivf128.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//===-- Implementation header for fdivf128 ----------------------*- 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_MATH_FDIVF128_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIVF128_H
|
||||
|
||||
#include "include/llvm-libc-types/float128.h"
|
||||
|
||||
#ifdef LIBC_TYPES_HAS_FLOAT128
|
||||
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace math {
|
||||
|
||||
LIBC_INLINE constexpr float fdivf128(float128 x, float128 y) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LIBC_TYPES_HAS_FLOAT128
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIVF128_H
|
||||
25
libc/src/__support/math/fdivl.h
Normal file
25
libc/src/__support/math/fdivl.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//===-- Implementation header for fdivl -------------------------*- 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_MATH_FDIVL_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_FDIVL_H
|
||||
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace math {
|
||||
|
||||
LIBC_INLINE constexpr float fdivl(long double x, long double y) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FDIVL_H
|
||||
@@ -3116,7 +3116,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../fdiv.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.math.fdiv
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
@@ -3126,7 +3126,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../fdivl.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.math.fdivl
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
@@ -3136,8 +3136,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../fdivf128.h
|
||||
DEPENDS
|
||||
libc.src.__support.macros.properties.types
|
||||
libc.src.__support.FPUtil.generic.div
|
||||
libc.src.__support.math.fdivf128
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/fdiv.h"
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/__support/math/fdiv.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, fdiv, (double x, double y)) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
return math::fdiv(x, y);
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/fdivf128.h"
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/__support/math/fdivf128.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, fdivf128, (float128 x, float128 y)) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
return math::fdivf128(x, y);
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/fdivl.h"
|
||||
#include "src/__support/FPUtil/generic/div.h"
|
||||
#include "src/__support/common.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/__support/math/fdivl.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(float, fdivl, (long double x, long double y)) {
|
||||
return fputil::generic::div<float>(x, y);
|
||||
return math::fdivl(x, y);
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
@@ -151,6 +151,9 @@ add_fp_unittest(
|
||||
libc.src.__support.math.fdimf128
|
||||
libc.src.__support.math.fdimf16
|
||||
libc.src.__support.math.fdiml
|
||||
libc.src.__support.math.fdiv
|
||||
libc.src.__support.math.fdivf128
|
||||
libc.src.__support.math.fdivl
|
||||
libc.src.__support.math.ffma
|
||||
libc.src.__support.math.ffmaf128
|
||||
libc.src.__support.math.ffmal
|
||||
@@ -306,6 +309,9 @@ add_fp_unittest(
|
||||
libc.src.__support.math.ddivl
|
||||
libc.src.__support.math.dmulf128
|
||||
libc.src.__support.math.dmull
|
||||
libc.src.__support.math.fdiv
|
||||
libc.src.__support.math.fdivf128
|
||||
libc.src.__support.math.fdivl
|
||||
libc.src.__support.math.floor
|
||||
libc.src.__support.math.floorbf16
|
||||
libc.src.__support.math.floorf
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
static_assert(0.0 == LIBC_NAMESPACE::shared::ceil(0.0));
|
||||
static_assert(0.0 == LIBC_NAMESPACE::shared::copysign(0.0, 0.0));
|
||||
static_assert(1.0 == LIBC_NAMESPACE::shared::fabs(-1.0));
|
||||
static_assert(0.0f == LIBC_NAMESPACE::shared::fdiv(0.0, 1.0));
|
||||
static_assert(1.0 == LIBC_NAMESPACE::shared::floor(1.2));
|
||||
static_assert(0.0 == LIBC_NAMESPACE::shared::log(1.0));
|
||||
|
||||
@@ -55,6 +56,7 @@ static_assert(0.0L == LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
|
||||
static_assert(0.0 == LIBC_NAMESPACE::shared::ddivl(0.0L, 1.0L));
|
||||
static_assert(0.0 == LIBC_NAMESPACE::shared::dmull(0.0L, 1.0L));
|
||||
static_assert(1.0L == LIBC_NAMESPACE::shared::fabsl(-1.0L));
|
||||
static_assert(0.0f == LIBC_NAMESPACE::shared::fdivl(0.0L, 1.0L));
|
||||
static_assert(0.0L == LIBC_NAMESPACE::shared::floorl(0.0L));
|
||||
|
||||
#endif
|
||||
@@ -75,6 +77,8 @@ static_assert(0.0 ==
|
||||
LIBC_NAMESPACE::shared::ddivf128(float128(0.0), float128(1.0)));
|
||||
static_assert(0.0 ==
|
||||
LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
|
||||
static_assert(0.0f ==
|
||||
LIBC_NAMESPACE::shared::fdivf128(float128(0.0), float128(1.0)));
|
||||
static_assert(float128(0.0) ==
|
||||
LIBC_NAMESPACE::shared::floorf128(float128(0.0)));
|
||||
|
||||
|
||||
@@ -264,6 +264,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fabs(0.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fadd(0.0, 0.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fdim(0.0, 0.0));
|
||||
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fdiv(1.0, 1.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::floor(0.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
|
||||
double getpayload_x = 0.0;
|
||||
@@ -329,6 +330,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
|
||||
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fabsl(0.0L));
|
||||
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L));
|
||||
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fdiml(0.0L, 0.0L));
|
||||
EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::shared::fdivl(1.0L, 1.0L));
|
||||
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::floorl(0.0L));
|
||||
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::fmaxl(0.0L, 0.0L));
|
||||
long double getpayloadl_x = 0.0L;
|
||||
@@ -422,6 +424,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
|
||||
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::floorf128(float128(0.0)));
|
||||
EXPECT_FP_EQ(float128(0.0),
|
||||
LIBC_NAMESPACE::shared::fdimf128(float128(0.0), float128(0.0)));
|
||||
EXPECT_FP_EQ(1.0f,
|
||||
LIBC_NAMESPACE::shared::fdivf128(float128(1.0), float128(1.0)));
|
||||
EXPECT_FP_EQ(float128(0.0),
|
||||
LIBC_NAMESPACE::shared::fmaxf128(float128(0.0), float128(0.0)));
|
||||
|
||||
|
||||
@@ -4493,6 +4493,34 @@ libc_support_library(
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_fdiv",
|
||||
hdrs = ["src/__support/math/fdiv.h"],
|
||||
deps = [
|
||||
":__support_fputil_basic_operations",
|
||||
":__support_macros_config",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_fdivf128",
|
||||
hdrs = ["src/__support/math/fdivf128.h"],
|
||||
deps = [
|
||||
":__support_fputil_basic_operations",
|
||||
":__support_macros_config",
|
||||
":llvm_libc_types_float128",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_fdivl",
|
||||
hdrs = ["src/__support/math/fdivl.h"],
|
||||
deps = [
|
||||
":__support_fputil_basic_operations",
|
||||
":__support_macros_config",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_f16mul",
|
||||
hdrs = ["src/__support/math/f16mul.h"],
|
||||
@@ -7721,12 +7749,25 @@ libc_math_function(
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(name = "fdiv")
|
||||
libc_math_function(
|
||||
name = "fdiv",
|
||||
additional_deps = [
|
||||
":__support_math_fdiv",
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(name = "fdivl")
|
||||
libc_math_function(
|
||||
name = "fdivl",
|
||||
additional_deps = [
|
||||
":__support_math_fdivl",
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(
|
||||
name = "fdivf128",
|
||||
additional_deps = [
|
||||
":__support_math_fdivf128",
|
||||
],
|
||||
)
|
||||
|
||||
libc_math_function(
|
||||
|
||||
Reference in New Issue
Block a user