Skip to main content

bytes

Function bytes 

Source
pub fn bytes(func: &mut Func)
Expand description

Rewrites every byte swap into the shifts and masks that are one, and leaves the rest alone.

A byte swap is a rule on a machine that has the instruction and this everywhere else, and until x64.bswap is a term the model knows about, this is what x86-64 gets too. That is tamnd/rucc#307 and the whole of what is left of it: what is written below is correct at every width and slower than the one instruction, which is the trade spec/10-backend.md section 10.3 says the fast path makes everywhere.

It is here rather than in the front end because the masks are worked out from the width, and arithmetic on a value a pattern matched is the one thing the rule language deliberately cannot do. It is here rather than in the walk to the IR because a byte swap is one instruction in the IR and should stay one for as long as anything is reading the IR, so that the day the rule exists nothing above the backend has to change.