Skip to content

Instantly share code, notes, and snippets.

@gsauthof
Last active April 26, 2025 19:43
Show Gist options
  • Save gsauthof/c2dbb214803015c07d71fd0a7d4e0d74 to your computer and use it in GitHub Desktop.
Save gsauthof/c2dbb214803015c07d71fd0a7d4e0d74 to your computer and use it in GitHub Desktop.
Code / Registers: x5 x6 x7 x29 x30
addi x30, x0, 0x123 ? ? ? ? 0x123
andi x29, x30, 0x00f 0x3
slli x6, x29, 60 0x3000000000000000
srli x7, x30, 4 0x12
add x5, x6, x7 0x3000000000000012
when eliminating the andi instruction, it yields exactly the same result in x6 and of course in x5:
Code / Registers: x5 x6 x7 x29 x30
addi x30, x0, 0x123 ? ? ? ? 0x123
slli x6, x30, 60 0x3000000000000000
srli x7, x30, 4 0x12
add x5, x6, x7 0x3000000000000012
That means the masking step is superfluous, because the left shift would shift out all the masked bits anyways.
Q.E.D.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment