3 ms·
You don't need a conditional. You can set up a mask using sbb. ; precondition: 0 <= x <= N ; (N is constant) mov y, 0
by SamReidHughes 10y ago
You don't need a conditional. You can set up a mask using sbb.
; precondition: 0 <= x <= N
; (N is constant)
mov y, 0 ; set up mask
cmp x, N-1 ; set carry flag if x >= N
sbb y, 0 ; subtract 1 from y if carry flag set
and x, y ; set x to zero if x == N
- jnordwick 10y agoThe cmov looks better than sbb, but both have data dependencies than a predicted branch wouldn't.
- SamReidHughes 10y agoAhh! Serves me right for reading books from before the 486 :P