Skip to content

Commit 7b89fa0

Browse files
[libc][math][c23] Implement fmaxf16 function
1 parent 0310f7f commit 7b89fa0

File tree

9 files changed

+83
-0
lines changed

9 files changed

+83
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
500500
list(APPEND TARGET_LIBM_ENTRYPOINTS
501501
# math.h C23 _Float16 entrypoints
502502
libc.src.math.fabsf16
503+
libc.src.math.fmaxf16
503504
)
504505
endif()
505506

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
533533
list(APPEND TARGET_LIBM_ENTRYPOINTS
534534
# math.h C23 _Float16 entrypoints
535535
libc.src.math.fabsf16
536+
libc.src.math.fmaxf16
536537
)
537538
endif()
538539

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def StdC : StandardSpec<"stdc"> {
417417
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
418418
FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
419419
GuardedFunctionSpec<"fmaxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
420+
GuardedFunctionSpec<"fmaxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
420421

421422
FunctionSpec<"fmaximum", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
422423
FunctionSpec<"fmaximumf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ add_math_entrypoint_object(fmax)
119119
add_math_entrypoint_object(fmaxf)
120120
add_math_entrypoint_object(fmaxl)
121121
add_math_entrypoint_object(fmaxf128)
122+
add_math_entrypoint_object(fmaxf16)
122123

123124
add_math_entrypoint_object(fmin)
124125
add_math_entrypoint_object(fminf)

libc/src/math/fmaxf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_FMAXF_H
10+
#define LLVM_LIBC_SRC_MATH_FMAXF_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
21+

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,19 @@ add_entrypoint_object(
16611661
-O3
16621662
)
16631663

1664+
add_entrypoint_object(
1665+
fmaxf16
1666+
SRCS
1667+
fmaxf16.cpp
1668+
HDRS
1669+
../fmaxf16.h
1670+
DEPENDS
1671+
libc.src.__support.macros.properties.types
1672+
libc.src.__support.FPUtil.basic_operations
1673+
COMPILE_OPTIONS
1674+
-O3
1675+
)
1676+
16641677
add_entrypoint_object(
16651678
fmaximum
16661679
SRCS

libc/src/math/generic/fmaxf16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Unittest 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/test/src/math/smoke/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,19 @@ add_fp_unittest(
15581558
libc.src.__support.FPUtil.fp_bits
15591559
)
15601560

1561+
add_fp_unittest(
1562+
fmaxf16_test
1563+
SUITE
1564+
libc-math-smoke-tests
1565+
SRCS
1566+
fmaxf16_test.cpp
1567+
HDRS
1568+
FMaxTest.h
1569+
DEPENDS
1570+
libc.src.math.fmaxf16
1571+
libc.src.__support.FPUtil.fp_bits
1572+
)
1573+
15611574
add_fp_unittest(
15621575
fmaximuml_test
15631576
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fmaxf128 --------------------------------------------===//
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)

0 commit comments

Comments
 (0)