From 836a86e85b8de2d0ca71e34dfb3d27ee8ceb6641 Mon Sep 17 00:00:00 2001
From: rtoy <rtoy>
Date: Wed, 6 Oct 2004 23:58:46 +0000
Subject: [PATCH] o Add vop for INTEGER-LENGTH of (UNSIGNED-BYTE 32). o Fix
 FAST-ASH/UNSIGNED=>UNSIGNED vop where the amount might be   greater than 31.

---
 compiler/ppc/arith.lisp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/compiler/ppc/arith.lisp b/compiler/ppc/arith.lisp
index 25f5fa3c6..8c69a4db8 100644
--- a/compiler/ppc/arith.lisp
+++ b/compiler/ppc/arith.lisp
@@ -7,7 +7,7 @@
 ;;; Scott Fahlman (FAHLMAN@CMUC). 
 ;;; **********************************************************************
 ;;;
-;;; $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/ppc/arith.lisp,v 1.7 2004/08/02 03:15:17 rtoy Exp $
+;;; $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/ppc/arith.lisp,v 1.8 2004/10/06 23:58:46 rtoy Exp $
 ;;;
 ;;;    This file contains the VM definition arithmetic VOPs for the MIPS.
 ;;;
@@ -351,6 +351,7 @@
 	 (cond
 	  ((and (minusp amount) (< amount -31)) (move result zero-tn))
 	  ((minusp amount) (inst srwi result number (- amount)))
+	  ((> amount 31) (move result zero-tn))
 	  (t (inst slwi result number amount))))))))
 
 (define-vop (fast-ash/signed=>signed)
@@ -412,6 +413,21 @@
       (inst slwi shift shift 2)
       (inst subfic res  shift (fixnumize 32)))))
 
+(define-vop (unsigned-byte-32-len)
+  (:translate integer-length)
+  (:note "inline (unsigned-byte 32) integer-length")
+  (:policy :fast-safe)
+  (:args (arg :scs (unsigned-reg)))
+  (:arg-types unsigned-num)
+  (:results (res :scs (any-reg)))
+  (:result-types positive-fixnum)
+  (:temporary (:scs (non-descriptor-reg) :to (:argument 0)) shift)
+  (:generator 6
+    ; (integer-length arg) = (- 32 (cntlz arg)))
+    (inst cntlzw shift arg)
+    (inst slwi shift shift 2)
+    (inst subfic res  shift (fixnumize 32))))
+
 (define-vop (unsigned-byte-32-count)
   (:translate logcount)
   (:note "inline (unsigned-byte 32) logcount")
-- 
GitLab