summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Optimizing-assembly-code.md24
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`