diff options
| author | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-11-26 13:35:00 -0500 |
|---|---|---|
| committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2020-11-26 13:46:59 -0500 |
| commit | 617e9f725d29910a608af6d9ead9e91867aa604d (patch) | |
| tree | 1264622ae17c41030897d58c002d0511e4babd04 /Optimizing-assembly-code.md | |
| parent | 60b598504c3f1663607f67153b5c385b35d581ed (diff) | |
Lookup table
Diffstat (limited to 'Optimizing-assembly-code.md')
| -rw-r--r-- | Optimizing-assembly-code.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index cfeb403..17dbc88 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -241,6 +241,30 @@ Or if you really want to optimize for size over speed, then do: ld a, b ``` +Or if you really want to optimize for speed over size, then do: + +```asm + ; 6 bytes, 12 cycles + ; (4 bytes, 5 cycles if you don't need the push hl/pop hl) + push hl + ld h, HIGH(ReversedBitTable) + ld l, a + ld a, [hl] + pop hl +``` + +```asm + ; 256 bytes; placed in ROM0 or the same ROMX section as the bit reversal +SECTION "ReversedBitTable", ROM0, ALIGN[8] +ReversedBitTable:: +x = 0 +rept 256 + ; http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits + db LOW(((((x * $802) & $22110) | ((x * $8020) & $88440)) * $10101) >> 16) +x = x + 1 +endr +``` + ### Set `a` to some constant minus `a` |
