hex.scmp¶
Three-way SIGNED compare (two’s complement) on n-nibble hex vectors: jumps to lt if a[:n]<b[:n], eq if equal, gt if a[:n]>b[:n]. a, b are not modified.
Method: flips the sign bit (MSB) of copies of a, b, then unsigned-compares — this maps the signed range monotonically onto the unsigned range, so it is correct over the whole range with no subtraction (hence no overflow).
Signature¶
def scmp n, a, b, lt, eq, gt @ ba, bb { ... }
Defined in hex/cond_jumps.fj — lines 209–219 (view on GitHub).
Complexity¶
Time:
n(7@+8) + 8 // worst case (a==b); = 2·mov + 2·xor_by + cmpSpace:
n(7@+80) + 8 // (cmp is cheaper than worst when a,b differ in a high hex)
See the complexity glossary for what @, w, dw, dbit, n mean.
Requires init¶
The following must be initialised before this macro is invoked:
hex.cmp.init (or hex.init)
Source¶
Click to view the macro body
def scmp n, a, b, lt, eq, gt @ ba, bb {
.mov n, ba, a
.xor_by ba+(n-1)*dw, 8
.mov n, bb, b
.xor_by bb+(n-1)*dw, 8
.cmp n, ba, bb, lt, eq, gt
ba:
.vec n
bb:
.vec n
}
Depends on¶
← Previous: hex.max