From e188f845350da58ffd0f52f08f21cb06cd57c584 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Tue, 14 Nov 2006 22:15:20 +0000 Subject: [PATCH] 0.9.18.52: If possible, use a shorter XOR instruction on x86-64 when we zero a register. --- src/compiler/x86-64/alloc.lisp | 2 +- src/compiler/x86-64/arith.lisp | 10 +++++----- src/compiler/x86-64/call.lisp | 6 +++--- src/compiler/x86-64/cell.lisp | 2 +- src/compiler/x86-64/move.lisp | 19 +++++++++++++++---- src/compiler/x86-64/subprim.lisp | 4 ++-- version.lisp-expr | 2 +- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/compiler/x86-64/alloc.lisp b/src/compiler/x86-64/alloc.lisp index 690e34b..76bad49 100644 --- a/src/compiler/x86-64/alloc.lisp +++ b/src/compiler/x86-64/alloc.lisp @@ -124,7 +124,7 @@ (inst lea result (make-ea :byte :base result :disp other-pointer-lowtag)) (storew type result 0 other-pointer-lowtag) (storew length result vector-length-slot other-pointer-lowtag) - (inst xor zero zero) + (zeroize zero) (inst rep) (inst stos zero))) diff --git a/src/compiler/x86-64/arith.lisp b/src/compiler/x86-64/arith.lisp index 100ca5e..e0a4d3c 100644 --- a/src/compiler/x86-64/arith.lisp +++ b/src/compiler/x86-64/arith.lisp @@ -694,7 +694,7 @@ (inst shl result amount) (inst shr result (- amount)))) (t (if (sc-is result unsigned-reg) - (inst xor result result) + (zeroize result) (inst mov result 0)))))))) (define-vop (fast-ash-left/signed=>signed) @@ -786,7 +786,7 @@ (inst neg ecx) (inst cmp ecx 63) (inst jmp :be OKAY) - (inst xor result result) + (zeroize result) (inst jmp DONE) OKAY (inst shr result :cl) @@ -896,7 +896,7 @@ (inst or ecx ecx) (inst jmp :ns POSITIVE) (inst neg ecx) - (inst xor zero zero) + (zeroize zero) (inst shr result :cl) (inst cmp ecx 63) (inst cmov :nbe result zero) @@ -927,7 +927,7 @@ (inst inc res) (inst jmp DONE) ZERO - (inst xor res res) + (zeroize res) DONE)) (define-vop (unsigned-byte-64-len) @@ -944,7 +944,7 @@ (inst inc res) (inst jmp DONE) ZERO - (inst xor res res) + (zeroize res) DONE)) (define-vop (unsigned-byte-64-count) diff --git a/src/compiler/x86-64/call.lisp b/src/compiler/x86-64/call.lisp index da925b3..4f25442 100644 --- a/src/compiler/x86-64/call.lisp +++ b/src/compiler/x86-64/call.lisp @@ -797,7 +797,7 @@ do (noise `(loadw ,name new-fp ,index))) (noise)) '((if (zerop nargs) - (inst xor rcx rcx) + (zeroize rcx) (inst mov rcx (fixnumize nargs))))) ,@(cond ((eq return :tail) '(;; Python has figured out what frame we should @@ -1032,7 +1032,7 @@ ;; Establish the values pointer and values count. (move rbx rbp-tn) (if (zerop nvals) - (inst xor rcx rcx) ; smaller + (zeroize rcx) ; smaller (inst mov rcx (fixnumize nvals))) ;; Restore the frame pointer. (move rbp-tn old-fp) @@ -1194,7 +1194,7 @@ ;; We need to copy from downwards up to avoid overwriting some of ;; the yet uncopied args. So we need to use R9 as the copy index ;; and RCX as the loop counter, rather than using RCX for both. - (inst xor copy-index copy-index) + (zeroize copy-index) ;; We used to use REP MOVS here, but on modern x86 it performs ;; much worse than an explicit loop for small blocks. diff --git a/src/compiler/x86-64/cell.lisp b/src/compiler/x86-64/cell.lisp index d9e8368..929e74f 100644 --- a/src/compiler/x86-64/cell.lisp +++ b/src/compiler/x86-64/cell.lisp @@ -289,7 +289,7 @@ (pseudo-atomic (emit-label get-tls-index-lock) (inst mov temp 1) - (inst xor rax rax) + (zeroize rax) (inst lock) (inst cmpxchg (make-ea-for-symbol-value *tls-index-lock*) temp) (inst jmp :ne get-tls-index-lock) diff --git a/src/compiler/x86-64/move.lisp b/src/compiler/x86-64/move.lisp index 4caf11f..a5de78c 100644 --- a/src/compiler/x86-64/move.lisp +++ b/src/compiler/x86-64/move.lisp @@ -11,6 +11,17 @@ (in-package "SB!VM") +(defun zeroize (tn) + (let ((offset (tn-offset tn))) + ;; Using the 32-bit instruction accomplishes the same thing and is + ;; one byte shorter. + (if (<= offset edi-offset) + (let ((tn (make-random-tn :kind :normal + :sc (sc-or-lose 'dword-reg) + :offset offset))) + (inst xor tn tn)) + (inst xor tn tn)))) + (define-move-fun (load-immediate 1) (vop x y) ((immediate) (any-reg descriptor-reg)) @@ -18,7 +29,7 @@ (etypecase val (integer (if (zerop val) - (inst xor y y) + (zeroize y) (inst mov y (fixnumize val)))) (symbol (load-symbol y val)) @@ -30,7 +41,7 @@ ((immediate) (signed-reg unsigned-reg)) (let ((val (tn-value x))) (if (zerop val) - (inst xor y y) + (zeroize y) (inst mov y val)))) (define-move-fun (load-character 1) (vop x y) @@ -80,7 +91,7 @@ (etypecase val (integer (if (and (zerop val) (sc-is y any-reg descriptor-reg)) - (inst xor y y) + (zeroize y) (move-immediate y (fixnumize val) temp))) (symbol (inst mov y (+ nil-value (static-symbol-offset val)))) @@ -134,7 +145,7 @@ (let ((val (tn-value x))) (etypecase val ((integer 0 0) - (inst xor y y)) + (zeroize y)) ((or (signed-byte 29) (unsigned-byte 29)) (inst mov y (fixnumize val))) (integer diff --git a/src/compiler/x86-64/subprim.lisp b/src/compiler/x86-64/subprim.lisp index 74692e8..4b3eed2 100644 --- a/src/compiler/x86-64/subprim.lisp +++ b/src/compiler/x86-64/subprim.lisp @@ -28,7 +28,7 @@ (:generator 40 ;; Move OBJECT into a temp we can bash on, and initialize the count. (move ptr object) - (inst xor count count) + (zeroize count) ;; If we are starting with NIL, then it's really easy. (inst cmp ptr nil-value) (inst jmp :e DONE) @@ -66,7 +66,7 @@ ;; Get a copy of OBJECT in a register we can bash on, and ;; initialize COUNT. (move ptr object) - (inst xor count count) + (zeroize count) ;; If we are starting with NIL, we be done. (inst cmp ptr nil-value) (inst jmp :e DONE) diff --git a/version.lisp-expr b/version.lisp-expr index 51fa7d7..72f3f96 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -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.18.51" +"0.9.18.52" -- 1.7.10.4