From 23e8ed407c99d1b26465acc0aa61c1c88cc81893 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Sun, 2 Jun 2013 21:14:15 +0400 Subject: [PATCH] Better calls to static functions on x86-64. Encode the calls to static functions as an immediate argument to the CALL instruction when possible. --- NEWS | 1 + src/compiler/x86-64/macros.lisp | 8 ++++++++ src/compiler/x86-64/static-fn.lisp | 10 +--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 9b52416..d84fd52 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ changes relative to sbcl-1.1.8: * enchancement: disassemble now annotates some previously missing static functions, like LENGTH. + * optimization: calls to static functions on x86-64 use less instructions. changes in sbcl-1.1.8 relative to sbcl-1.1.7: * notice: The implementation of MAP-ALLOCATED-OBJECTS (the heart of diff --git a/src/compiler/x86-64/macros.lisp b/src/compiler/x86-64/macros.lisp index 04d7ae5..8088d43 100644 --- a/src/compiler/x86-64/macros.lisp +++ b/src/compiler/x86-64/macros.lisp @@ -61,6 +61,14 @@ (defmacro popw (ptr &optional (slot 0) (lowtag 0)) `(inst pop (make-ea-for-object-slot ,ptr ,slot ,lowtag))) + +(defun call-indirect (offset) + (let ((ea (make-ea :qword :disp offset))) + (cond ((immediate32-p offset) + (inst call ea)) + (t + (inst mov temp-reg-tn ea) + (inst call temp-reg-tn))))) ;;;; macros to generate useful values diff --git a/src/compiler/x86-64/static-fn.lisp b/src/compiler/x86-64/static-fn.lisp index bf3c6ea..ec4809a 100644 --- a/src/compiler/x86-64/static-fn.lisp +++ b/src/compiler/x86-64/static-fn.lisp @@ -73,7 +73,6 @@ static-fun-template) (:args ,@(args)) ,@(temps) - (:temporary (:sc unsigned-reg) call-target) (:results ,@(results)) (:node-var ,node) (:generator ,(+ 50 num-args num-results) @@ -109,14 +108,7 @@ ;; longer executed? Does it not depend on the ;; 1+3=4=fdefn_raw_address_offset relationship above? ;; Is something else going on?) - - ;; Need to load the target address into a register, since - ;; immediate call arguments are just a 32-bit displacement, - ;; which obviously can't work with >4G spaces. - (inst mov call-target - (make-ea :qword - :disp (+ nil-value (static-fun-offset function)))) - (inst call call-target) + (call-indirect (+ nil-value (static-fun-offset function))) ,(collect ((bindings) (links)) (do ((temp (temp-names) (cdr temp)) (name 'values (gensym)) -- 1.7.10.4