Popcnt() of crate bitinstr fails to compile

Some months ago I created GitHub - StefanSalewski/tiny-chess: Tiny Rust chess game with egui board. As Xilem seems to be not ready yet for a chessboard display, I was playing with Bevy instead. But when copying my engine to the project with the Bevy chessboard, it stops to compile, and I just noticed that the initial EGUI version also stops to compile. The error is

error[E0635]: unknown feature `stdsimd`
  --> /home/salewski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bitintr-0.3.0/src/lib.rs:13:38
   |
13 | #![cfg_attr(bitintr_nightly, feature(stdsimd))]
   |                                      ^^^^^^^

For more information about this error, try `rustc --explain E0635`.
error: could not compile `bitintr` (lib) due to 1 previous error

I guess the reason is, that my Gentoo box recently updated the Rust compiler to

emerge -pv rust

These are the packages that would be merged, in order:

Calculating dependencies... done!
Dependency resolution took 1.15 s (backtrack: 0/20).

[ebuild   R    ] dev-lang/rust-1.80.1:stable/1.80::gentoo  USE="clippy lto nightly parallel-compiler profiler rust-analyzer rust-src rustfmt (-big-endian) -debug -dist -doc (-llvm-libunwind) (-miri) (-system-bootstrap) (-system-llvm) -test -verify-sig -wasm" CPU_FLAGS_X86="sse2" LLVM_TARGETS="AMDGPU (X86) -AArch64 -ARC -ARM -AVR -BPF -CSKY -DirectX -Hexagon -Lanai -LoongArch -M68k -MSP430 -Mips -NVPTX -PowerPC -RISCV -SPIRV -Sparc -SystemZ -VE -WebAssembly -XCore -Xtensa" 0 KiB

I think my engine uses only function popcnt() from bitintr crate. So the question is: Is crate bitintr deprecated now and should not longer be used? And what is the replacement for popcnt() and the other functions provided by crate bitinst?

The stdsimd nightly feature got removed in February. There is already an issue in the bitinstr repo:

and a fix for it

that has not been applied.

Furthermore, the last commit into master was five years ago. The crate looks unmaintained to me. I believe you should either look for a different crate or apply the PR I linked as a patch. Or get rid of the dependency entirely, you can easily implement the Popcnt trait yourself.

2 Likes

Thanks for the fast and detailed reply.

I noticed as well that bitintr was not updated for a long time, but it seems to offer many useful functions, so I was hoping for some form of replacement, perhaps some compiler intrinsics? For popcnt() there is a crate which offers ONLY this function, see crates.io: Rust Package Registry

When I started with Rust one year ago, I was indeed surprised how many crates are typically used even for tiny projects.

The stdlib offers a count_ones methods on all integer types, I'm not sure why you would want to go our of your way to use a crate (guaranteed vectorization maybe? but that's probably a highly specific usecase). It even comes up when you search popcnt.

5 Likes

The stdlib offers a count_ones methods on all integer types,

Thanks, I think that is the desired solution. I never heard the term count_ones for that before, sorry.

[EDIT]

Actually, most of the time I just do a Google search, instead of using std - Rust. I should bookmark that Rust doc page, with it I had found count_ones() immediately :slight_smile:

Note that the relevant feature should be only enabled on a nightly compiler, if a certain feature flag is set. Are you even using cargo +nightly? I doubt so. I think it's a bug in the build cache, because I also sometimes hit a similar issue with some dependency after a toolchain upgrade.

In case you get such weird errors, it usually helps to run cargo clean on your project. I don't know why the build cache sometimes gets messed up.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.