From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.devel Subject: Re: master 2fd38e5c496: Simplify and speed up numeric comparisons Date: Sat, 27 Jul 2024 10:39:48 +0000 Message-ID: <5dD1_jV9BjDuodxn5EeX11fGdLsbe39GKXOjEJR9HI-m8dp5yPovuKCcpSe6S54I_kj4R_Qd9dPutcP3q9fWG16ohZV9Kq9te3Z7K60lWWw=@protonmail.com> References: <172207472641.7015.10274857436137393822@vcs2.savannah.gnu.org> <20240727100529.7278BC41F04@vcs2.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10000"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs Devel To: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 27 13:59:21 2024 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 1sXg52-0002Qi-Fi for ged-emacs-devel@m.gmane-mx.org; Sat, 27 Jul 2024 13:59:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sXg4L-0005xj-Uz; Sat, 27 Jul 2024 07:58:38 -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 1sXeqK-0005eM-Nx for emacs-devel@gnu.org; Sat, 27 Jul 2024 06:40:05 -0400 Original-Received: from mail-4316.protonmail.ch ([185.70.43.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sXeqI-0000hI-20 for emacs-devel@gnu.org; Sat, 27 Jul 2024 06:40:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1722076792; x=1722335992; bh=SVQBH+wzZb9jBLYKoH8XtEJ6ncxJ7abptRETZtYxsQ0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=FX8V/ECOHm2UE5fCpvCtyrD5hvI1YFoQz+mTa106IgncQxQ3+Q3uJyocmlYn3dc7z r91ll5Ocw1OaZhd0iGdIt1yGUGbHSl5fTpzoEVxXvfmv8yxZCMBTTsTXQf11QSuGDv L6n9qlVv1dx2N6X/zmkuKn/+Iq2WrGNAeNegX2lxMA1tX6pUTe2LpyLWFEUQKS7B3F fwPUVMBRGMpyJUTpvTbSQO2N4BCPjcm1uGLkAS494R1nzu9Dkz0e4w+61n6P1iSLbj QVNm3IHi3gHTTYBQQtNC6NerhSaRNtBpJsfmI4IlldqMwA5pOWwRdTnvSqVrc0UJQn ZRzR0Lvk6u2yA== In-Reply-To: <20240727100529.7278BC41F04@vcs2.savannah.gnu.org> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 08d2ca3d6bfdb54ee6afb48cce012b6da923d895 Received-SPF: pass client-ip=185.70.43.16; envelope-from=pipcet@protonmail.com; helo=mail-4316.protonmail.ch X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 27 Jul 2024 07:58:36 -0400 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:322122 Archived-At: On Saturday, July 27th, 2024 at 10:05, Mattias Engdeg=C3=A5rd via Mailing l= ist for Emacs changes wrote: > branch: master > commit 2fd38e5c496a2351a25e95df37a7900f6f80f22f > Author: Mattias Engdeg=C3=A5rd mattiase@acm.org >=20 > Commit: Mattias Engdeg=C3=A5rd mattiase@acm.org >=20 > Simplify and speed up numeric comparisons >=20 > This makes comparison functions (=3D, /=3D, <, <=3D, >, >=3D, min, max) q= uite > a bit faster (10-20 %). Bytecode ops on fixnums are not affected, > nor is `value<`. How was this measured? I would expect GCC to perform similar optimizations = with -flto, at least. IIUC, the "if" branches are currently optimized in or= der for byte-compiled code, though the fixnum <=3D> fixnum case should of c= ourse be moved after the fixnum <=3D> bignum case. > else > - i2 =3D mpz_sgn (*xbignum_val (num2)); > + { > + int sgn =3D mpz_sgn (*xbignum_val (num2)); > + eq =3D sgn =3D=3D 0; > + lt =3D sgn > 0; > + gt =3D sgn < 0; > + } As we use a fixnum for 0, mpz_sgn (*xbignum_val (num2)) can never be 0, IIU= C, here and in a few other places. This would simplify the code further (bu= t probably not be much of a speed up since we use bignums rarely), though "= eassume (!eq)" might be a better way to write it. I would have preferred arithcompare() to return 1.0, 0.0, -1.0, or NaN (or = another set of four values) for the four valid orderings, rather than using= three mutually-exclusive bits, but maybe I missed something about NaNs the= re. Are they mutually exclusive? If so, why do we test with "&" rather than= "=3D=3D" when we're testing a single bit? I have a very hypothetical objection, too: I have code somewhere around her= e that replaces floats by mpq_t big rationals, and for those, equality comp= arisons are much cheaper than ordering them is :-) Pip