From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: bignum branch Date: Tue, 07 Aug 2018 18:25:16 -0600 Message-ID: <87tvo5k8lv.fsf@tromey.com> References: <87o9fbbw1t.fsf@tromey.com> <83wotxaiwi.fsf@gnu.org> <86k1pxmvmx.fsf@gmail.com> <87efg4a9xc.fsf@tromey.com> <87a7qr8cz7.fsf@tromey.com> <86tvoy3je9.fsf@gmail.com> <86bmb0vbxf.fsf@gmail.com> <87k1pnfcg1.fsf@tromey.com> <86sh4b1833.fsf@gmail.com> <861sbgz3dm.fsf@gmail.com> <83a7q4ufxp.fsf@gnu.org> <86in4resc8.fsf@gmail.com> <831sbfvl11.fsf@gnu.org> <8636vv7ohh.fsf@gmail.com> <83y3dntwsw.fsf@gnu.org> <83wot7tkdh.fsf@gnu.org> <87y3dnyzkl.fsf@tromey.com> <861sbegz37.fsf@gmail.com> <87k1p3ko6a.fsf@tromey.com> <86r2jamv0q.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1533687856 5129 195.159.176.226 (8 Aug 2018 00:24:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 8 Aug 2018 00:24:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Andy Moreton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 08 02:24:11 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fnCGo-0001Dd-Hm for ged-emacs-devel@m.gmane.org; Wed, 08 Aug 2018 02:24:10 +0200 Original-Received: from localhost ([::1]:41322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnCIt-0004OD-AJ for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2018 20:26:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnCIG-0004O0-8a for emacs-devel@gnu.org; Tue, 07 Aug 2018 20:25:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnCID-0005sK-0p for emacs-devel@gnu.org; Tue, 07 Aug 2018 20:25:40 -0400 Original-Received: from gateway31.websitewelcome.com ([192.185.143.31]:33066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnCIC-0005rf-NB for emacs-devel@gnu.org; Tue, 07 Aug 2018 20:25:36 -0400 Original-Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway31.websitewelcome.com (Postfix) with ESMTP id A5489D683F for ; Tue, 7 Aug 2018 19:25:34 -0500 (CDT) Original-Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id nCHtfBKiZbXuJnCI3faLu9; Tue, 07 Aug 2018 19:25:34 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=r3fRAmIuqEmua9H8zwbfEgs99lvtG/l8/FO0i92NXd8=; b=glm0/Rz5PNOnA1oS+8xZtvDh0/ eG/pebFjQtmaFIR3Kie66DpP+dQkD1rxxUOxW2LacGlqr755/uMcKkX9BHknN9ECaWPGLiDJJJ6wo a3qJtg20R7bK0RhSVc5iPZy0J; Original-Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:58802 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fnCHt-004OSC-3N; Tue, 07 Aug 2018 19:25:17 -0500 X-Attribution: Tom In-Reply-To: <86r2jamv0q.fsf@gmail.com> (Andy Moreton's message of "Tue, 07 Aug 2018 09:38:13 +0100") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.85.72 X-Source-L: No X-Exim-ID: 1fnCHt-004OSC-3N X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-85-72.hlrn.qwest.net (bapiya) [75.166.85.72]:58802 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 192.185.143.31 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228303 Archived-At: >>>>> "Andy" == Andy Moreton writes: Andy> This should use mpz_size. [...] Andy> Use a loop with mpz_getlimbn or mpz_limbs_read to do this with the API. Andy> mpz_roinit_n may be useful instead, using the low level APIs. Andy> See (info "(gmp) Integer Special Functions"). What do you think of this version? I tested it by hacking a bignum defconst into subr.el and then re-building. Tom diff --git a/src/alloc.c b/src/alloc.c index 512fdadfb2..edfb87e5cd 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5535,6 +5535,34 @@ make_pure_float (double num) return new; } +/* Value is a bignum object with value VALUE allocated from pure + space. */ + +static Lisp_Object +make_pure_bignum (struct Lisp_Bignum *value) +{ + Lisp_Object new; + size_t i, nlimbs = mpz_size (value->value); + size_t nbytes = nlimbs * sizeof (mp_limb_t); + mp_limb_t *pure_limbs; + mp_size_t new_size; + + struct Lisp_Bignum *b = pure_alloc (sizeof (struct Lisp_Bignum), Lisp_Misc); + b->type = Lisp_Misc_Bignum; + + pure_limbs = pure_alloc (nbytes, -1); + for (i = 0; i < nlimbs; ++i) + pure_limbs[i] = mpz_getlimbn (value->value, i); + + new_size = nlimbs; + if (mpz_sgn (value->value) < 0) + new_size = -new_size; + + mpz_roinit_n (b->value, pure_limbs, new_size); + + XSETMISC (new, b); + return new; +} /* Return a vector with room for LEN Lisp_Objects allocated from pure space. */ @@ -5676,6 +5704,8 @@ purecopy (Lisp_Object obj) /* Don't hash-cons it. */ return obj; } + else if (BIGNUMP (obj)) + obj = make_pure_bignum (XBIGNUM (obj)); else { AUTO_STRING (fmt, "Don't know how to purify: %S");