Hacker News new | ask | show | jobs
by SamReidHughes 3476 days 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
1 comments

The cmov looks better than sbb, but both have data dependencies than a predicted branch wouldn't.
Ahh! Serves me right for reading books from before the 486 :P