From: Vitaly Mayatskikh <v.mayatskih@gm...>  20081116 14:28:26

1. SBCL generates LEA operation even for increments. Use INC instead of LEA in such cases. 2. SBCL can optimize addition to use LEA and INC instead of ADD, but there's no optimization for subtraction. It's possible to use DEC for decrements, which is shorter and faster than `sub r, 1'. Index: arith.lisp =================================================================== RCS file: /cvsroot/sbcl/sbcl/src/compiler/x8664/arith.lisp,v retrieving revision 1.28 diff p u w r1.28 arith.lisp  arith.lisp 8 May 2008 15:05:23 0000 1.28 +++ arith.lisp 16 Nov 2008 14:27:04 0000 @@ 291,7 +291,7 @@ (:note "inline (signedbyte 64) arithmetic") (:generator 4 (cond ((and (scis x signedreg) (scis r signedreg)  (not (location= x r))) + (not (location= x r)) (not (= y 1))) (inst lea r (makeea :qword :base x :disp y))) (t (move r x) @@ 334,7 +334,7 @@ (:note "inline (unsignedbyte 64) arithmetic") (:generator 4 (cond ((and (scis x unsignedreg) (scis r unsignedreg)  (not (location= x r))) + (not (location= x r)) (not (= y 1))) (inst lea r (makeea :qword :base x :disp y))) (t (move r x) @@ 342,6 +342,38 @@ (inst inc r) (inst add r y)))))) +;;; Special handling of sub on the x86; can use dec for decrements. + +(definevop (fastc/signed=>signed fastsafearithop) + (:translate ) + (:args (x :target r :scs (signedreg signedstack))) + (:info y) + (:argtypes signednum (:constant (signedbyte 32))) + (:results (r :scs (signedreg) + :loadif (not (location= x r)))) + (:resulttypes signednum) + (:note "inline (signedbyte 64) arithmetic") + (:generator 4 + (move r x) + (if (= y 1) + (inst dec r) + (inst sub r y)))) + +(definevop (fastc/unsigned=>unsigned fastsafearithop) + (:translate ) + (:args (x :target r :scs (unsignedreg unsignedstack))) + (:info y) + (:argtypes unsignednum (:constant (unsignedbyte 31))) + (:results (r :scs (unsignedreg) + :loadif (not (location= x r)))) + (:resulttypes unsignednum) + (:note "inline (unsignedbyte 64) arithmetic") + (:generator 4 + (move r x) + (if (= y 1) + (inst dec r) + (inst sub r y)))) + ;;;; multiplication and division (definevop (fast*/fixnum=>fixnum fastsafearithop)  wbr, Vitaly 