Skip to content

Commit 9c40026

Browse files
[libc][math][c23] Implement fminf16 function
1 parent 7b89fa0 commit 9c40026

File tree

11 files changed

+85
-2
lines changed

11 files changed

+85
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
501501
# math.h C23 _Float16 entrypoints
502502
libc.src.math.fabsf16
503503
libc.src.math.fmaxf16
504+
libc.src.math.fminf16
504505
)
505506
endif()
506507

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
534534
# math.h C23 _Float16 entrypoints
535535
libc.src.math.fabsf16
536536
libc.src.math.fmaxf16
537+
libc.src.math.fminf16
537538
)
538539
endif()
539540

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ def StdC : StandardSpec<"stdc"> {
412412
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
413413
FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
414414
GuardedFunctionSpec<"fminf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
415+
GuardedFunctionSpec<"fminf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
415416

416417
FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
417418
FunctionSpec<"fmaxf", 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
@@ -125,6 +125,7 @@ add_math_entrypoint_object(fmin)
125125
add_math_entrypoint_object(fminf)
126126
add_math_entrypoint_object(fminl)
127127
add_math_entrypoint_object(fminf128)
128+
add_math_entrypoint_object(fminf16)
128129

129130
add_math_entrypoint_object(fmaximum)
130131
add_math_entrypoint_object(fmaximumf)

libc/src/math/fmaxf16.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Implementation header for fmaxf16 -------------------------*- C++ -*-===//
1+
//===-- Implementation header for fmaxf16 -----------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/math/fminf16.h

Lines changed: 20 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,20 @@ add_entrypoint_object(
16121612
-O3
16131613
)
16141614

1615+
add_entrypoint_object(
1616+
fminf16
1617+
SRCS
1618+
fminf16.cpp
1619+
HDRS
1620+
../fminf16.h
1621+
DEPENDS
1622+
libc.src.__support.macros.properties.types
1623+
libc.src.__support.FPUtil.basic_operations
1624+
COMPILE_OPTIONS
1625+
-O3
1626+
)
1627+
1628+
16151629
add_entrypoint_object(
16161630
fmax
16171631
SRCS

libc/src/math/generic/fmaxf16.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Unittest of fmaxf16 function ----------------------------------===//
1+
//===-- Unittest of fmaxf16 function --------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

libc/src/math/generic/fminf16.cpp

Lines changed: 19 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,19 @@ add_fp_unittest(
15061506
libc.src.__support.FPUtil.fp_bits
15071507
)
15081508

1509+
add_fp_unittest(
1510+
fminf16_test
1511+
SUITE
1512+
libc-math-smoke-tests
1513+
SRCS
1514+
fminf16_test.cpp
1515+
HDRS
1516+
FMinTest.h
1517+
DEPENDS
1518+
libc.src.math.fminf16
1519+
libc.src.__support.FPUtil.fp_bits
1520+
)
1521+
15091522
add_fp_unittest(
15101523
fmaxf_test
15111524
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fminf -----------------------------------------------===//
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)