2 ms·
It's a little too early to be hyped about const generics in Rust. You still can't do basic compile time arithmetic on them, such as (BITS+7)/8 to get how many b
by Animats 5y ago
It's a little too early to be hyped about const generics in Rust. You still can't do basic compile time arithmetic on them, such as (BITS+7)/8 to get how many bytes you need.
I recently had to use "FixedBitSet" in Rust. This is simply a set of N bits.
It's the clean way in Rust to do bit-banging. Unfortunately, the underlying implementation is a dynamically allocated Vec. So, when you do bitset.set(4,true), far more code is generated than just one OR instruction.
So, it's not quite here yet.
- SV_BubbleTime 5y ago> far more code is generated than just one OR instruction. How many? Because looking at ARM and C with an unpacked bitfield structure, you’ll have 3 or 4 easily. A load, some shift, or, store. Anytime I see a bitfield in C I assume 4 instructions. So is this close?
- Shish2k 5y agoI’ve been using the `bitflags` crate to do my bit-banging, and it seems to compile down to a single OR instruction quite nicely :)
- pcwalton 5y agoI wonder if it'd make sense to have the const generic parameter be the number of bytes (or words) that the bit set needs, instead of the number of bits. It's ugly, but it could allow the optimizer to eliminate many runtime bounds checks as the size of the vector would become a compile-time constant.