Skip to content

Commit afa6bed

Browse files
authored
[libc] Fix integer rint variants on the GPU (#98095)
Summary: Currently these are implemented as a static cast on `__builtin_rint()` to a long. Howver, this is not strictly correct. The standard states that the output is unspecified, but most implementations, and the LLVM libc implementation, do some kind of guarantee on this beahvior. This is not guaranteed by just doing a cast. This patch just uses the generic versions until we implement `__builitin_lrint` correctly.
1 parent b2fd1eb commit afa6bed

File tree

4 files changed

+7
-99
lines changed

4 files changed

+7
-99
lines changed

libc/src/math/amdgpu/CMakeLists.txt

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -456,54 +456,6 @@ add_entrypoint_object(
456456
VENDOR
457457
)
458458

459-
add_entrypoint_object(
460-
lrint
461-
SRCS
462-
lrint.cpp
463-
HDRS
464-
../lrint.h
465-
COMPILE_OPTIONS
466-
${bitcode_link_flags}
467-
-O2
468-
VENDOR
469-
)
470-
471-
add_entrypoint_object(
472-
lrintf
473-
SRCS
474-
lrintf.cpp
475-
HDRS
476-
../lrintf.h
477-
COMPILE_OPTIONS
478-
${bitcode_link_flags}
479-
-O2
480-
VENDOR
481-
)
482-
483-
add_entrypoint_object(
484-
llrint
485-
SRCS
486-
llrint.cpp
487-
HDRS
488-
../llrint.h
489-
COMPILE_OPTIONS
490-
${bitcode_link_flags}
491-
-O2
492-
VENDOR
493-
)
494-
495-
add_entrypoint_object(
496-
llrintf
497-
SRCS
498-
llrintf.cpp
499-
HDRS
500-
../llrintf.h
501-
COMPILE_OPTIONS
502-
${bitcode_link_flags}
503-
-O2
504-
VENDOR
505-
)
506-
507459
add_entrypoint_object(
508460
pow
509461
SRCS

libc/src/math/nvptx/CMakeLists.txt

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -409,54 +409,6 @@ add_entrypoint_object(
409409
VENDOR
410410
)
411411

412-
add_entrypoint_object(
413-
lrint
414-
SRCS
415-
lrint.cpp
416-
HDRS
417-
../lrint.h
418-
COMPILE_OPTIONS
419-
${bitcode_link_flags}
420-
-O2
421-
VENDOR
422-
)
423-
424-
add_entrypoint_object(
425-
lrintf
426-
SRCS
427-
lrintf.cpp
428-
HDRS
429-
../lrintf.h
430-
COMPILE_OPTIONS
431-
${bitcode_link_flags}
432-
-O2
433-
VENDOR
434-
)
435-
436-
add_entrypoint_object(
437-
llrint
438-
SRCS
439-
llrint.cpp
440-
HDRS
441-
../llrint.h
442-
COMPILE_OPTIONS
443-
${bitcode_link_flags}
444-
-O2
445-
VENDOR
446-
)
447-
448-
add_entrypoint_object(
449-
llrintf
450-
SRCS
451-
llrintf.cpp
452-
HDRS
453-
../llrintf.h
454-
COMPILE_OPTIONS
455-
${bitcode_link_flags}
456-
-O2
457-
VENDOR
458-
)
459-
460412
add_entrypoint_object(
461413
pow
462414
SRCS

libc/test/src/math/RoundToIntegerTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/__support/CPP/algorithm.h"
1313
#include "src/__support/FPUtil/FEnvImpl.h"
1414
#include "src/__support/FPUtil/FPBits.h"
15+
#include "src/__support/macros/properties/architectures.h"
1516
#include "test/UnitTest/FEnvSafeTest.h"
1617
#include "test/UnitTest/FPMatcher.h"
1718
#include "test/UnitTest/Test.h"

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "src/__support/CPP/algorithm.h"
1313
#include "src/__support/FPUtil/FEnvImpl.h"
1414
#include "src/__support/FPUtil/FPBits.h"
15-
#include "src/__support/macros/properties/architectures.h"
1615
#include "test/UnitTest/FEnvSafeTest.h"
1716
#include "test/UnitTest/FPMatcher.h"
1817
#include "test/UnitTest/Test.h"
@@ -51,12 +50,10 @@ class RoundToIntegerTestTemplate
5150
// 0 for errno and exceptions, but this doesn't hold for
5251
// all math functions using RoundToInteger test:
5352
// https://github.com/llvm/llvm-project/pull/88816
54-
#ifndef LIBC_TARGET_ARCH_IS_GPU
5553
if (expectError) {
5654
ASSERT_FP_EXCEPTION(FE_INVALID);
5755
ASSERT_MATH_ERRNO(EDOM);
5856
}
59-
#endif
6057
}
6158

6259
public:
@@ -169,7 +166,13 @@ class RoundToIntegerTestTemplate
169166
#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func) \
170167
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
171168

169+
// The GPU target does not support different rounding modes.
170+
#ifdef LIBC_TARGET_ARCH_IS_GPU
171+
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
172+
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
173+
#else
172174
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
173175
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true)
176+
#endif
174177

175178
#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H

0 commit comments

Comments
 (0)