Raymond Toy pushed to branch issue-283-unsigned-integer-length-vop at cmucl / cmucl
Commits: 8bf5b284 by Raymond Toy at 2024-03-22T07:56:03-07:00 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.
- - - - -
1 changed file:
- src/compiler/x86/arith.lisp
Changes:
===================================== src/compiler/x86/arith.lisp ===================================== @@ -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)
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/8bf5b28444fe3d962efad9d8...