Skip to content

Commit 6c4c533

Browse files
committed
[libc][math][c23] Add remainderf16 C23 math function
1 parent 2cf1439 commit 6c4c533

File tree

9 files changed

+60
-3
lines changed

9 files changed

+60
-3
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
536536
# clang-12 and after: https://godbolt.org/z/8ceT9454c
537537
# libc.src.math.nexttowardf16
538538
libc.src.math.nextupf16
539+
libc.src.math.remainderf16
539540
libc.src.math.rintf16
540541
libc.src.math.roundf16
541542
libc.src.math.roundevenf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
566566
libc.src.math.nextdownf16
567567
libc.src.math.nexttowardf16
568568
libc.src.math.nextupf16
569+
libc.src.math.remainderf16
569570
libc.src.math.rintf16
570571
libc.src.math.roundf16
571572
libc.src.math.roundevenf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Basic Operations
198198
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
199199
| nextup | |check| | |check| | |check| | |check| | |check| | 7.12.11.5 | F.10.8.5 |
200200
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
201-
| remainder | |check| | |check| | |check| | | | 7.12.10.2 | F.10.7.2 |
201+
| remainder | |check| | |check| | |check| | |check| | | 7.12.10.2 | F.10.7.2 |
202202
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
203203
| remquo | |check| | |check| | |check| | | |check| | 7.12.10.3 | F.10.7.3 |
204204
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,10 @@ def StdC : StandardSpec<"stdc"> {
581581
FunctionSpec<"exp10", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
582582
FunctionSpec<"exp10f", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
583583

584-
FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
585584
FunctionSpec<"remainder", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
585+
FunctionSpec<"remainderf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
586586
FunctionSpec<"remainderl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
587+
GuardedFunctionSpec<"remainderf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
587588

588589
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
589590
GuardedFunctionSpec<"remquof128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT128">,

libc/src/__support/FPUtil/NormalFloat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ template <typename T> struct NormalFloat {
5252
return;
5353

5454
unsigned normalization_shift = evaluate_normalization_shift(mantissa);
55-
mantissa = mantissa << normalization_shift;
55+
mantissa <<= normalization_shift;
5656
exponent -= normalization_shift;
5757
}
5858

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ add_math_entrypoint_object(powf)
315315
add_math_entrypoint_object(remainder)
316316
add_math_entrypoint_object(remainderf)
317317
add_math_entrypoint_object(remainderl)
318+
add_math_entrypoint_object(remainderf16)
318319

319320
add_math_entrypoint_object(remquo)
320321
add_math_entrypoint_object(remquof)

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,19 @@ add_entrypoint_object(
25702570
-O2
25712571
)
25722572

2573+
add_entrypoint_object(
2574+
remainderf16
2575+
SRCS
2576+
remainderf16.cpp
2577+
HDRS
2578+
../remainderf16.h
2579+
DEPENDS
2580+
libc.src.__support.macros.properties.types
2581+
libc.src.__support.FPUtil.division_and_remainder_operations
2582+
COMPILE_OPTIONS
2583+
-O2
2584+
)
2585+
25732586
add_entrypoint_object(
25742587
hypotf
25752588
SRCS
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of remainderf16 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/remainderf16.h"
10+
#include "src/__support/FPUtil/DivisionAndRemainderOperations.h"
11+
#include "src/__support/common.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
15+
LLVM_LIBC_FUNCTION(float16, remainderf16, (float16 x, float16 y)) {
16+
int quotient;
17+
return fputil::remquo(x, y, quotient);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE

libc/src/math/remainderf16.h

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

0 commit comments

Comments
 (0)