[libc][math] Refactor fmaf16 implementation to header-only in src/__support/math folder. (#163977)

This commit is contained in:
Muhammad Bassiouni 2026-03-17 21:35:08 +02:00 committed by GitHub
parent e6f0ec8343
commit bed5e7dc20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 90 additions and 7 deletions

View File

@ -140,6 +140,7 @@
#include "math/fma.h"
#include "math/fmabf16.h"
#include "math/fmaf.h"
#include "math/fmaf16.h"
#include "math/fmax.h"
#include "math/fmaxbf16.h"
#include "math/fmaxf.h"

29
libc/shared/math/fmaf16.h Normal file
View File

@ -0,0 +1,29 @@
//===-- Shared fmaf16 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_FMAF16_H
#define LLVM_LIBC_SHARED_MATH_FMAF16_H
#include "include/llvm-libc-macros/float16-macros.h"
#ifdef LIBC_TYPES_HAS_FLOAT16
#include "shared/libc_common.h"
#include "src/__support/math/fmaf16.h"
namespace LIBC_NAMESPACE_DECL {
namespace shared {
using math::fmaf16;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_TYPES_HAS_FLOAT16
#endif // LLVM_LIBC_SHARED_MATH_FMAF16_H

View File

@ -1338,6 +1338,16 @@ add_header_library(
libc.src.__support.macros.config
)
add_header_library(
fmaf16
HDRS
fmaf16.h
DEPENDS
libc.include.llvm-libc-macros.float16_macros
libc.src.__support.FPUtil.fma
libc.src.__support.macros.config
)
add_header_library(
ffma
HDRS

View File

@ -0,0 +1,33 @@
//===-- Implementation header for fmaf16 ------------------------*- 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_FMAF16_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_FMAF16_H
#include "include/llvm-libc-macros/float16-macros.h"
#ifdef LIBC_TYPES_HAS_FLOAT16
#include "src/__support/FPUtil/FMA.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
LIBC_INLINE float16 fmaf16(float16 x, float16 y, float16 z) {
return fputil::fma<float16>(x, y, z);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_TYPES_HAS_FLOAT16
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMAF16_H

View File

@ -4388,8 +4388,7 @@ add_entrypoint_object(
HDRS
../fmaf16.h
DEPENDS
libc.src.__support.FPUtil.fma
libc.src.__support.macros.properties.types
libc.src.__support.math.fmaf16
)
add_entrypoint_object(

View File

@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmaf16.h"
#include "src/__support/FPUtil/FMA.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/math/fmaf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, fmaf16, (float16 x, float16 y, float16 z)) {
return fputil::fma<float16>(x, y, z);
return math::fmaf16(x, y, z);
}
} // namespace LIBC_NAMESPACE_DECL

View File

@ -136,6 +136,7 @@ add_fp_unittest(
libc.src.__support.math.floorl
libc.src.__support.math.fma
libc.src.__support.math.fmaf
libc.src.__support.math.fmaf16
libc.src.__support.math.fmabf16
libc.src.__support.math.fmax
libc.src.__support.math.fmaxbf16

View File

@ -38,6 +38,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::exp2m1f16(0.0f16));
EXPECT_FP_EQ(0x1p+0f16, LIBC_NAMESPACE::shared::expf16(0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::expm1f16(0.0f16));
EXPECT_FP_EQ(0x0p+0f16,
LIBC_NAMESPACE::shared::fmaf16(0.0f16, 0.0f16, 0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::hypotf16(0.0f16, 0.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::logf16(1.0f16));
EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::sinhf16(0.0f16));

View File

@ -4329,6 +4329,16 @@ libc_support_library(
],
)
libc_support_library(
name = "__support_math_fmaf16",
hdrs = ["src/__support/math/fmaf16.h"],
deps = [
":__support_fputil_fma",
":__support_macros_config",
":llvm_libc_types_float16",
],
)
libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
@ -7108,7 +7118,7 @@ libc_math_function(
libc_math_function(
name = "fmaf16",
additional_deps = [
":__support_math_fma",
":__support_math_fmaf16",
],
)