[libc][math] Refactor dadd family to header-only (#182142)

Closes https://github.com/llvm/llvm-project/issues/182141
This commit is contained in:
Mohamed Emad 2026-03-19 06:37:35 +02:00 committed by GitHub
parent 2e6740541b
commit 4db2ce4d54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 169 additions and 12 deletions

View File

@ -75,6 +75,8 @@
#include "math/coshf16.h"
#include "math/cospif.h"
#include "math/cospif16.h"
#include "math/daddf128.h"
#include "math/daddl.h"
#include "math/dfmaf128.h"
#include "math/dfmal.h"
#include "math/dsqrtl.h"

View File

@ -0,0 +1,29 @@
//===-- Shared daddf128 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_DADDF128_H
#define LLVM_LIBC_SHARED_MATH_DADDF128_H
#include "include/llvm-libc-types/float128.h"
#ifdef LIBC_TYPES_HAS_FLOAT128
#include "shared/libc_common.h"
#include "src/__support/math/daddf128.h"
namespace LIBC_NAMESPACE_DECL {
namespace shared {
using math::daddf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_TYPES_HAS_FLOAT128
#endif // LLVM_LIBC_SHARED_MATH_DADDF128_H

23
libc/shared/math/daddl.h Normal file
View File

@ -0,0 +1,23 @@
//===-- Shared daddl 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_DADDL_H
#define LLVM_LIBC_SHARED_MATH_DADDL_H
#include "shared/libc_common.h"
#include "src/__support/math/daddl.h"
namespace LIBC_NAMESPACE_DECL {
namespace shared {
using math::daddl;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SHARED_MATH_DADDL_H

View File

@ -881,6 +881,25 @@ add_header_library(
libc.src.__support.macros.optimization
)
add_header_library(
daddf128
HDRS
daddf128.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
add_header_library(
daddl
HDRS
daddl.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
add_header_library(
dsqrtl
HDRS

View File

@ -0,0 +1,31 @@
//===-- Implementation header for daddf128 ----------------------*- 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_DADDF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H
#include "include/llvm-libc-types/float128.h"
#ifdef LIBC_TYPES_HAS_FLOAT128
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
LIBC_INLINE double daddf128(float128 x, float128 y) {
return fputil::generic::add<double>(x, y);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_TYPES_HAS_FLOAT128
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDF128_H

View File

@ -0,0 +1,25 @@
//===-- Implementation header for daddl -------------------------*- 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_DADDL_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
LIBC_INLINE double daddl(long double x, long double y) {
return fputil::generic::add<double>(x, y);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DADDL_H

View File

@ -185,7 +185,7 @@ add_entrypoint_object(
HDRS
../daddl.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.math.daddl
)
add_entrypoint_object(
@ -195,8 +195,7 @@ add_entrypoint_object(
HDRS
../daddf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.math.daddf128
)
add_entrypoint_object(

View File

@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/daddf128.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/math/daddf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, daddf128, (float128 x, float128 y)) {
return fputil::generic::add<double>(x, y);
return math::daddf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/daddl.h"
#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/math/daddl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, daddl, (long double x, long double y)) {
return fputil::generic::add<double>(x, y);
return math::daddl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -72,6 +72,8 @@ add_fp_unittest(
libc.src.__support.math.coshf16
libc.src.__support.math.cospif
libc.src.__support.math.cospif16
libc.src.__support.math.daddf128
libc.src.__support.math.daddl
libc.src.__support.math.dfmaf128
libc.src.__support.math.dfmal
libc.src.__support.math.dsqrtl

View File

@ -316,6 +316,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16mull(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::ceill(0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::faddl(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fdiml(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::floorl(0.0L));
@ -375,6 +376,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
&canonicalizef128_x));
EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16subf128(
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::bf16fmaf128(
@ -384,6 +386,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divf128(
float128(4.0), float128(2.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
LIBC_NAMESPACE::shared::daddf128(float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
LIBC_NAMESPACE::shared::faddf128(float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::floorf128(float128(0.0)));

View File

@ -3716,6 +3716,25 @@ libc_support_library(
],
)
libc_support_library(
name = "__support_math_daddf128",
hdrs = ["src/__support/math/daddf128.h"],
deps = [
":__support_fputil_basic_operations",
":__support_macros_config",
":llvm_libc_types_float128",
],
)
libc_support_library(
name = "__support_math_daddl",
hdrs = ["src/__support/math/daddl.h"],
deps = [
":__support_fputil_basic_operations",
":__support_macros_config",
],
)
libc_support_library(
name = "__support_math_dsqrtl",
hdrs = ["src/__support/math/dsqrtl.h"],
@ -6646,10 +6665,18 @@ libc_math_function(
],
)
libc_math_function(name = "daddl")
libc_math_function(
name = "daddl",
additional_deps = [
":__support_math_daddl",
],
)
libc_math_function(
name = "daddf128",
additional_deps = [
":__support_math_daddf128",
],
)
libc_math_function(name = "ddivl")