Skip to content

Commit 3614bee

Browse files
authored
[libc][math][c23] Add canonicalizef16 C23 math function (#94341)
#93566
1 parent 6168e82 commit 3614bee

File tree

12 files changed

+89
-3
lines changed

12 files changed

+89
-3
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ set(TARGET_LIBM_ENTRYPOINTS
499499
if(LIBC_TYPES_HAS_FLOAT16)
500500
list(APPEND TARGET_LIBM_ENTRYPOINTS
501501
# math.h C23 _Float16 entrypoints
502+
libc.src.math.canonicalizef16
502503
libc.src.math.ceilf16
503504
libc.src.math.fabsf16
504505
libc.src.math.floorf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ set(TARGET_LIBM_ENTRYPOINTS
532532
if(LIBC_TYPES_HAS_FLOAT16)
533533
list(APPEND TARGET_LIBM_ENTRYPOINTS
534534
# math.h C23 _Float16 entrypoints
535+
libc.src.math.canonicalizef16
535536
libc.src.math.ceilf16
536537
libc.src.math.fabsf16
537538
libc.src.math.floorf16

libc/docs/c23.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Additions:
6161
* ufromfpx* |check|
6262
* nextup*
6363
* nextdown*
64-
* canonicalize*
64+
* canonicalize* |check|
6565
* fmaximum*
6666
* fminimum*
6767
* fmaximum_mag*

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Basic Operations
110110
+==================+==================+=================+========================+======================+========================+========================+============================+
111111
| ceil | |check| | |check| | |check| | |check| | |check| | 7.12.9.1 | F.10.6.1 |
112112
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
113-
| canonicalize | |check| | |check| | |check| | | |check| | 7.12.11.7 | F.10.8.7 |
113+
| canonicalize | |check| | |check| | |check| | |check| | |check| | 7.12.11.7 | F.10.8.7 |
114114
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
115115
| copysign | |check| | |check| | |check| | | |check| | 7.12.11.1 | F.10.8.1 |
116116
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ def StdC : StandardSpec<"stdc"> {
679679
FunctionSpec<"canonicalize", RetValSpec<IntType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
680680
FunctionSpec<"canonicalizef", RetValSpec<IntType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
681681
FunctionSpec<"canonicalizel", RetValSpec<IntType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
682+
GuardedFunctionSpec<"canonicalizef16", RetValSpec<IntType>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
682683
GuardedFunctionSpec<"canonicalizef128", RetValSpec<IntType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
683684
]
684685
>;

libc/src/math/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ add_math_entrypoint_object(atanhf)
6161

6262
add_math_entrypoint_object(canonicalize)
6363
add_math_entrypoint_object(canonicalizef)
64-
add_math_entrypoint_object(canonicalizef128)
6564
add_math_entrypoint_object(canonicalizel)
65+
add_math_entrypoint_object(canonicalizef16)
66+
add_math_entrypoint_object(canonicalizef128)
6667

6768
add_math_entrypoint_object(ceil)
6869
add_math_entrypoint_object(ceilf)

libc/src/math/canonicalizef16.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for canonicalizef16 ---------------*- 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_CANONICALIZEF16_H
10+
#define LLVM_LIBC_SRC_MATH_CANONICALIZEF16_H
11+
12+
#include "src/__support/macros/properties/types.h"
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
int canonicalizef16(float16 *cx, const float16 *x);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_MATH_CANONICALIZEF16_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ add_entrypoint_object(
2222
libc.src.__support.FPUtil.basic_operations
2323
)
2424

25+
add_entrypoint_object(
26+
canonicalizef16
27+
SRCS
28+
canonicalizef16.cpp
29+
HDRS
30+
../canonicalizef16.h
31+
COMPILE_OPTIONS
32+
-O3
33+
DEPENDS
34+
libc.src.__support.macros.properties.types
35+
libc.src.__support.FPUtil.basic_operations
36+
)
37+
2538
add_entrypoint_object(
2639
canonicalizef128
2740
SRCS
@@ -31,6 +44,7 @@ add_entrypoint_object(
3144
COMPILE_OPTIONS
3245
-O3
3346
DEPENDS
47+
libc.src.__support.macros.properties.types
3448
libc.src.__support.FPUtil.basic_operations
3549
)
3650

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of canonicalizef16 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/canonicalizef16.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(int, canonicalizef16, (float16 * cx, const float16 *x)) {
16+
return fputil::canonicalize(*cx, *x);
17+
}
18+
19+
} // namespace LIBC_NAMESPACE

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ add_fp_unittest(
211211
libc.src.__support.integer_literals
212212
)
213213

214+
add_fp_unittest(
215+
canonicalizef16_test
216+
SUITE
217+
libc-math-smoke-tests
218+
SRCS
219+
canonicalizef16_test.cpp
220+
HDRS
221+
CanonicalizeTest.h
222+
DEPENDS
223+
libc.src.math.canonicalizef16
224+
libc.src.__support.FPUtil.fp_bits
225+
libc.src.__support.FPUtil.fenv_impl
226+
libc.src.__support.integer_literals
227+
)
228+
214229
add_fp_unittest(
215230
canonicalizef128_test
216231
SUITE

libc/test/src/math/smoke/CanonicalizeTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
1111

12+
#include "src/__support/FPUtil/FEnvImpl.h"
1213
#include "src/__support/FPUtil/FPBits.h"
1314
#include "src/__support/integer_literals.h"
1415
#include "test/UnitTest/FEnvSafeTest.h"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for canonicalizef16 -------------------------------------===//
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 "CanonicalizeTest.h"
10+
11+
#include "src/math/canonicalizef16.h"
12+
13+
LIST_CANONICALIZE_TESTS(float16, LIBC_NAMESPACE::canonicalizef16)

0 commit comments

Comments
 (0)