[libc][math] Refactor dmul family to header-only (#182151)

Refactors the dmul math family to be header-only.

Closes https://github.com/llvm/llvm-project/issues/182150

Target Functions:
  - dmulf128
  - dmull
This commit is contained in:
hulxv
2026-04-24 17:49:19 +03:00
committed by GitHub
parent 25a035d944
commit b093148328
13 changed files with 173 additions and 13 deletions

View File

@@ -89,6 +89,8 @@
#include "math/daddl.h"
#include "math/dfmaf128.h"
#include "math/dfmal.h"
#include "math/dmulf128.h"
#include "math/dmull.h"
#include "math/dsqrtl.h"
#include "math/erfcf16.h"
#include "math/erff.h"

View File

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

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

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

View File

@@ -1005,6 +1005,25 @@ add_header_library(
libc.src.__support.macros.optimization
)
add_header_library(
dmulf128
HDRS
dmulf128.h
DEPENDS
libc.include.llvm-libc-types.float128
libc.src.__support.FPUtil.generic.mul
libc.src.__support.macros.config
)
add_header_library(
dmull
HDRS
dmull.h
DEPENDS
libc.src.__support.FPUtil.generic.mul
libc.src.__support.macros.config
)
add_header_library(
daddf128
HDRS

View File

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

View File

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

View File

@@ -5017,7 +5017,7 @@ add_entrypoint_object(
HDRS
../dmull.h
DEPENDS
libc.src.__support.FPUtil.generic.mul
libc.src.__support.math.dmull
)
add_entrypoint_object(
@@ -5027,8 +5027,7 @@ add_entrypoint_object(
HDRS
../dmulf128.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.generic.mul
libc.src.__support.math.dmulf128
)
add_entrypoint_object(

View File

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

View File

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

View File

@@ -86,6 +86,8 @@ add_fp_unittest(
libc.src.__support.math.daddl
libc.src.__support.math.dfmaf128
libc.src.__support.math.dfmal
libc.src.__support.math.dmulf128
libc.src.__support.math.dmull
libc.src.__support.math.dsqrtl
libc.src.__support.math.exp10m1f
libc.src.__support.math.exp10m1f16
@@ -290,6 +292,8 @@ add_fp_unittest(
libc.src.__support.math.copysignf128
libc.src.__support.math.copysignf16
libc.src.__support.math.copysignl
libc.src.__support.math.dmulf128
libc.src.__support.math.dmull
libc.src.__support.math.floor
libc.src.__support.math.floorbf16
libc.src.__support.math.floorf

View File

@@ -49,6 +49,7 @@ static_assert(3.0f16 == LIBC_NAMESPACE::shared::floorf16(3.7f16));
static_assert(0.0L == LIBC_NAMESPACE::shared::ceill(0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
static_assert(0.0 == LIBC_NAMESPACE::shared::dmull(0.0L, 1.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::floorl(0.0L));
#endif
@@ -63,7 +64,8 @@ static_assert(float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
static_assert(float128(0.0) ==
LIBC_NAMESPACE::shared::copysignf128(float128(0.0),
float128(0.0)));
static_assert(0.0 ==
LIBC_NAMESPACE::shared::dmulf128(float128(0.0), float128(1.0)));
static_assert(float128(0.0) ==
LIBC_NAMESPACE::shared::floorf128(float128(0.0)));

View File

@@ -320,6 +320,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::ceill(0.0L));
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::copysignl(0.0L, 0.0L));
EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::daddl(0.0L, 0.0L));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::dmull(0.0L, 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(0.0L, LIBC_NAMESPACE::shared::floorl(0.0L));
@@ -403,6 +404,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
LIBC_NAMESPACE::shared::daddf128(float128(0.0), float128(0.0)));
EXPECT_FP_EQ(0.0,
LIBC_NAMESPACE::shared::dmulf128(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

@@ -4062,6 +4062,25 @@ libc_support_library(
],
)
libc_support_library(
name = "__support_math_dmulf128",
hdrs = ["src/__support/math/dmulf128.h"],
deps = [
":__support_fputil_basic_operations",
":__support_macros_config",
":llvm_libc_types_float128",
],
)
libc_support_library(
name = "__support_math_dmull",
hdrs = ["src/__support/math/dmull.h"],
deps = [
":__support_fputil_basic_operations",
":__support_macros_config",
],
)
libc_support_library(
name = "__support_math_dsqrtl",
hdrs = ["src/__support/math/dsqrtl.h"],
@@ -7161,10 +7180,18 @@ libc_math_function(
],
)
libc_math_function(name = "dmull")
libc_math_function(
name = "dmull",
additional_deps = [
":__support_math_dmull",
],
)
libc_math_function(
name = "dmulf128",
additional_deps = [
":__support_math_dmulf128",
],
)
libc_math_function(