unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@protonmail.com>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Emacs Devel <emacs-devel@gnu.org>
Subject: Re: master 2fd38e5c496: Simplify and speed up numeric comparisons
Date: Sat, 27 Jul 2024 10:39:48 +0000	[thread overview]
Message-ID: <5dD1_jV9BjDuodxn5EeX11fGdLsbe39GKXOjEJR9HI-m8dp5yPovuKCcpSe6S54I_kj4R_Qd9dPutcP3q9fWG16ohZV9Kq9te3Z7K60lWWw=@protonmail.com> (raw)
In-Reply-To: <20240727100529.7278BC41F04@vcs2.savannah.gnu.org>

On Saturday, July 27th, 2024 at 10:05, Mattias Engdegård via Mailing list for Emacs changes <emacs-diffs@gnu.org> wrote:
> branch: master
> commit 2fd38e5c496a2351a25e95df37a7900f6f80f22f
> Author: Mattias Engdegård mattiase@acm.org
> 
> Commit: Mattias Engdegård mattiase@acm.org
> 
> Simplify and speed up numeric comparisons
> 
> This makes comparison functions (=, /=, <, <=, >, >=, min, max) quite
> 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 order for byte-compiled code, though the fixnum <=> fixnum case should of course be moved after the fixnum <=> bignum case.

> else
> - i2 = mpz_sgn (*xbignum_val (num2));
> + {
> +     int sgn = mpz_sgn (*xbignum_val (num2));
> +     eq = sgn == 0;
> +     lt = sgn > 0;
> +     gt = sgn < 0;
> + }

As we use a fixnum for 0, mpz_sgn (*xbignum_val (num2)) can never be 0, IIUC, here and in a few other places. This would simplify the code further (but 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 there. Are they mutually exclusive? If so, why do we test with "&" rather than "==" when we're testing a single bit?

I have a very hypothetical objection, too: I have code somewhere around here that replaces floats by mpq_t big rationals, and for those, equality comparisons are much cheaper than ordering them is :-)

Pip



       reply	other threads:[~2024-07-27 10:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <172207472641.7015.10274857436137393822@vcs2.savannah.gnu.org>
     [not found] ` <20240727100529.7278BC41F04@vcs2.savannah.gnu.org>
2024-07-27 10:39   ` Pip Cet [this message]
2024-07-27 12:07     ` master 2fd38e5c496: Simplify and speed up numeric comparisons Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='5dD1_jV9BjDuodxn5EeX11fGdLsbe39GKXOjEJR9HI-m8dp5yPovuKCcpSe6S54I_kj4R_Qd9dPutcP3q9fWG16ohZV9Kq9te3Z7K60lWWw=@protonmail.com' \
    --to=pipcet@protonmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).