Skip to content

Commit

Permalink
[libc][math][c23] Add remquof16 C23 math function
Browse files Browse the repository at this point in the history
  • Loading branch information
overmighty committed Jun 10, 2024
1 parent 6c4c533 commit 7e53ea7
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
# libc.src.math.nexttowardf16
libc.src.math.nextupf16
libc.src.math.remainderf16
libc.src.math.remquof16
libc.src.math.rintf16
libc.src.math.roundf16
libc.src.math.roundevenf16
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 @@ -567,6 +567,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.nexttowardf16
libc.src.math.nextupf16
libc.src.math.remainderf16
libc.src.math.remquof16
libc.src.math.rintf16
libc.src.math.roundf16
libc.src.math.roundevenf16
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 @@ -200,7 +200,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| remquo | |check| | |check| | |check| | | |check| | 7.12.10.3 | F.10.7.3 |
| remquo | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| rint | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
5 changes: 3 additions & 2 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,11 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,

FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
GuardedFunctionSpec<"remquof128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT128">,
FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
FunctionSpec<"remquol", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<IntPtr>]>,
GuardedFunctionSpec<"remquof16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"remquof128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"round", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"roundf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ add_math_entrypoint_object(remquo)
add_math_entrypoint_object(remquof)
add_math_entrypoint_object(remquof128)
add_math_entrypoint_object(remquol)
add_math_entrypoint_object(remquof16)

add_math_entrypoint_object(rint)
add_math_entrypoint_object(rintf)
Expand Down
13 changes: 13 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,19 @@ add_entrypoint_object(
-O2
)

add_entrypoint_object(
remquof16
SRCS
remquof16.cpp
HDRS
../remquof16.h
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.division_and_remainder_operations
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
remainderf
SRCS
Expand Down
19 changes: 19 additions & 0 deletions libc/src/math/generic/remquof16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===-- Implementation of remquof16 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/remquof16.h"
#include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

LLVM_LIBC_FUNCTION(float16, remquof16, (float16 x, float16 y, int *exp)) {
return fputil::remquo(x, y, *exp);
}

} // namespace LIBC_NAMESPACE
20 changes: 20 additions & 0 deletions libc/src/math/remquof16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for remquof16 ---------------------*- 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_REMQUOF16_H
#define LLVM_LIBC_SRC_MATH_REMQUOF16_H

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

namespace LIBC_NAMESPACE {

float16 remquof16(float16 x, float16 y, int *exp);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_MATH_REMQUOF16_H
16 changes: 13 additions & 3 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,6 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquof
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)

Expand Down Expand Up @@ -2636,7 +2635,6 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquo
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)

Expand All @@ -2650,7 +2648,19 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquol
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
remquof16_test
SUITE
libc-math-smoke-tests
SRCS
remquof16_test.cpp
HDRS
RemQuoTest.h
DEPENDS
libc.src.math.remquof16
libc.src.__support.FPUtil.fp_bits
)

Expand Down
2 changes: 0 additions & 2 deletions libc/test/src/math/smoke/RemQuoTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H

#include "hdr/math_macros.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/remquof16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for remquof16 -------------------------------------------===//
//
// 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 "RemQuoTest.h"

#include "src/math/remquof16.h"

LIST_REMQUO_TESTS(float16, LIBC_NAMESPACE::remquof16)

0 comments on commit 7e53ea7

Please sign in to comment.