summaryrefslogtreecommitdiff
path: root/Optimizing-assembly-code.md
diff options
context:
space:
mode:
Diffstat (limited to 'Optimizing-assembly-code.md')
-rw-r--r--Optimizing-assembly-code.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md
index 2612299..ea8036e 100644
--- a/Optimizing-assembly-code.md
+++ b/Optimizing-assembly-code.md
@@ -54,6 +54,7 @@ WikiTI's advice fully applies here:
- [Compare `a` to 1](#compare-a-to-1)
- [Compare `a` to 255](#compare-a-to-255)
- [Compare `a` to 0 after masking it](#compare-a-to-0-after-masking-it)
+ - [Compare `a` to a mask after masking it](#compare-a-to-a-mask-after-masking-it)
- [Test whether `a` is negative (compare `a` to $80)](#test-whether-a-is-negative-compare-a-to-80)
- [Subroutines (functions)](#subroutines-functions)
- [Tail call optimization](#tail-call-optimization)
@@ -1688,6 +1689,25 @@ Instead, do this:
```
+### Compare `a` to a mask after masking it
+
+Don't do this:
+
+```asm
+ ; 4 bytes, 4 cycles; sets zero flag if a == MASK and carry flag if a < MASK
+ and MASK
+ cp MASK
+```
+
+If you don't need to set the carry flag, and don't need the masked value of `a`, then do this:
+
+```asm
+ ; 3 bytes, 3 cycles; sets zero flag if a was equal to MASK
+ or ~MASK
+ inc a
+```
+
+
### Test whether `a` is negative (compare `a` to $80)
If you don't need to preserve the value in `a`, then don't do this: