diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2022-01-12 18:04:58 -0500 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2022-01-12 18:04:58 -0500 |
commit | 696d4f6eb20348c2173ab3ee72e55f7674d50a75 (patch) | |
tree | eb835a4d5aed8bb6637109724bbd6107c4e40625 | |
parent | e41078e383236e9cd99e54e5a141ad7a2242424c (diff) |
Optimize a & MASK == MASK
-rw-r--r-- | Optimizing-assembly-code.md | 20 |
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: |