Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/shared/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "math/expm1f16.h"
#include "math/fma.h"
#include "math/fmaf.h"
#include "math/fmaf16.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
Expand Down
29 changes: 29 additions & 0 deletions libc/shared/math/fmaf16.h
Original file line number Diff line number Diff line change
@@ -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"
#include "shared/libc_common.h"

#ifdef LIBC_TYPES_HAS_FLOAT16

#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
8 changes: 8 additions & 0 deletions libc/src/__support/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ add_header_library(
libc.src.__support.FPUtil.fma
)

add_header_library(
fmaf16
HDRS
fmaf16.h
DEPENDS
libc.src.__support.FPUtil.fma
)

add_header_library(
frexpf128
HDRS
Expand Down
33 changes: 33 additions & 0 deletions libc/src/__support/math/fmaf16.h
Original file line number Diff line number Diff line change
@@ -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 static 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
3 changes: 1 addition & 2 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4711,8 +4711,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(
Expand Down
6 changes: 2 additions & 4 deletions libc/src/math/generic/fmaf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions libc/test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ add_fp_unittest(
libc.src.__support.math.expf16
libc.src.__support.math.fma
libc.src.__support.math.fmaf
libc.src.__support.math.fmaf16
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
Expand Down
3 changes: 2 additions & 1 deletion libc/test/shared/shared_math_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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));
ASSERT_FP_EQ(float16(8 << 5), LIBC_NAMESPACE::shared::ldexpf16(8.0f16, 5));
ASSERT_FP_EQ(float16(-1 * (8 << 5)),
LIBC_NAMESPACE::shared::ldexpf16(-8.0f16, 5));
Expand Down
10 changes: 9 additions & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2807,6 +2807,14 @@ libc_support_library(
],
)

libc_support_library(
name = "__support_math_fmaf16",
hdrs = ["src/__support/math/fmaf16.h"],
deps = [
":__support_fputil_fma",
],
)

libc_support_library(
name = "__support_math_frexpf128",
hdrs = ["src/__support/math/frexpf128.h"],
Expand Down Expand Up @@ -4031,7 +4039,7 @@ libc_math_function(
libc_math_function(
name = "fmaf16",
additional_deps = [
":__support_fputil_fma",
":__support_math_fmaf16",
],
)

Expand Down
Loading