-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Documentation: std::intrinsics::cttz
does not specify the handling of zero.
#34381
Comments
From: rust/src/librustc_typeck/check/intrinsic.rs Line 264 in 34fd686
It might seem that the intrinsic is always called with a value of 0 (false) but I cannot find where the |
Ah I see now. This intrinsic is used to implement |
That makes sense. Having to do Where is I guess to improve the docs it would be enough to add a note like:
|
Easy way to check that is to ask rustc to emit LLVM-IR for your code. If you click LLVM IR on this playpen, you’ll find a Trailing_zeros is implemented here. |
Thanks! Where is
Nice, TIL! One can also output the asm directly in the playpen :) |
PR opened #38310 |
Clarify zero-value behavior of `ctlz`/`cttz` intrinsics. Fixes rust-lang#34381.
Clarify zero-value behavior of `ctlz`/`cttz` intrinsics. Fixes rust-lang#34381.
Clarify zero-value behavior of `ctlz`/`cttz` intrinsics. Fixes #34381.
The llvm docs for `llvm.cttz.iX(value, flag) specifies that a flag can be passed to control whether zero provides a defined result or not.
Whether
std::intrinsics::cttz
provides a defined result for zero or not should be specified in the documentation, since if not some code might requireif x == 0 { mem::sizeof(x) * 8 } else { std::intrinsics::cttz(x) }
to be used (instead of juststd::intrinsics::cttz(x)
).See the LLVM documentation: http://llvm.org/docs/LangRef.html#llvm-cttz-intrinsic
The text was updated successfully, but these errors were encountered: