base:advanced_optimizing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
base:advanced_optimizing [2022-12-09 14:47] – [Shifting] bitbreaker | base:advanced_optimizing [2024-01-16 12:57] – [Combining bits / Substitute logical operations] bitbreaker | ||
---|---|---|---|
Line 907: | Line 907: | ||
| | ||
In the same way this method can also be used to set bits (for e.g. with adc #$81) or to toggle bits. | In the same way this method can also be used to set bits (for e.g. with adc #$81) or to toggle bits. | ||
+ | |||
+ | When masking out bits, SAX or SBX is often a good choice. | ||
+ | |||
+ | < | ||
+ | lax value | ||
+ | and #%11110000 | ||
+ | sta highnibble | ||
+ | </ | ||
+ | |||
+ | After this we need to restore from X to mask the lower bits, better then another lda value, but still. | ||
+ | |||
+ | < | ||
+ | lda value | ||
+ | ldx #%11110000 | ||
+ | sax highnibble | ||
+ | </ | ||
+ | |||
+ | This looks already better, we have the original value still in A and can do another mask operation. | ||
+ | |||
+ | < | ||
+ | lax value | ||
+ | eor #%000011111 | ||
+ | sax highnibble | ||
+ | </ | ||
+ | |||
+ | This looks even better, we can reuse X here and also A still contains the original bits, but in an inverted manner. So this opens up more options of reusing the original value at more than one register which gives potential for further savings. | ||
+ | This was spotted in Krill' | ||
====== Illegal opcodes ====== | ====== Illegal opcodes ====== | ||
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker