From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: ash rewrite Date: Fri, 28 Jan 2005 09:48:25 +1100 Message-ID: <87oefaqyiu.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1106866592 6309 80.91.229.6 (27 Jan 2005 22:56:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 Jan 2005 22:56:32 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Jan 27 23:56:26 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CuIYr-0001PG-00 for ; Thu, 27 Jan 2005 23:56:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CuIlF-0004GD-Ak for guile-devel@m.gmane.org; Thu, 27 Jan 2005 18:09:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CuIkV-0003uW-6Y for guile-devel@gnu.org; Thu, 27 Jan 2005 18:08:27 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CuIkS-0003sZ-7f for guile-devel@gnu.org; Thu, 27 Jan 2005 18:08:24 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CuIkQ-0003qC-Ku for guile-devel@gnu.org; Thu, 27 Jan 2005 18:08:22 -0500 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CuIRJ-0008BB-4q for guile-devel@gnu.org; Thu, 27 Jan 2005 17:48:37 -0500 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-7.1) with ESMTP id j0RMmWHn012061 for ; Fri, 28 Jan 2005 09:48:32 +1100 Original-Received: from localhost (ppp2C4B.dyn.pacific.net.au [61.8.44.75]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-7.1) with ESMTP id j0RMmU8v005915 for ; Fri, 28 Jan 2005 09:48:31 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1CuIR7-0003GC-00; Fri, 28 Jan 2005 09:48:25 +1100 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4749 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4749 I checked in my rewrite of ash, it should be much faster than using integer-expt. { long bits_to_shift; bits_to_shift = scm_to_long (cnt); if (SCM_I_INUMP (n)) { long nn = SCM_I_INUM (n); if (bits_to_shift > 0) { /* Left shift of bits_to_shift >= SCM_I_FIXNUM_BIT-1 will always overflow a non-zero fixnum. For smaller shifts we check the bits going into positions above SCM_I_FIXNUM_BIT-1. If they're all 0s for nn>=0, or all 1s for nn<0 then there's no overflow. Those bits are "nn >> (SCM_I_FIXNUM_BIT-1 - bits_to_shift)". */ if (nn == 0) return n; if (bits_to_shift < SCM_I_FIXNUM_BIT-1 && ((unsigned long) (SCM_SRS (nn, (SCM_I_FIXNUM_BIT-1 - bits_to_shift)) + 1) <= 1)) { return SCM_I_MAKINUM (nn << bits_to_shift); } else { SCM result = scm_i_long2big (nn); mpz_mul_2exp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (result), bits_to_shift); return result; } } else { bits_to_shift = -bits_to_shift; if (bits_to_shift >= SCM_LONG_BIT) return (nn >= 0 ? SCM_I_MAKINUM (0) : SCM_I_MAKINUM(-1)); else return SCM_I_MAKINUM (SCM_SRS (nn, bits_to_shift)); } } else if (SCM_BIGP (n)) { SCM result; if (bits_to_shift == 0) return n; result = scm_i_mkbig (); if (bits_to_shift >= 0) { mpz_mul_2exp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (n), bits_to_shift); return result; } else { /* GMP doesn't have an fdiv_q_2exp variant returning just a long, so we have to allocate a bignum even if the result is going to be a fixnum. */ mpz_fdiv_q_2exp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (n), -bits_to_shift); return scm_i_normbig (result); } } else { SCM_WRONG_TYPE_ARG (SCM_ARG1, n); } } _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel