Skip to content

Commit 7fe59bc

Browse files
committed
Merge branch 'libc-math-fmodf16' into libc-math-fmodf16-exhaustive-test
2 parents dd1cd02 + f6621ff commit 7fe59bc

File tree

13 files changed

+118
-29
lines changed

13 files changed

+118
-29
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
515515
libc.src.math.fminimum_magf16
516516
libc.src.math.fminimum_mag_numf16
517517
libc.src.math.fminimum_numf16
518+
libc.src.math.fmodf16
518519
libc.src.math.fromfpf16
519520
libc.src.math.fromfpxf16
520521
libc.src.math.llrintf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
548548
libc.src.math.fminimum_magf16
549549
libc.src.math.fminimum_mag_numf16
550550
libc.src.math.fminimum_numf16
551+
libc.src.math.fmodf16
551552
libc.src.math.fromfpf16
552553
libc.src.math.fromfpxf16
553554
libc.src.math.llrintf16

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Basic Operations
156156
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
157157
| fminimum_num | |check| | |check| | |check| | |check| | |check| | 7.12.12.9 | F.10.9.5 |
158158
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
159-
| fmod | |check| | |check| | |check| | | |check| | 7.12.10.1 | F.10.7.1 |
159+
| fmod | |check| | |check| | |check| | |check| | |check| | 7.12.10.1 | F.10.7.1 |
160160
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
161161
| fmul | N/A | | | N/A | | 7.12.14.3 | F.10.11 |
162162
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ def StdC : StandardSpec<"stdc"> {
478478
FunctionSpec<"fmod", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
479479
FunctionSpec<"fmodf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
480480
FunctionSpec<"fmodl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
481+
GuardedFunctionSpec<"fmodf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
481482
GuardedFunctionSpec<"fmodf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
482483

483484
FunctionSpec<"frexp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,

libc/src/__support/FPUtil/FPBits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ struct FPRepImpl : public FPRepSem<fp_type, RetT> {
744744
if (LIBC_LIKELY(ep >= 0)) {
745745
// Implicit number bit will be removed by mask
746746
result.set_significand(number);
747-
result.set_biased_exponent(ep + 1);
747+
result.set_biased_exponent(static_cast<StorageType>(ep + 1));
748748
} else {
749749
result.set_significand(number >> -ep);
750750
}

libc/src/__support/FPUtil/generic/FMod.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ class FMod {
210210
e_x - e_y <= int(FPB::EXP_LEN))) {
211211
StorageType m_x = sx.get_explicit_mantissa();
212212
StorageType m_y = sy.get_explicit_mantissa();
213-
StorageType d = (e_x == e_y) ? (m_x - m_y) : (m_x << (e_x - e_y)) % m_y;
213+
StorageType d = (e_x == e_y)
214+
? (m_x - m_y)
215+
: static_cast<StorageType>(m_x << (e_x - e_y)) % m_y;
214216
if (d == 0)
215217
return FPB::zero();
216218
// iy - 1 because of "zero power" for number with power 1

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ add_math_entrypoint_object(fminimum_mag_numf128)
183183
add_math_entrypoint_object(fmod)
184184
add_math_entrypoint_object(fmodf)
185185
add_math_entrypoint_object(fmodl)
186+
add_math_entrypoint_object(fmodf16)
186187
add_math_entrypoint_object(fmodf128)
187188

188189
add_math_entrypoint_object(frexp)

libc/src/math/fmodf16.h

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

libc/src/math/generic/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,19 @@ add_entrypoint_object(
28872887
-O3
28882888
)
28892889

2890+
add_entrypoint_object(
2891+
fmodf16
2892+
SRCS
2893+
fmodf16.cpp
2894+
HDRS
2895+
../fmodf16.h
2896+
DEPENDS
2897+
libc.src.__support.macros.properties.types
2898+
libc.src.__support.FPUtil.generic.fmod
2899+
COMPILE_OPTIONS
2900+
-O3
2901+
)
2902+
28902903
add_entrypoint_object(
28912904
fmodf128
28922905
SRCS

libc/src/math/generic/fmodf16.cpp

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

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,10 +3111,10 @@ add_fp_unittest(
31113111
HDRS
31123112
FModTest.h
31133113
DEPENDS
3114+
libc.hdr.fenv_macros
31143115
libc.src.errno.errno
31153116
libc.src.math.fmodf
3116-
libc.src.__support.FPUtil.basic_operations
3117-
libc.src.__support.FPUtil.nearest_integer_operations
3117+
libc.src.__support.FPUtil.fenv_impl
31183118
# FIXME: Currently fails on the GPU build.
31193119
UNIT_TEST_ONLY
31203120
)
@@ -3128,10 +3128,10 @@ add_fp_unittest(
31283128
HDRS
31293129
FModTest.h
31303130
DEPENDS
3131+
libc.hdr.fenv_macros
31313132
libc.src.errno.errno
31323133
libc.src.math.fmod
3133-
libc.src.__support.FPUtil.basic_operations
3134-
libc.src.__support.FPUtil.nearest_integer_operations
3134+
libc.src.__support.FPUtil.fenv_impl
31353135
# FIXME: Currently fails on the GPU build.
31363136
UNIT_TEST_ONLY
31373137
)
@@ -3145,10 +3145,27 @@ add_fp_unittest(
31453145
HDRS
31463146
FModTest.h
31473147
DEPENDS
3148+
libc.hdr.fenv_macros
31483149
libc.src.errno.errno
31493150
libc.src.math.fmodl
3150-
libc.src.__support.FPUtil.basic_operations
3151-
libc.src.__support.FPUtil.nearest_integer_operations
3151+
libc.src.__support.FPUtil.fenv_impl
3152+
# FIXME: Currently fails on the GPU build.
3153+
UNIT_TEST_ONLY
3154+
)
3155+
3156+
add_fp_unittest(
3157+
fmodf16_test
3158+
SUITE
3159+
libc-math-smoke-tests
3160+
SRCS
3161+
fmodf16_test.cpp
3162+
HDRS
3163+
FModTest.h
3164+
DEPENDS
3165+
libc.hdr.fenv_macros
3166+
libc.src.errno.errno
3167+
libc.src.math.fmodf16
3168+
libc.src.__support.FPUtil.fenv_impl
31523169
# FIXME: Currently fails on the GPU build.
31533170
UNIT_TEST_ONLY
31543171
)
@@ -3162,10 +3179,10 @@ add_fp_unittest(
31623179
HDRS
31633180
FModTest.h
31643181
DEPENDS
3182+
libc.hdr.fenv_macros
31653183
libc.src.errno.errno
31663184
libc.src.math.fmodf128
3167-
libc.src.__support.FPUtil.basic_operations
3168-
libc.src.__support.FPUtil.nearest_integer_operations
3185+
libc.src.__support.FPUtil.fenv_impl
31693186
# FIXME: Currently fails on the GPU build.
31703187
UNIT_TEST_ONLY
31713188
)

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
1111

12-
#include "src/__support/FPUtil/BasicOperations.h"
13-
#include "src/__support/FPUtil/NearestIntegerOperations.h"
12+
#include "src/__support/FPUtil/FEnvImpl.h"
13+
#include "src/errno/libc_errno.h"
1414
#include "test/UnitTest/FEnvSafeTest.h"
1515
#include "test/UnitTest/FPMatcher.h"
1616
#include "test/UnitTest/Test.h"
1717

18-
#include "hdr/math_macros.h"
18+
#include "hdr/fenv_macros.h"
1919

2020
#define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \
2121
EXPECT_FP_EQ(expected, f(x, y)); \
@@ -210,7 +210,8 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
210210
}
211211

212212
void testRegularExtreme(FModFunc f) {
213-
213+
if constexpr (sizeof(T) < sizeof(float))
214+
return;
214215
TEST_REGULAR(0x1p127L, 0x3p-149L, 0x1p-149L);
215216
TEST_REGULAR(0x1p127L, -0x3p-149L, 0x1p-149L);
216217
TEST_REGULAR(0x1p127L, 0x3p-148L, 0x1p-147L);
@@ -224,20 +225,20 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
224225
TEST_REGULAR(-0x1p127L, 0x3p-126L, -0x1p-125L);
225226
TEST_REGULAR(-0x1p127L, -0x3p-126L, -0x1p-125L);
226227

227-
if constexpr (sizeof(T) >= sizeof(double)) {
228-
TEST_REGULAR(0x1p1023L, 0x3p-1074L, 0x1p-1073L);
229-
TEST_REGULAR(0x1p1023L, -0x3p-1074L, 0x1p-1073L);
230-
TEST_REGULAR(0x1p1023L, 0x3p-1073L, 0x1p-1073L);
231-
TEST_REGULAR(0x1p1023L, -0x3p-1073L, 0x1p-1073L);
232-
TEST_REGULAR(0x1p1023L, 0x3p-1022L, 0x1p-1021L);
233-
TEST_REGULAR(0x1p1023L, -0x3p-1022L, 0x1p-1021L);
234-
TEST_REGULAR(-0x1p1023L, 0x3p-1074L, -0x1p-1073L);
235-
TEST_REGULAR(-0x1p1023L, -0x3p-1074L, -0x1p-1073L);
236-
TEST_REGULAR(-0x1p1023L, 0x3p-1073L, -0x1p-1073L);
237-
TEST_REGULAR(-0x1p1023L, -0x3p-1073L, -0x1p-1073L);
238-
TEST_REGULAR(-0x1p1023L, 0x3p-1022L, -0x1p-1021L);
239-
TEST_REGULAR(-0x1p1023L, -0x3p-1022L, -0x1p-1021L);
240-
}
228+
if constexpr (sizeof(T) < sizeof(double))
229+
return;
230+
TEST_REGULAR(0x1p1023L, 0x3p-1074L, 0x1p-1073L);
231+
TEST_REGULAR(0x1p1023L, -0x3p-1074L, 0x1p-1073L);
232+
TEST_REGULAR(0x1p1023L, 0x3p-1073L, 0x1p-1073L);
233+
TEST_REGULAR(0x1p1023L, -0x3p-1073L, 0x1p-1073L);
234+
TEST_REGULAR(0x1p1023L, 0x3p-1022L, 0x1p-1021L);
235+
TEST_REGULAR(0x1p1023L, -0x3p-1022L, 0x1p-1021L);
236+
TEST_REGULAR(-0x1p1023L, 0x3p-1074L, -0x1p-1073L);
237+
TEST_REGULAR(-0x1p1023L, -0x3p-1074L, -0x1p-1073L);
238+
TEST_REGULAR(-0x1p1023L, 0x3p-1073L, -0x1p-1073L);
239+
TEST_REGULAR(-0x1p1023L, -0x3p-1073L, -0x1p-1073L);
240+
TEST_REGULAR(-0x1p1023L, 0x3p-1022L, -0x1p-1021L);
241+
TEST_REGULAR(-0x1p1023L, -0x3p-1022L, -0x1p-1021L);
241242
}
242243
};
243244

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for fmodf16 ---------------------------------------------===//
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 "FModTest.h"
10+
11+
#include "src/math/fmodf16.h"
12+
13+
LIST_FMOD_TESTS(float16, LIBC_NAMESPACE::fmodf16)

0 commit comments

Comments
 (0)