Better calls to static functions on x86-64.
authorStas Boukarev <stassats@gmail.com>
Sun, 2 Jun 2013 17:14:15 +0000 (21:14 +0400)
committerStas Boukarev <stassats@gmail.com>
Sun, 2 Jun 2013 17:14:15 +0000 (21:14 +0400)
Encode the calls to static functions as an immediate argument to the
CALL instruction when possible.

NEWS
src/compiler/x86-64/macros.lisp
src/compiler/x86-64/static-fn.lisp

diff --git a/NEWS b/NEWS
index 9b52416..d84fd52 100644 (file)
--- 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
index 04d7ae5..8088d43 100644 (file)
 
 (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)))))
 \f
 ;;;; macros to generate useful values
 
index bf3c6ea..ec4809a 100644 (file)
@@ -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)
          ;; 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))