rust: add a bit operation module
authorPaolo Bonzini <pbonzini@redhat.com>
Thu, 5 Dec 2024 13:29:13 +0000 (14:29 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 10 Dec 2024 17:49:26 +0000 (18:49 +0100)
commitab870fa106e0e3f48db2c5ef0507d107b1b41a21
treecb6b0d6b5fc788dc027981f4b4734401e96e9e0d
parent4ed4da164c957a4475b9d075206f33113a69abda
rust: add a bit operation module

The bindgen supports `static inline` function binding since v0.64.0 as
an experimental feature (`--wrap-static-fns`), and stabilizes it after
v0.70.0.

But the oldest version of bindgen supported by QEMU is v0.60.1, so
there's no way to generate the binding for deposit64() which is `static
inline` (in include/qemu/bitops.h).

Instead, implement it by hand in Rust and make it available for all
unsigned types through an IntegerExt trait. Since it only involves bit
operations, the Rust version of the code is almost identical to the
original C version, but it applies to more types than just u64.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Co-authored-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rust/qemu-api/meson.build
rust/qemu-api/src/bitops.rs [new file with mode: 0644]
rust/qemu-api/src/lib.rs
rust/qemu-api/src/prelude.rs