User Tools

Site Tools


base:advanced_optimizing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
base:advanced_optimizing [2022-12-09 14:47] – [Shifting] bitbreakerbase: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.
 + 
 +<code>
 +       lax value
 +       and #%11110000
 +       sta highnibble
 +</code>
 +
 +After this we need to restore from X to mask the lower bits, better then another lda value, but still. 
 +
 +<code>      
 +       lda value
 +       ldx #%11110000
 +       sax highnibble
 +</code>
 +
 +This looks already better, we have the original value still in A and can do another mask operation.
 +
 +<code>
 +       lax value
 +       eor #%000011111
 +       sax highnibble       
 +</code>
 +
 +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's loader when doing lookups on the GCR tables, so thanks to Krill here :-)
 ====== Illegal opcodes ====== ====== Illegal opcodes ======
  
base/advanced_optimizing.txt · Last modified: 2024-03-03 11:06 by bitbreaker