Skip to content

Commit 7683a16

Browse files
authored
[libc][math][c23] Add {remainder,remquo}f16 C23 math functions (#94773)
Part of #93566.
1 parent 4722911 commit 7683a16

File tree

14 files changed

+151
-17
lines changed

14 files changed

+151
-17
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ 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
540+
libc.src.math.remquof16
539541
libc.src.math.rintf16
540542
libc.src.math.roundf16
541543
libc.src.math.roundevenf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ 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
570+
libc.src.math.remquof16
569571
libc.src.math.rintf16
570572
libc.src.math.roundf16
571573
libc.src.math.roundevenf16

libc/docs/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ 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
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
203-
| remquo | |check| | |check| | |check| | | |check| | 7.12.10.3 | F.10.7.3 |
203+
| remquo | |check| | |check| | |check| | |check| | |check| | 7.12.10.3 | F.10.7.3 |
204204
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
205205
| rint | |check| | |check| | |check| | |check| | |check| | 7.12.9.4 | F.10.6.4 |
206206
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,16 @@ 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

588-
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
589-
GuardedFunctionSpec<"remquof128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT128">,
590589
FunctionSpec<"remquo", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
590+
FunctionSpec<"remquof", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
591591
FunctionSpec<"remquol", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>, ArgSpec<IntPtr>]>,
592+
GuardedFunctionSpec<"remquof16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT16">,
593+
GuardedFunctionSpec<"remquof128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>, ArgSpec<IntPtr>], "LIBC_TYPES_HAS_FLOAT128">,
592594

593595
FunctionSpec<"round", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
594596
FunctionSpec<"roundf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,13 @@ 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)
321322
add_math_entrypoint_object(remquof128)
322323
add_math_entrypoint_object(remquol)
324+
add_math_entrypoint_object(remquof16)
323325

324326
add_math_entrypoint_object(rint)
325327
add_math_entrypoint_object(rintf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ add_entrypoint_object(
24952495
DEPENDS
24962496
libc.src.__support.FPUtil.division_and_remainder_operations
24972497
COMPILE_OPTIONS
2498-
-O2
2498+
-O3
24992499
)
25002500

25012501
add_entrypoint_object(
@@ -2519,7 +2519,7 @@ add_entrypoint_object(
25192519
DEPENDS
25202520
libc.src.__support.FPUtil.division_and_remainder_operations
25212521
COMPILE_OPTIONS
2522-
-O2
2522+
-O3
25232523
)
25242524

25252525
add_entrypoint_object(
@@ -2531,7 +2531,20 @@ add_entrypoint_object(
25312531
DEPENDS
25322532
libc.src.__support.FPUtil.division_and_remainder_operations
25332533
COMPILE_OPTIONS
2534-
-O2
2534+
-O3
2535+
)
2536+
2537+
add_entrypoint_object(
2538+
remquof16
2539+
SRCS
2540+
remquof16.cpp
2541+
HDRS
2542+
../remquof16.h
2543+
DEPENDS
2544+
libc.src.__support.macros.properties.types
2545+
libc.src.__support.FPUtil.division_and_remainder_operations
2546+
COMPILE_OPTIONS
2547+
-O3
25352548
)
25362549

25372550
add_entrypoint_object(
@@ -2543,7 +2556,7 @@ add_entrypoint_object(
25432556
DEPENDS
25442557
libc.src.__support.FPUtil.division_and_remainder_operations
25452558
COMPILE_OPTIONS
2546-
-O2
2559+
-O3
25472560
)
25482561

25492562
add_entrypoint_object(
@@ -2555,7 +2568,7 @@ add_entrypoint_object(
25552568
DEPENDS
25562569
libc.src.__support.FPUtil.division_and_remainder_operations
25572570
COMPILE_OPTIONS
2558-
-O2
2571+
-O3
25592572
)
25602573

25612574
add_entrypoint_object(
@@ -2567,7 +2580,20 @@ add_entrypoint_object(
25672580
DEPENDS
25682581
libc.src.__support.FPUtil.division_and_remainder_operations
25692582
COMPILE_OPTIONS
2570-
-O2
2583+
-O3
2584+
)
2585+
2586+
add_entrypoint_object(
2587+
remainderf16
2588+
SRCS
2589+
remainderf16.cpp
2590+
HDRS
2591+
../remainderf16.h
2592+
DEPENDS
2593+
libc.src.__support.macros.properties.types
2594+
libc.src.__support.FPUtil.division_and_remainder_operations
2595+
COMPILE_OPTIONS
2596+
-O3
25712597
)
25722598

25732599
add_entrypoint_object(
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/generic/remquof16.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Implementation of remquof16 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/remquof16.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, remquof16, (float16 x, float16 y, int *exp)) {
16+
return fputil::remquo(x, y, *exp);
17+
}
18+
19+
} // 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

libc/src/math/remquof16.h

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

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,6 @@ add_fp_unittest(
26082608
RemQuoTest.h
26092609
DEPENDS
26102610
libc.src.math.remquof
2611-
libc.src.__support.FPUtil.basic_operations
26122611
libc.src.__support.FPUtil.fp_bits
26132612
)
26142613

@@ -2636,7 +2635,6 @@ add_fp_unittest(
26362635
RemQuoTest.h
26372636
DEPENDS
26382637
libc.src.math.remquo
2639-
libc.src.__support.FPUtil.basic_operations
26402638
libc.src.__support.FPUtil.fp_bits
26412639
)
26422640

@@ -2650,7 +2648,19 @@ add_fp_unittest(
26502648
RemQuoTest.h
26512649
DEPENDS
26522650
libc.src.math.remquol
2653-
libc.src.__support.FPUtil.basic_operations
2651+
libc.src.__support.FPUtil.fp_bits
2652+
)
2653+
2654+
add_fp_unittest(
2655+
remquof16_test
2656+
SUITE
2657+
libc-math-smoke-tests
2658+
SRCS
2659+
remquof16_test.cpp
2660+
HDRS
2661+
RemQuoTest.h
2662+
DEPENDS
2663+
libc.src.math.remquof16
26542664
libc.src.__support.FPUtil.fp_bits
26552665
)
26562666

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
1111

12-
#include "hdr/math_macros.h"
13-
#include "src/__support/FPUtil/BasicOperations.h"
1412
#include "src/__support/FPUtil/FPBits.h"
1513
#include "test/UnitTest/FEnvSafeTest.h"
1614
#include "test/UnitTest/FPMatcher.h"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for remquof16 -------------------------------------------===//
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 "RemQuoTest.h"
10+
11+
#include "src/math/remquof16.h"
12+
13+
LIST_REMQUO_TESTS(float16, LIBC_NAMESPACE::remquof16)

0 commit comments

Comments
 (0)