Skip to content

Commit

Permalink
0.9.16.34:
Browse files Browse the repository at this point in the history
	Improve code generation for LOGTEST on x86.

	* Use the logic the fixnum test VOPs use for emitting small TEST
	  instructions in the LOGTEST VOPs as well;
	* Change {ODD,EVEN}P source transforms to use LOGTEST.
  • Loading branch information
Nathan Froyd committed Sep 17, 2006
1 parent 01331c5 commit fd63d6a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/compiler/srctran.lisp
Expand Up @@ -183,8 +183,8 @@
(define-source-transform 1+ (x) `(+ ,x 1))
(define-source-transform 1- (x) `(- ,x 1))

(define-source-transform oddp (x) `(not (zerop (logand ,x 1))))
(define-source-transform evenp (x) `(zerop (logand ,x 1)))
(define-source-transform oddp (x) `(logtest ,x 1))
(define-source-transform evenp (x) `(not (logtest ,x 1)))

;;; Note that all the integer division functions are available for
;;; inline expansion.
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/x86/arith.lisp
Expand Up @@ -1060,9 +1060,10 @@
,(symbolicate "FAST-CONDITIONAL" suffix))
(:translate logtest)
(:generator ,cost
(inst test x ,(if (eq suffix '-c/fixnum)
'(fixnumize y)
'y))
(emit-optimized-test-inst x
,(if (eq suffix '-c/fixnum)
'(fixnumize y)
'y))
(inst jmp (if not-p :e :ne) target)))))))
(define-logtest-vops))

Expand Down
24 changes: 24 additions & 0 deletions src/compiler/x86/insts.lisp
Expand Up @@ -1533,6 +1533,30 @@
(t
(error "bogus operands for TEST: ~S and ~S" this that)))))))

;;; Emit the most compact form of the test immediate instruction,
;;; using an 8 bit test when the immediate is only 8 bits and the
;;; value is one of the four low registers (eax, ebx, ecx, edx) or the
;;; control stack.
(defun emit-optimized-test-inst (x y)
(typecase y
((unsigned-byte 7)
(let ((offset (tn-offset x)))
(cond ((and (sc-is x any-reg descriptor-reg)
(or (= offset eax-offset) (= offset ebx-offset)
(= offset ecx-offset) (= offset edx-offset)))
(inst test (make-random-tn :kind :normal
:sc (sc-or-lose 'byte-reg)
:offset offset)
y))
((sc-is x control-stack)
(inst test (make-ea :byte :base ebp-tn
:disp (- (* (1+ offset) n-word-bytes)))
y))
(t
(inst test x y)))))
(t
(inst test x y))))

(define-instruction or (segment dst src)
(:printer-list
(arith-inst-printer-list #b001))
Expand Down
19 changes: 1 addition & 18 deletions src/compiler/x86/type-vops.lisp
Expand Up @@ -13,25 +13,8 @@

;;;; test generation utilities

;;; Emit the most compact form of the test immediate instruction,
;;; using an 8 bit test when the immediate is only 8 bits and the
;;; value is one of the four low registers (eax, ebx, ecx, edx) or the
;;; control stack.
(defun generate-fixnum-test (value)
(let ((offset (tn-offset value)))
(cond ((and (sc-is value any-reg descriptor-reg)
(or (= offset eax-offset) (= offset ebx-offset)
(= offset ecx-offset) (= offset edx-offset)))
(inst test (make-random-tn :kind :normal
:sc (sc-or-lose 'byte-reg)
:offset offset)
3))
((sc-is value control-stack)
(inst test (make-ea :byte :base ebp-tn
:disp (- (* (1+ offset) n-word-bytes)))
3))
(t
(inst test value 3)))))
(emit-optimized-test-inst value 3))

(defun %test-fixnum (value target not-p)
(generate-fixnum-test value)
Expand Down
2 changes: 1 addition & 1 deletion version.lisp-expr
Expand Up @@ -17,4 +17,4 @@
;;; checkins which aren't released. (And occasionally for internal
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
"0.9.16.33"
"0.9.16.34"

0 comments on commit fd63d6a

Please sign in to comment.