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 Diff line number Diff line
@@ -765,10 +765,12 @@
  (:result-types positive-fixnum)
  (:generator 30
    (move res arg)
    ;; BSR is undefined if the source is 0, so check for that here.
    (inst cmp res 0)
    (inst jmp :eq DONE)
    ;; The Intel docs say that BSR leaves the destination register
    ;; undefined if the source is 0.  But AMD64 says the destination
    ;; register is unchanged.  This also appears to be the case for
    ;; GCC and LLVM.
    (inst bsr res res)
    (inst jmp :z DONE)
    ;; The result of BSR is one too small for what we want, so
    ;; increment the result.
    (inst inc res)