-
Notifications
You must be signed in to change notification settings - Fork 13.4k
HIP: Use builtin_nan instead of manual expansion #128023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/arsenm/clang-hip-remove-unused-ocml-declarations
Are you sure you want to change the base?
HIP: Use builtin_nan instead of manual expansion #128023
Conversation
I'm guessing the only reason the __make_mantissa* functions exist were to support this, so maybe these can be deleted now. This is broken in the non-constant string case, since it ends up emitting a call to the libm function
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-clang Author: Matt Arsenault (arsenm) ChangesI'm guessing the only reason the __make_mantissa* functions This is broken in the non-constant string case, since it ends Full diff: https://github.com/llvm/llvm-project/pull/128023.diff 1 Files Affected:
diff --git a/clang/lib/Headers/__clang_hip_math.h b/clang/lib/Headers/__clang_hip_math.h
index 79cb7906852c4..8c21f5d882181 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -519,24 +519,8 @@ float modff(float __x, float *__iptr) {
}
__DEVICE__
-float nanf(const char *__tagp __attribute__((nonnull))) {
- union {
- float val;
- struct ieee_float {
- unsigned int mantissa : 22;
- unsigned int quiet : 1;
- unsigned int exponent : 8;
- unsigned int sign : 1;
- } bits;
- } __tmp;
- __static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
-
- __tmp.bits.sign = 0u;
- __tmp.bits.exponent = ~0u;
- __tmp.bits.quiet = 1u;
- __tmp.bits.mantissa = __make_mantissa(__tagp);
-
- return __tmp.val;
+float nanf(const char *__tagp) {
+ return __builtin_nanf(__tagp);
}
__DEVICE__
@@ -1072,30 +1056,7 @@ double modf(double __x, double *__iptr) {
__DEVICE__
double nan(const char *__tagp) {
-#if !_WIN32
- union {
- double val;
- struct ieee_double {
- uint64_t mantissa : 51;
- uint32_t quiet : 1;
- uint32_t exponent : 11;
- uint32_t sign : 1;
- } bits;
- } __tmp;
- __static_assert_type_size_equal(sizeof(__tmp.val), sizeof(__tmp.bits));
-
- __tmp.bits.sign = 0u;
- __tmp.bits.exponent = ~0u;
- __tmp.bits.quiet = 1u;
- __tmp.bits.mantissa = __make_mantissa(__tagp);
-
- return __tmp.val;
-#else
- __static_assert_type_size_equal(sizeof(uint64_t), sizeof(double));
- uint64_t __val = __make_mantissa(__tagp);
- __val |= 0xFFF << 51;
- return *reinterpret_cast<double *>(&__val);
-#endif
+ return __builtin_nan(__tagp);
}
__DEVICE__
|
You can test this locally with the following command:git-clang-format --diff c6c75b5d7a9a1869bfcdc413a98b00fe4b9f07d1 88b441975bc452c5b19d30b4d534fbce0b16dc0b --extensions h -- clang/lib/Headers/__clang_hip_math.h View the diff from clang-format here.diff --git a/clang/lib/Headers/__clang_hip_math.h b/clang/lib/Headers/__clang_hip_math.h
index 8c21f5d882..1f62a06b50 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -519,9 +519,7 @@ float modff(float __x, float *__iptr) {
}
__DEVICE__
-float nanf(const char *__tagp) {
- return __builtin_nanf(__tagp);
-}
+float nanf(const char *__tagp) { return __builtin_nanf(__tagp); }
__DEVICE__
float nearbyintf(float __x) { return __builtin_nearbyintf(__x); }
@@ -1055,9 +1053,7 @@ double modf(double __x, double *__iptr) {
}
__DEVICE__
-double nan(const char *__tagp) {
- return __builtin_nan(__tagp);
-}
+double nan(const char *__tagp) { return __builtin_nan(__tagp); }
__DEVICE__
double nearbyint(double __x) { return __builtin_nearbyint(__x); }
|
why do we want to do this if it is broken for non-literal string? |
Right. It doesn't seem likely that it won't be literal, but no documentation I've found requires it to be. |
It's WIP from 3 years ago, I'm putting this up for reference |
I'm guessing the only reason the __make_mantissa* functions
exist were to support this, so maybe these can be deleted now.
This is broken in the non-constant string case, since it ends
up emitting a call to the libm function