-
Notifications
You must be signed in to change notification settings - Fork 163
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
Add ctpop intrinsics #3246
Add ctpop intrinsics #3246
Conversation
Dear reviewers, the CI result looks good overall except for the changelog check. If the patch looks good, I will update the commit message accordingly. Thank you! |
Hello! As we are contributing everything to GCC, we need to follow their rules wrt licensing/authorship. Can you please read https://gcc.gnu.org/dco.html and make sure you add the necessary Also, we'd need you to squash all 3 commits in a single one and add a commit description:
|
let _pop1 = ctpop(42i32); | ||
let _pop2 = ctpop(42u32); | ||
let _pop3 = ctpop(42i128); | ||
let _pop4 = ctpop(42u128); |
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 the test can be made to check the actual result. You could do something similar to the above, or you could even create a dedicated file that only checks ctpop.
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 tried to put this in execute
, but I encountered the following error:
/usr/bin/ld: /workspace/gccrs-build/demo.rs:11: undefined reference to `__builtin_popcountg'
Since this builtin was introduced in gcc 14, I am wondering if the related patch has been merged into the current gcc codebase?
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.
"gcc 14" is a bit too vague, as we're really tracking gcc master branch. If the builtin is missing, then we can't really merge it now I guess.
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 searched for this function in the repository, and it actually appears in the test case. So it's strange that we can't find the symbol. Am I doing something wrong, like missing a necessary runtime library that needs to be linked?
Try passing |
|
||
tree popcount_builtin = error_mark_node; | ||
|
||
BuiltinsContext::get ().lookup_simple_builtin ("__builtin_popcountg", |
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.
why popcountg
and not popcount
here?
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.
Maybe check that the builtin is correctly registered and found (rust-builtins.cc in define_builtins() and lookup_gcc_builtin.
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.
why
popcountg
and notpopcount
here?
Because it is a generic version, it can accommodate various integral types.
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.
It seems to be working now - please take another look :)
42d7d27
to
ec27138
Compare
It looks like you're getting errors on the 32 bit testsuites and the gcc4.8 one |
For the program below: int main() { return __builtin_popcountg((unsigned __int128)45); } The current version of gccrs will produce the following error when using
|
int128 are probably not supported for this target. You need to adjust your test. In C you'd test a macro to check support for int128, but not sure how that is supposed to work in rust. |
I think we should be checking |
And then once |
I'm unsure if rustc supports 128-bit types on the x32 platform. Also, note that clang still cannot compile this on the armv7a target: https://godbolt.org/z/77q7Eee5M. EDIT: Yes https://godbolt.org/z/459e3zssY. |
It's probably fine to just skip |
@c8ef why do you close your PR? |
Sorry, I was trying to re-trigger the CI and got interrupted by other things. |
Oops, there are still two |
This patch adds support for the `ctpop` intrinsic. gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (ctpop_hander): Add `ctpop`. gcc/testsuite/ChangeLog: * rust/execute/torture/ctpop.rs: New test. Signed-off-by: Yuao Ma <[email protected]>
You don't need to close the PR everytime there's something going on. You can mark it as draft to make it clear you're still working on it. |
Part of #658.
This patch adds support for the
ctpop
intrinsic.gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog:
Signed-off-by: Yuao Ma [email protected]