Commit 8bf5b284 authored by Raymond Toy's avatar Raymond Toy
Browse files

Use ZF flag for the 0 case

Instead of explicitly testing for 0, using the ZF flag after the `BSR`
instruction which is set to true if the source is 0.

We also assume that `BSR` in this case leaves the destination
unchanged even though the Intel docs say the result is undefined in
this case, but the AMD docs say it is unchanged.  See !194 for more
references that say this is true for Intel too.
parent c590fd26
Loading
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -765,10 +765,12 @@
  (:result-types positive-fixnum)
  (:result-types positive-fixnum)
  (:generator 30
  (:generator 30
    (move res arg)
    (move res arg)
    ;; BSR is undefined if the source is 0, so check for that here.
    ;; The Intel docs say that BSR leaves the destination register
    (inst cmp res 0)
    ;; undefined if the source is 0.  But AMD64 says the destination
    (inst jmp :eq DONE)
    ;; register is unchanged.  This also appears to be the case for
    ;; GCC and LLVM.
    (inst bsr res res)
    (inst bsr res res)
    (inst jmp :z DONE)
    ;; The result of BSR is one too small for what we want, so
    ;; The result of BSR is one too small for what we want, so
    ;; increment the result.
    ;; increment the result.
    (inst inc res)
    (inst inc res)