Skip to content

Commit 8e67495

Browse files
[libc][math][c23] Implement fmaxf16 and fminf16 function (#94131)
Implements fmaxf16 and fminf16, which are two missing functions listed here: #93566
1 parent d5ab38f commit 8e67495

File tree

13 files changed

+167
-2
lines changed

13 files changed

+167
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

+2
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ if(LIBC_TYPES_HAS_FLOAT16)
505505
libc.src.math.fabsf16
506506
libc.src.math.fdimf16
507507
libc.src.math.floorf16
508+
libc.src.math.fmaxf16
509+
libc.src.math.fminf16
508510
libc.src.math.fromfpf16
509511
libc.src.math.fromfpxf16
510512
libc.src.math.llrintf16

libc/config/linux/x86_64/entrypoints.txt

+2
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ if(LIBC_TYPES_HAS_FLOAT16)
538538
libc.src.math.fabsf16
539539
libc.src.math.fdimf16
540540
libc.src.math.floorf16
541+
libc.src.math.fmaxf16
542+
libc.src.math.fminf16
541543
libc.src.math.fromfpf16
542544
libc.src.math.fromfpxf16
543545
libc.src.math.llrintf16

libc/docs/math/index.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Basic Operations
136136
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
137137
| floor | |check| | |check| | |check| | |check| | |check| | 7.12.9.2 | F.10.6.2 |
138138
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
139-
| fmax | |check| | |check| | |check| | | |check| | 7.12.12.2 | F.10.9.2 |
139+
| fmax | |check| | |check| | |check| | |check| | |check| | 7.12.12.2 | F.10.9.2 |
140140
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
141141
| fmaximum | |check| | |check| | |check| | | |check| | 7.12.12.4 | F.10.9.4 |
142142
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -146,7 +146,7 @@ Basic Operations
146146
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
147147
| fmaximum_num | |check| | |check| | |check| | | |check| | 7.12.12.8 | F.10.9.5 |
148148
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
149-
| fmin | |check| | |check| | |check| | | |check| | 7.12.12.3 | F.10.9.3 |
149+
| fmin | |check| | |check| | |check| | |check| | |check| | 7.12.12.3 | F.10.9.3 |
150150
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
151151
| fminimum | |check| | |check| | |check| | | |check| | 7.12.12.5 | F.10.9.4 |
152152
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

+2
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,13 @@ def StdC : StandardSpec<"stdc"> {
416416
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
417417
FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
418418
GuardedFunctionSpec<"fminf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
419+
GuardedFunctionSpec<"fminf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
419420

420421
FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
421422
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
422423
FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
423424
GuardedFunctionSpec<"fmaxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
425+
GuardedFunctionSpec<"fmaxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
424426

425427
FunctionSpec<"fmaximum", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
426428
FunctionSpec<"fmaximumf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ add_math_entrypoint_object(fmax)
124124
add_math_entrypoint_object(fmaxf)
125125
add_math_entrypoint_object(fmaxl)
126126
add_math_entrypoint_object(fmaxf128)
127+
add_math_entrypoint_object(fmaxf16)
127128

128129
add_math_entrypoint_object(fmin)
129130
add_math_entrypoint_object(fminf)
130131
add_math_entrypoint_object(fminl)
131132
add_math_entrypoint_object(fminf128)
133+
add_math_entrypoint_object(fminf16)
132134

133135
add_math_entrypoint_object(fmaximum)
134136
add_math_entrypoint_object(fmaximumf)

libc/src/math/fmaxf16.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for fmaxf16 -----------------------*- 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_FMAXF16_H
10+
#define LLVM_LIBC_SRC_MATH_FMAXF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 fmaxf16(float16 x, float16 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FMAXF16_H

libc/src/math/fminf16.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for fminf16 -----------------------*- 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_FMINF16_H
10+
#define LLVM_LIBC_SRC_MATH_FMINF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
float16 fminf16(float16 x, float16 y);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_FMINF16_H

libc/src/math/generic/CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,20 @@ add_entrypoint_object(
17821782
-O3
17831783
)
17841784

1785+
add_entrypoint_object(
1786+
fminf16
1787+
SRCS
1788+
fminf16.cpp
1789+
HDRS
1790+
../fminf16.h
1791+
DEPENDS
1792+
libc.src.__support.macros.properties.types
1793+
libc.src.__support.FPUtil.basic_operations
1794+
COMPILE_OPTIONS
1795+
-O3
1796+
)
1797+
1798+
17851799
add_entrypoint_object(
17861800
fmax
17871801
SRCS
@@ -1831,6 +1845,19 @@ add_entrypoint_object(
18311845
-O3
18321846
)
18331847

1848+
add_entrypoint_object(
1849+
fmaxf16
1850+
SRCS
1851+
fmaxf16.cpp
1852+
HDRS
1853+
../fmaxf16.h
1854+
DEPENDS
1855+
libc.src.__support.macros.properties.types
1856+
libc.src.__support.FPUtil.basic_operations
1857+
COMPILE_OPTIONS
1858+
-O3
1859+
)
1860+
18341861
add_entrypoint_object(
18351862
fmaximum
18361863
SRCS

libc/src/math/generic/fmaxf16.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of fmaxf16 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/fmaxf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, fmaxf16, (float16 x, float16 y)) {
16+
return fputil::fmax(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/src/math/generic/fminf16.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of fminf16 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/fminf16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, fminf16, (float16 x, float16 y)) {
16+
return fputil::fmin(x, y);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

libc/test/src/math/smoke/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,19 @@ add_fp_unittest(
17471747
libc.src.__support.FPUtil.fp_bits
17481748
)
17491749

1750+
add_fp_unittest(
1751+
fminf16_test
1752+
SUITE
1753+
libc-math-smoke-tests
1754+
SRCS
1755+
fminf16_test.cpp
1756+
HDRS
1757+
FMinTest.h
1758+
DEPENDS
1759+
libc.src.math.fminf16
1760+
libc.src.__support.FPUtil.fp_bits
1761+
)
1762+
17501763
add_fp_unittest(
17511764
fmaxf_test
17521765
SUITE
@@ -1799,6 +1812,19 @@ add_fp_unittest(
17991812
libc.src.__support.FPUtil.fp_bits
18001813
)
18011814

1815+
add_fp_unittest(
1816+
fmaxf16_test
1817+
SUITE
1818+
libc-math-smoke-tests
1819+
SRCS
1820+
fmaxf16_test.cpp
1821+
HDRS
1822+
FMaxTest.h
1823+
DEPENDS
1824+
libc.src.math.fmaxf16
1825+
libc.src.__support.FPUtil.fp_bits
1826+
)
1827+
18021828
add_fp_unittest(
18031829
fmaximuml_test
18041830
SUITE
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fmaxf16 --------------------------------------------===//
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 "FMaxTest.h"
10+
11+
#include "src/math/fmaxf16.h"
12+
13+
LIST_FMAX_TESTS(float16, LIBC_NAMESPACE::fmaxf16)
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fminf16 ---------------------------------------------===//
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 "FMinTest.h"
10+
11+
#include "src/math/fminf16.h"
12+
13+
LIST_FMIN_TESTS(float16, LIBC_NAMESPACE::fminf16)

0 commit comments

Comments
 (0)