From 6e3acd73b3c9505d179a1c7c576950aac0d05367 Mon Sep 17 00:00:00 2001
From: dtc <dtc>
Date: Thu, 13 Apr 2000 05:29:07 +0000
Subject: [PATCH] o Add a derive-type optimizer for INTEGER-LENGTH; based on a 
  contribution from Raymond Toy.

---
 compiler/srctran.lisp | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/compiler/srctran.lisp b/compiler/srctran.lisp
index 087a887ae..5b53f349e 100644
--- a/compiler/srctran.lisp
+++ b/compiler/srctran.lisp
@@ -5,7 +5,7 @@
 ;;; Carnegie Mellon University, and has been placed in the public domain.
 ;;;
 (ext:file-comment
-  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/srctran.lisp,v 1.97 2000/04/07 20:33:34 dtc Exp $")
+  "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/srctran.lisp,v 1.98 2000/04/13 05:29:07 dtc Exp $")
 ;;;
 ;;; **********************************************************************
 ;;;
@@ -2598,6 +2598,31 @@
   (frob logior)
   (frob logxor))
 
+(defoptimizer (integer-length derive-type) ((num))
+  (one-arg-derive-type
+   num
+   #'(lambda (type)
+       (when (and (numeric-type-p type)
+		  (eq (numeric-type-class type) 'integer))
+	 (let ((low (numeric-type-low type))
+	       (high (numeric-type-high type)))
+	   (cond ((and low (>= low 0))
+		  (make-numeric-type :class 'integer :complexp :real
+				     :low (integer-length low)
+				     :high (and high (integer-length high))))
+		 ((and high (<= high 0))
+		  (make-numeric-type :class 'integer :complexp :real
+				     :low (integer-length high)
+				     :high (and low (integer-length low))))
+		 ((and low (<= low 0) high (>= high 0))
+		  (make-numeric-type :class 'integer :complexp :real
+				     :low 0 :high (max (integer-length low)
+						       (integer-length high))))
+		 (t
+		  (make-numeric-type :class 'integer :complexp :real
+				     :low 0 :high nil))))))
+   #'integer-length))
+
 ) ; end progn
 
 
-- 
GitLab