From cd8131541577ddd4b229e75f34b5f44540cdc6fd Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Thu, 6 Jul 2017 09:27:46 -0400 Subject: [PATCH] x86-64: Improve symbol-value even without #!+immobile-symbols. Better code is generated for #!+immobile-space. The problem is determining which symbols are immobile. Since the cross-compiler always uses immobile space for symbols when it can, at least that much is easy to decide. The other case is compilation to memory: if a symbol has a low address, it won't move. Unfortunately, compiling to fasl can not make use of this, because after deciding to use a 4-byte immediate operand to reference a symbol, we'll lose badly if the loading process has the symbol at a high address. --- src/compiler/tn.lisp | 2 +- src/compiler/x86-64/memory.lisp | 2 +- src/compiler/x86-64/move.lisp | 5 +++-- src/compiler/x86-64/vm.lisp | 14 +++++++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/compiler/tn.lisp b/src/compiler/tn.lisp index 77ff440a2..b001d607c 100644 --- a/src/compiler/tn.lisp +++ b/src/compiler/tn.lisp @@ -224,7 +224,7 @@ ;; Objects of type SYMBOL can be immediate but they still go in the constants ;; because liveness depends on pointer tracing without looking at code-fixups. (when (or (not use-immed-p) - #!+immobile-symbols + #!+immobile-space (let ((val (constant-value constant))) (and (symbolp val) (not (sb!vm:static-symbol-p val))))) (let ((constants (ir2-component-constants component))) diff --git a/src/compiler/x86-64/memory.lisp b/src/compiler/x86-64/memory.lisp index 0dc95db17..3333215af 100644 --- a/src/compiler/x86-64/memory.lisp +++ b/src/compiler/x86-64/memory.lisp @@ -29,7 +29,7 @@ (make-ea :qword :disp (let* ((symbol (tn-value object)) (offset (- (* offset n-word-bytes) lowtag))) - (if (and #!+immobile-symbols (static-symbol-p symbol)) + (if (static-symbol-p symbol) (+ nil-value (static-symbol-offset symbol) offset) (make-fixup symbol :immobile-object offset))))) (loadw value object offset lowtag)))) diff --git a/src/compiler/x86-64/move.lisp b/src/compiler/x86-64/move.lisp index 45b384f45..f11fa959e 100644 --- a/src/compiler/x86-64/move.lisp +++ b/src/compiler/x86-64/move.lisp @@ -85,8 +85,9 @@ ;; If target is a register, we can just mov it there directly ((and (tn-p target) (sc-is target signed-reg unsigned-reg descriptor-reg any-reg)) - ;; val can be a fixup for an immobile symbol - (cond ((and #!+immobile-symbols (numberp val) (zerop val)) (zeroize target)) + ;; val can be a fixup for an immobile-space symbol, i.e. not a number, + ;; hence not acceptable to ZEROP. + (cond ((and (numberp val) (zerop val)) (zeroize target)) (t (inst mov target val)))) ;; Likewise if the value is small enough. ((typep val '(or (signed-byte 32) #!+immobile-space fixup)) diff --git a/src/compiler/x86-64/vm.lisp b/src/compiler/x86-64/vm.lisp index 5bcd7c481..e4528f26b 100644 --- a/src/compiler/x86-64/vm.lisp +++ b/src/compiler/x86-64/vm.lisp @@ -457,8 +457,16 @@ character) (sc-number-or-lose 'immediate)) (symbol - ;; immobile-symbols implies that ALL symbols are static in placement. - (when (and #!-immobile-symbols (static-symbol-p value)) + ;; If #!+immobile-symbols, then ALL symbols are static in placement + ;; and in the sub-2GB space, therefore immediate constants. + ;; Otherwise, if #!+immobile-space, and either compilation is to memory + ;; and the symbol is in immobile-space, or if in the cross-compiler which + ;; dumps all symbols as immobile if possible, then it's immediate. + (when (or #!+(or immobile-symbols (and immobile-space (host-feature sb-xc-host))) t + #!+(and immobile-space (not (host-feature sb-xc-host))) + (and (sb!c::core-object-p sb!c::*compile-object*) + (typep (get-lisp-obj-address value) '(signed-byte 32))) + (static-symbol-p value)) (sc-number-or-lose 'immediate))) (single-float (sc-number-or-lose @@ -491,7 +499,7 @@ (let ((val (tn-value tn))) (etypecase val (integer (if tag (fixnumize val) val)) - (symbol (if (and #!+immobile-symbols (static-symbol-p val)) + (symbol (if (static-symbol-p val) (+ nil-value (static-symbol-offset val)) (make-fixup val :immobile-object))) (character (if tag -- 2.11.4.GIT