cfallin labeled issue #1067:
This would add two new instructions to cranelift,
bextr
andbmak
. They provide a easy to optimize, and easy to generate mechanism for bitfield manipulation.bextr
a = bextr target, size, offset
bextr will extract a _n_ bit large field at the provided offset, and return it in
a
, shifted so that the LSB of the field is also the LSB ofa
.
a
's type is inferred fromtarget
Visual example
offset = 4 size = 4 typeof target = i8 xxxx **** \__/----V 0000 xxxx
bmak
a = bmak target, size, offset
bmak will fill a _n_ bit large field at the provided offset with 1s, the rest with 0. The generated field will then be applied to
target
using a bitwise AND, and the result will be returned ina
.
a
's type is inferred fromtarget
bmak is designed so that you can simply use a bitwise or to combine the fields.Visual Example
offset = 2 size = 4 typeof target = i8 xx0101xx \__/ / \ 00010100
cfallin labeled issue #1067:
This would add two new instructions to cranelift,
bextr
andbmak
. They provide a easy to optimize, and easy to generate mechanism for bitfield manipulation.bextr
a = bextr target, size, offset
bextr will extract a _n_ bit large field at the provided offset, and return it in
a
, shifted so that the LSB of the field is also the LSB ofa
.
a
's type is inferred fromtarget
Visual example
offset = 4 size = 4 typeof target = i8 xxxx **** \__/----V 0000 xxxx
bmak
a = bmak target, size, offset
bmak will fill a _n_ bit large field at the provided offset with 1s, the rest with 0. The generated field will then be applied to
target
using a bitwise AND, and the result will be returned ina
.
a
's type is inferred fromtarget
bmak is designed so that you can simply use a bitwise or to combine the fields.Visual Example
offset = 2 size = 4 typeof target = i8 xx0101xx \__/ / \ 00010100
Last updated: Nov 22 2024 at 16:03 UTC