From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Improving EQ Date: Wed, 11 Dec 2024 22:37:04 +0000 Message-ID: <87h679kftn.fsf@protonmail.com> Reply-To: Pip Cet 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="35069"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 12 06:26:12 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 1tLbiF-0008rS-Sl for ged-emacs-devel@m.gmane-mx.org; Thu, 12 Dec 2024 06:26:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLbhi-0000eV-2d; Thu, 12 Dec 2024 00:25:38 -0500 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 1tLVKW-0007Jc-B7 for emacs-devel@gnu.org; Wed, 11 Dec 2024 17:37:16 -0500 Original-Received: from mail-40131.protonmail.ch ([185.70.40.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLVKS-0006AN-GD for emacs-devel@gnu.org; Wed, 11 Dec 2024 17:37:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733956629; x=1734215829; bh=td1PBlGtUHAhXwVDGQD0gmNsEns5xs1gnPrTRMTDYqQ=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=bMLplGv7s/7K5iwqDoLZVxc3VQDJzMl+Uj6KfVXt7r5OZz2wn/9eVnDIXYr7mH0mS 3PQYwJ7nsWHI89Y7r0khSwMqogY/Zz8AdxUIaGBGz17bQ4gDpSg1GzgtIjxmcNjYu/ hQmi3v54eVQBXrC0Z2bR6JcTP/OtiNgRDIjvLwo57LUJPvMUcwpyf2gK6y+GU0+NHO DcKUhkCs7t+KNjwCVtegqyfi+UjfY4m0M1wNgsVGK5Of650DNLNT1pBWUrbwKRQ5Rp JvO0sgc7hGzagduN6KZpH4LbTUSTP99Vc05/5OM2dIRIgDxIaxVEg5g35fdyH/huyi XYsoo+1XORFWg== Feedback-ID: 112775352:user:proton X-Pm-Message-ID: fcf8abdb218a14bbdc93cb7776900a68da50e023 Received-SPF: pass client-ip=185.70.40.131; envelope-from=pipcet@protonmail.com; helo=mail-40131.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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: Thu, 12 Dec 2024 00:25:35 -0500 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:326398 Archived-At: I looked at the "new" code generated for our EQ macro, and decided that a fix was in order. I'm therefore sending a first proposal to explain what I think should be done, and some numbers. This patch: * moves the "slow path" of EQ into a NO_INLINE function * exits early if the arguments to EQ are actually BASE_EQ * returns quickly (after a single memory access which cannot be avoided until we fix our tagging scheme to distinguish exotic objects from ordinary ones) when symbols_with_pos_enabled isn't true. The effect on the code size of the stripped emacs binary is small, but significant: 8906336 bytes instead of 8955488 bytes on this machine. (The effect on the code size of the emacs binary with debugging information is much larger, reducing it from 32182000 bytes to 31125832 bytes on this system.) There is no effect on the size of the .pdmp file, which is expected. What's missing here is a benchmark, but unless there's a really nasty surprise when that happens, I'm quite confident that we can improve the code here. The proposed code doesn't use __builtin_expect anymore. I've deliberately written slow_eq so it returns the same value as EQ, even if the slow code path is disabled. Pip commit 2c807f7320bcb9654e0f148d64c92053b1a47b42 (HEAD -> faster-eq) Author: Pip Cet Date: Wed Dec 11 22:31:07 2024 +0000 Change EQ to move slow code path into a separate function =20 * src/data.c (slow_eq): New function. * src/lisp.h (EQ): Call it. diff --git a/src/data.c b/src/data.c index 66cf34c1e60..5ee383d2f48 100644 --- a/src/data.c +++ b/src/data.c @@ -162,6 +162,15 @@ circular_list (Lisp_Object list) =0C /* Data type predicates. */ =20 +/* NO_INLINE to avoid excessive code growth when LTO is in use. */ +NO_INLINE bool slow_eq (Lisp_Object x, Lisp_Object y) +{ + return BASE_EQ ((symbols_with_pos_enabled && SYMBOL_WITH_POS_P (x) ? +=09=09 XSYMBOL_WITH_POS_SYM (x) : x), +=09=09 (symbols_with_pos_enabled && SYMBOL_WITH_POS_P (y) ? +=09=09 XSYMBOL_WITH_POS_SYM (y) : y)); +} + DEFUN ("eq", Feq, Seq, 2, 2, 0, doc: /* Return t if the two args are the same Lisp object. */ attributes: const) diff --git a/src/lisp.h b/src/lisp.h index 832a1755c04..64d4835a499 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -618,6 +618,7 @@ #define ENUM_BF(TYPE) enum TYPE extern Lisp_Object default_value (Lisp_Object symbol); extern void defalias (Lisp_Object symbol, Lisp_Object definition); extern char *fixnum_to_string (EMACS_INT number, char *buffer, char *end); +extern bool slow_eq (Lisp_Object x, Lisp_Object y); =20 =20 /* Defined in emacs.c. */ @@ -1353,10 +1354,12 @@ make_fixed_natnum (EMACS_INT n) INLINE bool EQ (Lisp_Object x, Lisp_Object y) { - return BASE_EQ ((__builtin_expect (symbols_with_pos_enabled, false) -=09=09 && SYMBOL_WITH_POS_P (x) ? XSYMBOL_WITH_POS_SYM (x) : x), -=09=09 (__builtin_expect (symbols_with_pos_enabled, false) -=09=09 && SYMBOL_WITH_POS_P (y) ? XSYMBOL_WITH_POS_SYM (y) : y)); + if (BASE_EQ (x, y)) + return true; + else if (!symbols_with_pos_enabled) + return false; + else + return slow_eq (x, y); } =20 INLINE intmax_t