wiz-lang / wiz

A high-level assembly language for writing homebrew software and games on retro console platforms.
http://wiz-lang.org/
Other
409 stars 40 forks source link

Opt-in syntax sugar to translate multiply/divide/modulo by power-of-two into equivalent bitwise operations. #58

Open Bananattack opened 5 years ago

Bananattack commented 5 years ago

It would be nice if there was an easy way to automatically treat / by 2N as equivalent to right-shift by N (arithmetic if signed, logical if unsigned), * by 2N as equivalent to left-shift by N, % by 2N as bitwise and by 2N-1 (when unsigned). But only when such a specialized mul/div/mod can qualify (eg. math by constant power of two operand), and preferrably opt-in to prevent unwanted optimization from happening.

Then you'd be able to write x /= 16 instead of x >>= 4 or similar.

Potentially this sugar could also be extended to use more optimized instructions than just shifting, if applicable, too. eg. swap + bitwise and on the GB when dividing by 16.