We've just updated MediaWiki and its underlying software. If anything doesn't look or work quite right, please mention it to us. --RanAS
Bithacks: Difference between revisions
From SnesLab
Runic Rain (talk | contribs) m (→Math Bithacks) |
Runic Rain (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
Bithacks are optimization tricks that utilize information in bits and [https://en.wikipedia.org/wiki/Bit_manipulation bit manipulation] | Bithacks are optimization tricks that utilize information in bits and [https://en.wikipedia.org/wiki/Bit_manipulation bit manipulation] | ||
to accomplish their tasks. Usually they work in a slightly non-obvious way, (the most famous being the [https://en.wikipedia.org/wiki/Fast_inverse_square_root fast inverse sqrt]), and bit manipulation in general is harder on the 65c816. To that end here is a collection of some useful tricks. | to accomplish their tasks. Usually they work in a slightly non-obvious way, (the most famous being the [https://en.wikipedia.org/wiki/Fast_inverse_square_root fast inverse sqrt]), and bit manipulation in general is harder on the 65c816. To that end here is a collection of some useful tricks. | ||
<br> | |||
'''Note: cycle counts are intended to be a worst case measure.''' | |||
== Math Bithacks == | == Math Bithacks == | ||
Line 31: | Line 33: | ||
endmacro | endmacro | ||
</pre> | </pre> | ||
== Misc. Tricks == | |||
<small>As this list grows tricks here will be consolidated into their own sections. Clever optimization tricks that aren't necessarily what someone might personally call a "bithack" are okay here as well!</small> |
Revision as of 08:00, 6 April 2021
Bithacks are optimization tricks that utilize information in bits and bit manipulation
to accomplish their tasks. Usually they work in a slightly non-obvious way, (the most famous being the fast inverse sqrt), and bit manipulation in general is harder on the 65c816. To that end here is a collection of some useful tricks.
Note: cycle counts are intended to be a worst case measure.
Math Bithacks
Signed Division By 2 (5 bytes / 10 cycles)
inputs: A
outputs: A
STA $00 ASL $00 ROR
Signed Division By 2n (6+2n bytes / 5+2n cycles)
inputs: A, n
outputs: A
; signed division by two, n times macro SignedDiv_2N(n) BMI ?negative LSR #!n BRA ?end ?negative: LSR #!n ORA #($FF<<(8-!n)) ; sign extension ?end: endmacro
Misc. Tricks
As this list grows tricks here will be consolidated into their own sections. Clever optimization tricks that aren't necessarily what someone might personally call a "bithack" are okay here as well!