-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[libc][stdfix] Implement countlsfx
functions in libc.
#126597
Conversation
Signed-off-by: krishna2803 <[email protected]>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Signed-off-by: krishna2803 <[email protected]>
@PiJoules @nickdesaulniers @lntue please give a final review. |
Just to double check, were you able to build and run these tests locally? |
Yeah, I did the testing, the build succeeded locally (along with the On a side node, I think we should probably add pre-commit checks for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending libc owners approval
Tested again, build was successful. |
libc/test/src/stdfix/CMakeLists.txt
Outdated
SRCS | ||
countls${suffix}_test.cpp | ||
COMPILE_OPTIONS | ||
-O3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just removed these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here:
llvm-project/libc/test/src/stdfix/CMakeLists.txt
Lines 83 to 86 in 8790b2c
SRCS | |
countls${suffix}_test.cpp | |
COMPILE_OPTIONS | |
${libc_opt_high_flag} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this fixes the two typos from last time.
Signed-off-by: krishna2803 <[email protected]>
if (f < 0) | ||
f = bit_not(f); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, you had this correct before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry if im missing something, but the doc says:
// Use braces on the outer `if` to avoid a potential dangling `else`
// situation.
if (isa<VarDecl>(D)) {
if (shouldProcessAttr(A))
handleAttr(A);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, that's news to me. I guess because of constexpr
we cant make it if (FXRep::SIGN_LEN > 0 && f < 0)
... or could we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll just test it and see if it works!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it seems it doesn't..
// clang++ -std=c++20 -Wall hello.cpp -o hello
#include <iostream>
constexpr int x = 1;
int main() {
int y;
std::cin >> y;
if constexpr (x > 0 && y > 4)
std::cout << "foo bar";
}
hello.cpp:10:17: error: constexpr if condition is not a constant expression
if constexpr (x > 0 && y > 4)
^~~~~~~~~~~~~~
hello.cpp:10:26: note: read of non-const variable 'y' is not allowed in a constant expression
if constexpr (x > 0 && y > 4)
^
hello.cpp:7:7: note: declared here
int y;
^
1 error generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here:
In file included from /home/krishna/OpenSource/llvm-project/libc/src/stdfix/countlsr.cpp:11:
/home/krishna/OpenSource/llvm-project/libc/src/__support/fixed_point/fx_bits.h:188:17: error: constexpr if condition is not a constant expression
188 | if constexpr (FXRep::SIGN_LEN > 0 && f < 0)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/krishna/OpenSource/llvm-project/libc/src/stdfix/countlsr.cpp:16:68: note: in instantiation of function template specialization '__llvm_libc_21_0_0_git::fixed_point::countls<_Fract>' requested here
16 | LLVM_LIBC_FUNCTION(int, countlsr, (fract f)) { return fixed_point::countls(f); }
| ^
/home/krishna/OpenSource/llvm-project/libc/src/__support/fixed_point/fx_bits.h:188:40: note: function parameter 'f' with unknown value cannot be used in a constant expression
188 | if constexpr (FXRep::SIGN_LEN > 0 && f < 0)
| ^
/home/krishna/OpenSource/llvm-project/libc/src/__support/fixed_point/fx_bits.h:183:11: note: declared here
183 | countls(T f) {
| ^
1 error generated.
fixes llvm#113357 --------- Signed-off-by: krishna2803 <[email protected]>
fixes llvm#113357 --------- Signed-off-by: krishna2803 <[email protected]>
fixes llvm#113357 --------- Signed-off-by: krishna2803 <[email protected]>
fixes llvm#113357 --------- Signed-off-by: krishna2803 <[email protected]>
fixes llvm#113357 --------- Signed-off-by: krishna2803 <[email protected]>
fixes #113357