Skip to content

Commit 1c05bf0

Browse files
committed
[libc][math][c23] Add fmaf16 C23 math function.
1 parent 2e39533 commit 1c05bf0

File tree

17 files changed

+133
-1
lines changed

17 files changed

+133
-1
lines changed

libc/config/gpu/amdgpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
548548
libc.src.math.fabsf16
549549
libc.src.math.fdimf16
550550
libc.src.math.floorf16
551+
libc.src.math.fmaf16
551552
libc.src.math.fmaxf16
552553
libc.src.math.fmaximum_mag_numf16
553554
libc.src.math.fmaximum_magf16

libc/config/gpu/nvptx/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
550550
libc.src.math.fabsf16
551551
libc.src.math.fdimf16
552552
libc.src.math.floorf16
553+
libc.src.math.fmaf16
553554
libc.src.math.fmaxf16
554555
libc.src.math.fmaximum_mag_numf16
555556
libc.src.math.fmaximum_magf16

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
676676
libc.src.math.ffma
677677
libc.src.math.ffmal
678678
libc.src.math.floorf16
679+
libc.src.math.fmaf16
679680
libc.src.math.fmaxf16
680681
libc.src.math.fmaximum_mag_numf16
681682
libc.src.math.fmaximum_magf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
686686
libc.src.math.fabsf16
687687
libc.src.math.fdimf16
688688
libc.src.math.floorf16
689+
libc.src.math.fmaf16
689690
libc.src.math.fmaxf16
690691
libc.src.math.fmaximum_mag_numf16
691692
libc.src.math.fmaximum_magf16

libc/docs/headers/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Higher Math Functions
299299
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
300300
| expm1 | |check| | |check| | | |check| | | 7.12.6.6 | F.10.3.6 |
301301
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
302-
| fma | |check| | |check| | | | | 7.12.13.1 | F.10.10.1 |
302+
| fma | |check| | |check| | | |check| | | 7.12.13.1 | F.10.10.1 |
303303
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
304304
| f16sqrt | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.6 | F.10.11 |
305305
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/include/math.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ functions:
736736
- type: float
737737
- type: float
738738
- type: float
739+
- name: fmaf16
740+
standards:
741+
- stdc
742+
return_type: _Float16
743+
arguments:
744+
- type: _Float16
745+
- type: _Float16
746+
- type: _Float16
747+
guard: LIBC_TYPES_HAS_FLOAT16
739748
- name: fmax
740749
standards:
741750
- stdc

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ add_math_entrypoint_object(floorf128)
209209

210210
add_math_entrypoint_object(fma)
211211
add_math_entrypoint_object(fmaf)
212+
add_math_entrypoint_object(fmaf16)
212213

213214
add_math_entrypoint_object(fmax)
214215
add_math_entrypoint_object(fmaxf)

libc/src/math/fmaf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for fmaf16 ------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_FMAF16_H
10+
#define LLVM_LIBC_SRC_MATH_FMAF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
float16 fmaf16(float16 x, float16 y, float16 z);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_FMAF16_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,6 +4241,16 @@ add_entrypoint_object(
42414241
libc.src.__support.FPUtil.fma
42424242
)
42434243

4244+
add_entrypoint_object(
4245+
fmaf16
4246+
SRCS
4247+
fmaf16.cpp
4248+
HDRS
4249+
../fmaf16.h
4250+
DEPENDS
4251+
libc.src.__support.FPUtil.fma
4252+
)
4253+
42444254
add_entrypoint_object(
42454255
fma
42464256
SRCS

libc/src/math/generic/fmaf16.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of fmaf16 function ---------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/fmaf16.h"
10+
#include "src/__support/FPUtil/FMA.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(float16, fmaf16, (float16 x, float16 y, float16 z)) {
17+
return fputil::fma<float16>(x, y, z);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)