dzamlo / rust-bitfield

This crate provides macros to generate bitfield-like struct.
Apache License 2.0
157 stars 19 forks source link

Add design notes #16

Open asomers opened 6 years ago

asomers commented 6 years ago

Could you please add an overview of the design to the documentation? I can't get an idea for how efficiently this crate is implemented without reading the source, and macro source is hard to read.

dzamlo commented 6 years ago

Thanks for the suggestion, I will try to add something.

If you want to see the resulting code to evaluate it, you can use cargo expand on a small project with just your bitfield definition.You can also use cargo asm to check the resulting generated assembly.

In practice, because the bit offsets are constant and LLVM is very good, the generated assembly is often efficient, sometimes only a shr and and instructions to read a field for examples. Even in some case where the code generated by the macros seems bad.

But there is few things to watch for: