Skip to content

Commit 445837a

Browse files
authored
[libc][math][c23] Add fmaf16 C23 math function. (#130757)
Implementation of fmaf16 function for 16-bit inputs.
1 parent ee3e17d commit 445837a

File tree

19 files changed

+145
-13
lines changed

19 files changed

+145
-13
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
@@ -678,6 +678,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
678678
libc.src.math.ffma
679679
libc.src.math.ffmal
680680
libc.src.math.floorf16
681+
libc.src.math.fmaf16
681682
libc.src.math.fmaxf16
682683
libc.src.math.fmaximum_mag_numf16
683684
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
@@ -688,6 +688,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
688688
libc.src.math.fabsf16
689689
libc.src.math.fdimf16
690690
libc.src.math.floorf16
691+
libc.src.math.fmaf16
691692
libc.src.math.fmaxf16
692693
libc.src.math.fmaximum_mag_numf16
693694
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
@@ -749,6 +749,15 @@ functions:
749749
- type: float
750750
- type: float
751751
- type: float
752+
- name: fmaf16
753+
standards:
754+
- stdc
755+
return_type: _Float16
756+
arguments:
757+
- type: _Float16
758+
- type: _Float16
759+
- type: _Float16
760+
guard: LIBC_TYPES_HAS_FLOAT16
752761
- name: fmax
753762
standards:
754763
- stdc

libc/src/math/CMakeLists.txt

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

211211
add_math_entrypoint_object(fma)
212212
add_math_entrypoint_object(fmaf)
213+
add_math_entrypoint_object(fmaf16)
213214

214215
add_math_entrypoint_object(fmax)
215216
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,6 +4287,17 @@ add_entrypoint_object(
42874287
libc.src.__support.FPUtil.fma
42884288
)
42894289

4290+
add_entrypoint_object(
4291+
fmaf16
4292+
SRCS
4293+
fmaf16.cpp
4294+
HDRS
4295+
../fmaf16.h
4296+
DEPENDS
4297+
libc.src.__support.FPUtil.fma
4298+
libc.src.__support.macros.properties.types
4299+
)
4300+
42904301
add_entrypoint_object(
42914302
fma
42924303
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)