From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Gerd_M=c3=b6llmann?= Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Re: Bignum performance (was: Shrinking the C core) Date: Mon, 14 Aug 2023 11:28:21 +0200 Message-ID: <2d419e12-9239-de3e-47d0-38815a00025f@gmail.com> References: <87bkfartof.fsf@localhost> <175cf474-29c8-a482-072e-0de784ac59e8@gmail.com> <87o7jaqc31.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37625"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Cc: incal@dataswamp.org, emacs-devel To: Ihor Radchenko Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Aug 14 11:28:43 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qVTsR-0009bh-NC for ged-emacs-devel@m.gmane-mx.org; Mon, 14 Aug 2023 11:28:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVTsE-0005dD-0X; Mon, 14 Aug 2023 05:28:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVTsB-0005Wp-Tf for emacs-devel@gnu.org; Mon, 14 Aug 2023 05:28:27 -0400 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVTs9-0006ep-Ud for emacs-devel@gnu.org; Mon, 14 Aug 2023 05:28:27 -0400 Original-Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-99c1f6f3884so560547366b.0 for ; Mon, 14 Aug 2023 02:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692005303; x=1692610103; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=s4Ipq3IPuxDsCOxMuYoyugn2ab6R0T1Vf6IU0cs+3nw=; b=bYP+gAmwxDHqpbBPAHEE25qvWqJmN78z+V40qEYnYe2P2MwE7oA29xoZExyzPeH376 lKa+zG2CahsRLOEQyx/5Kpi3xXyf2L/aA4tEiMBbg4jGErr74UFveh0WeTDYf9ZQHubc wsqbFrAO4KV3+fYvoVs9vCgbE+CXuAGgyIiuzyuSv9LOjalBlDM2poEa/gpnwFABW0xR Q5YTGxbUDhHNekCkSBi8R/9Ia1/cw/9XT0dZ7VKpMxiA0XSxa+UiPVjHZUFv+VaQD1ah Ku6En26l3VbJbgCRlbZp2znnHOr7E8JE9MZy9KlVFkE+ToJn3QMCsjBlW31cdtTmHijk Q4MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692005303; x=1692610103; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s4Ipq3IPuxDsCOxMuYoyugn2ab6R0T1Vf6IU0cs+3nw=; b=hAhJhlQpEAKDea1oLcuabByNM8xCT/vEYB3Igcz+tGR/CnBnA5hBYRKjtVF8ro6Rk6 jdmdy4fdJxc2xCwmnHXV/BeQui3eH8J+ZcHt1LnBIlwuVL2COjap0+l63/FgdaSflwMH 1j8uuihGuve+MKr/JQeyVRgz/wRUyDnAr+OUifJoAAuLW3kzgpEGNODjN0B2y884BWSY 3LTMsgfAcFILZVFIPnOq/B1EXbVpB9X5u8zfmDjlIkQg2oq1bBXVqorKW1fhfXHdpUEl n0Gxfg+iQlIJKTiuRe1VGxeSgjQCAxiA42kmPOI7TzsUw7eVORtinaKUkjrZj809eYDa iPqA== X-Gm-Message-State: AOJu0YwHxV5meRsUp3Z5eJ5GG3Nxcz2ULqqZkKXFJ6dvCX6tMYUSf2jx 7YZR0e5r3Qmkjg1D1zctoJ8= X-Google-Smtp-Source: AGHT+IE9Y/0FpxG9BRcUTAI4xQ/hy79E6V6zK7FD/SKVo68tm/zdI9V3VDkJnur9+zfTRtfsZqAQzw== X-Received: by 2002:a17:906:1010:b0:989:450:e567 with SMTP id 16-20020a170906101000b009890450e567mr8707306ejm.65.1692005303103; Mon, 14 Aug 2023 02:28:23 -0700 (PDT) Original-Received: from [192.168.178.21] (p4fe3a81e.dip0.t-ipconnect.de. [79.227.168.30]) by smtp.gmail.com with ESMTPSA id cw13-20020a170906c78d00b00992e265495csm5420291ejb.212.2023.08.14.02.28.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Aug 2023 02:28:22 -0700 (PDT) Content-Language: en-US In-Reply-To: <87o7jaqc31.fsf@localhost> Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=gerd.moellmann@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -64 X-Spam_score: -6.5 X-Spam_bar: ------ X-Spam_report: (-6.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-4.359, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:308716 Archived-At: On 14.08.23 10:09, Ihor Radchenko wrote: > Gerd Möllmann writes: > >> Hm, then maybe we can look at the disassembly of then benchmark in SBCL? >> Not that in the end the compiler is so smart that it optimizes a lot >> of stuff simply away because it can prove that the result of the >> computations cannot possibly be observed? > > Sorry, but I do not know how to do it. Not familiar with CL. > Ok. I used the code from https://dataswamp.org/~incal/cl/fib.cl/fib.cl. And the first thing that stares at me in this function: (defun fib (reps num) (declare (optimize speed (safety 0) (debug 0))) (let ((z 0)) (declare (type (unsigned-byte 53) reps num z)) (dotimes (r reps) (let*((p1 1) (p2 1)) (dotimes (i (- num 2)) (setf z (+ p1 p2) p2 p1 p1 z)))) z)) is the declaration (unsigned-byte 53). The declaration means we are lying to the compiler because Z gets bigger than 53 bits eventually. And all bets are off because of the OPTIMIZE declaration. The result is that everything is done in fixnums on 64-bit machines. ; disassembly for FIB ; Size: 92 bytes. Origin: #x700530086C ; FIB ; 6C: 030080D2 MOVZ NL3, #0 ; 70: 040080D2 MOVZ NL4, #0 ; 74: 0E000014 B L3 ; 78: L0: 410080D2 MOVZ NL1, #2 ; 7C: E20301AA MOV NL2, NL1 ; 80: EB030CAA MOV R1, R2 ; 84: 651100D1 SUB NL5, R1, #4 ; 88: 000080D2 MOVZ NL0, #0 ; 8C: 05000014 B L2 ; 90: L1: 2300028B ADD NL3, NL1, NL2 ; 94: E20301AA MOV NL2, NL1 ; 98: E10303AA MOV NL1, NL3 ; 9C: 00080091 ADD NL0, NL0, #2 ; A0: L2: 1F0005EB CMP NL0, NL5 ; A4: 6BFFFF54 BLT L1 ; A8: 84080091 ADD NL4, NL4, #2 ; AC: L3: 9F000AEB CMP NL4, R0 ; B0: 4BFEFF54 BLT L0 ; B4: EA0303AA MOV R0, NL3 ; B8: FB031AAA MOV CSP, CFP ; BC: 5A7B40A9 LDP CFP, LR, [CFP] ; C0: BF0300F1 CMP NULL, #0 ; C4: C0035FD6 RET Tada!