Skip to content

[libc][math][c23] Add canonicalizef16 C23 math function #94341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ set(TARGET_LIBM_ENTRYPOINTS
if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
libc.src.math.fabsf16
libc.src.math.floorf16
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ set(TARGET_LIBM_ENTRYPOINTS
if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
libc.src.math.fabsf16
libc.src.math.floorf16
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/c23.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Additions:
* fromfpx*
* nextup*
* nextdown*
* canonicalize*
* canonicalize* |check|
* fmaximum*
* fminimum*
* fmaximum_mag*
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Basic Operations
+==================+==================+=================+========================+======================+========================+========================+============================+
| ceil | |check| | |check| | |check| | |check| | |check| | 7.12.9.1 | F.10.6.1 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| canonicalize | |check| | |check| | |check| | | |check| | 7.12.11.7 | F.10.8.7 |
| canonicalize | |check| | |check| | |check| | |check| | |check| | 7.12.11.7 | F.10.8.7 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| copysign | |check| | |check| | |check| | | |check| | 7.12.11.1 | F.10.8.1 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
1 change: 1 addition & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"canonicalize", RetValSpec<IntType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"canonicalizef", RetValSpec<IntType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"canonicalizel", RetValSpec<IntType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"canonicalizef16", RetValSpec<IntType>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"canonicalizef128", RetValSpec<IntType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
]
>;
Expand Down
3 changes: 2 additions & 1 deletion libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ add_math_entrypoint_object(atanhf)

add_math_entrypoint_object(canonicalize)
add_math_entrypoint_object(canonicalizef)
add_math_entrypoint_object(canonicalizef128)
add_math_entrypoint_object(canonicalizel)
add_math_entrypoint_object(canonicalizef16)
add_math_entrypoint_object(canonicalizef128)

add_math_entrypoint_object(ceil)
add_math_entrypoint_object(ceilf)
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/canonicalizef16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for canonicalizef16 ---------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_MATH_CANONICALIZEF16_H
#define LLVM_LIBC_SRC_MATH_CANONICALIZEF16_H

#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE {

int canonicalizef16(float16 *cx, const float16 *x);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_CANONICALIZEF16_H
14 changes: 14 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)

add_entrypoint_object(
canonicalizef16
SRCS
canonicalizef16.cpp
HDRS
../canonicalizef16.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.basic_operations
)

add_entrypoint_object(
canonicalizef128
SRCS
Expand All @@ -31,6 +44,7 @@ add_entrypoint_object(
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.basic_operations
)

Expand Down
19 changes: 19 additions & 0 deletions libc/src/math/generic/canonicalizef16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of canonicalizef16 function ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/math/canonicalizef16.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(int, canonicalizef16, (float16 * cx, const float16 *x)) {
return fputil::canonicalize(*cx, *x);
}

} // namespace LIBC_NAMESPACE
15 changes: 15 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ add_fp_unittest(
libc.src.__support.integer_literals
)

add_fp_unittest(
canonicalizef16_test
SUITE
libc-math-smoke-tests
SRCS
canonicalizef16_test.cpp
HDRS
CanonicalizeTest.h
DEPENDS
libc.src.math.canonicalizef16
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.integer_literals
)

add_fp_unittest(
canonicalizef128_test
SUITE
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/math/smoke/CanonicalizeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H

#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/integer_literals.h"
#include "test/UnitTest/FEnvSafeTest.h"
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/canonicalizef16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for canonicalizef16 -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "CanonicalizeTest.h"

#include "src/math/canonicalizef16.h"

LIST_CANONICALIZE_TESTS(float16, LIBC_NAMESPACE::canonicalizef16)
Loading