From 5d3a63fa223ea40f8625a47d367d13b8c85c0842 Mon Sep 17 00:00:00 2001
From: Raymond Toy <toy.raymond@gmail.com>
Date: Sat, 28 Nov 2015 16:43:54 -0800
Subject: [PATCH] Support constant shifts for bignum digits.

This gets rid of the load of the shift amount to ecx, saving one
instruction and reducing pressure on the ecx register.
---
 src/compiler/x86/arith.lisp | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/compiler/x86/arith.lisp b/src/compiler/x86/arith.lisp
index 3b51b0517..c01faf07f 100644
--- a/src/compiler/x86/arith.lisp
+++ b/src/compiler/x86/arith.lisp
@@ -1445,31 +1445,43 @@
   (:translate bignum::%ashr)
   (:policy :fast-safe)
   (:args (digit :scs (unsigned-reg unsigned-stack) :target result)
-	 (count :scs (unsigned-reg) :target ecx))
+	 (count :scs (unsigned-reg immediate)))
   (:arg-types unsigned-num positive-fixnum)
   (:temporary (:sc unsigned-reg :offset ecx-offset :from (:argument 1)) ecx)
   (:results (result :scs (unsigned-reg) :from (:argument 0)
 		    :load-if (not (and (sc-is result unsigned-stack)
 				       (location= digit result)))))
   (:result-types unsigned-num)
-  (:generator 1
+  (:generator 2
     (move result digit)
-    (move ecx count)
-    (inst sar result :cl)))
+    (sc-case count
+      (unsigned-reg
+       (move ecx count)
+       (inst sar result :cl))
+      (immediate
+       (inst sar result (tn-value count))))))
 
 (define-vop (digit-lshr digit-ashr)
   (:translate bignum::%digit-logical-shift-right)
-  (:generator 1
+  (:generator 2
     (move result digit)
-    (move ecx count)
-    (inst shr result :cl)))
+    (sc-case count
+      (unsigned-reg
+       (move ecx count)
+       (inst shr result :cl))
+      (immediate
+       (inst shr result (tn-value count))))))
 
 (define-vop (digit-ashl digit-ashr)
   (:translate bignum::%ashl)
-  (:generator 1
+  (:generator 2
     (move result digit)
-    (move ecx count)
-    (inst shl result :cl)))
+    (sc-case count
+      (unsigned-reg
+       (move ecx count)
+       (inst shl result :cl))
+      (immediate
+       (inst shl result (tn-value count))))))
 
 
 ;;;; Static functions.
-- 
GitLab