6 ms·
Rust does exactly this in many cases. All the integer types have methods like 'count_ones' for popcount and 'trailing_zeros' for ctz, things that are intrinsics
by trishume 10y ago
Rust does exactly this in many cases. All the integer types have methods like 'count_ones' for popcount and 'trailing_zeros' for ctz, things that are intrinsics in other languages. See http://doc.rust-lang.org/1.8.0/std/primitive.u64.html#method.count_ones http://doc.rust-lang.org/1.8.0/std/primitive.u64.html#method...
- kibwen 10y agoThough note that these methods are really just thin abstractions over intrinsics, since Rust doesn't want to stabilize intrinsics directly for reasons of compiler backend portability. For example, the `count_ones` method currently resolves directly to LLVM's `ctpop` intrinsic, defined at https://github.com/rust-lang/rust/blob/master/src/libcore/intrinsics.rs#L548 https://github.com/rust-lang/rust/blob/master/src/libcore/in... .
- nirvdrum 10y agoFYI, when you're on a GitHub page you can press the 'y' key to have the URL changed to one that includes a particular blob reference. It helps prevent bit rot. Curently, your linked line doesn't point to the `ctpop` intrinsic. I think you wanted https://github.com/rust-lang/rust/blob/34fd68668152530dcd1d00865fa8514461b895d7/src/libcore/intrinsics.rs#L558 https://github.com/rust-lang/rust/blob/34fd68668152530dcd1d0...