From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Excessive use of `eassert` Date: Tue, 23 Jan 2024 12:11:42 -0500 Message-ID: References: <83jzo5x0q8.fsf@gnu.org> <83sf2tv029.fsf@gnu.org> <811d5f03-fad4-47e1-b3fd-2f45229a5ee1@cs.ucla.edu> <1bcc2fc4-da9f-488e-b416-ef4443a3da65@cs.ucla.edu> 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="8059"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Alan Mackenzie , Eli Zaretskii , emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 23 18:12:44 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 1rSKKK-0001tY-DK for ged-emacs-devel@m.gmane-mx.org; Tue, 23 Jan 2024 18:12:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSKJe-0006ac-3h; Tue, 23 Jan 2024 12:12:02 -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 1rSKJY-0006a7-5s for emacs-devel@gnu.org; Tue, 23 Jan 2024 12:11:56 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSKJW-0001Fg-8B; Tue, 23 Jan 2024 12:11:55 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 9FB66441724; Tue, 23 Jan 2024 12:11:51 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1706029910; bh=IRGQGn6r0fsj6fZi3tv6ul90QcFmDOy11MQEpIsPI3s=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=pAAlsnjqBlafYVh42Qluej3doSgA4C0vTTWXt2KmXHKjWLjpsMeeZOTFuYcmUkrEO fV7QSkZ7bkdQRXt/30YE3ulL/JAIx1BKLZnxmZqSmt3xmnimz/9wjIgK3RNCMx+bgL UWS09mU3NqRRlLgn7e5XUQrlp+Bgeq5Yj43atyfRhLZ0/79LvvTrSgb9vcEIJVNFoR ajlpktxiORKPU8xklS0Do4DThX8ILTEkLxwpjj82w0jy5GQynnyhad20SDj6abP4xx 38wfoxxD7Z6TxYx+C2hu4IKxXauUECwNLo/wakVhJhVQr3Oxe33DXtpMjWQLNVuZoy +ZPkTgwOnEnJw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 06CD5441711; Tue, 23 Jan 2024 12:11:50 -0500 (EST) Original-Received: from alfajor (104-222-114-253.cpe.teksavvy.com [104.222.114.253]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C7F1C120A8E; Tue, 23 Jan 2024 12:11:49 -0500 (EST) In-Reply-To: (Paul Eggert's message of "Tue, 23 Jan 2024 00:15:03 -0800") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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:315259 Archived-At: BTW, gcc refuses to compile the current code on my i386 machine. It gives me loads of things like: lisp.h:620:28: error: expected expression before =E2=80=98{=E2=80=99 to= ken 620 | # define LISP_INITIALLY(w) {w} | ^ lisp.h:941:3: note: in expansion of macro =E2=80=98LISP_INITIALLY=E2=80= =99 941 | LISP_INITIALLY ((Lisp_Word) ((uintptr_t) (ptr) + LISP_WORD_TA= G (tag))) | ^~~~~~~~~~~~~~ lisp.h:415:3: note: in expansion of macro =E2=80=98TAG_PTR=E2=80=99 415 | TAG_PTR (Lisp_Symbol, (index) * sizeof *lispsym) | ^~~~~~~ lisp.h:482:37: note: in expansion of macro =E2=80=98lisp_h_builtin_lisp= _symbol=E2=80=99 482 | # define builtin_lisp_symbol(index) lisp_h_builtin_lisp_symbol = (index) | ^~~~~~~~~~~~~~~~~~~~~~~~~~ ./globals.h:7597:14: note: in expansion of macro =E2=80=98builtin_lisp_= symbol=E2=80=99 7597 | #define Qnil builtin_lisp_symbol (0) | ^~~~~~~~~~~~~~~~~~~ dispnew.c:6110:39: note: in expansion of macro =E2=80=98Qnil=E2=80=99 6110 | file =3D Fexpand_file_name (file, Qnil); | ^~~~ How 'bout the patch below. It gives the expected optimization under `-O2` and `-Og` and avoids duplicating the logic. It doesn't give the expected optimization under `-O0` because `-O0` doesn't do any inlining, but we've lived with that for a while so maybe that's OK (admittedly, I'm biased since I almost never use `-O0`). Stefan diff --git a/src/lisp.h b/src/lisp.h index 54d2f4d3dd1..74e4a78ae26 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -409,11 +409,7 @@ #define lisp_h_FIXNUMP(x) \ & ((1 << INTTYPEBITS) - 1))) #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float) #define lisp_h_NILP(x) BASE_EQ (x, Qnil) -/* Equivalent to "make_lisp_symbol (&lispsym[INDEX])", - and typically faster when compiling without optimization. */ -#define lisp_h_builtin_lisp_symbol(index) \ - TAG_PTR (Lisp_Symbol, (index) * sizeof *lispsym) -#define lisp_h_SET_SYMBOL_VAL(sym, v) \ +#define lisp_h_SET_SYMBOL_VAL(sym, v) \ (eassert ((sym)->u.s.redirect =3D=3D SYMBOL_PLAINVAL), \ (sym)->u.s.val.value =3D (v)) #define lisp_h_SYMBOL_CONSTANT_P(sym) \ @@ -479,7 +475,6 @@ #define lisp_h_XHASH(a) XUFIXNUM_RAW (a) # define FLOATP(x) lisp_h_FLOATP (x) # define FIXNUMP(x) lisp_h_FIXNUMP (x) # define NILP(x) lisp_h_NILP (x) -# define builtin_lisp_symbol(index) lisp_h_builtin_lisp_symbol (index) # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v) # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym) # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) @@ -1169,13 +1164,24 @@ XSYMBOL (Lisp_Object a) return XBARE_SYMBOL (a); } =20 +/* Apparently the `eassert` in `make_lisp_symbol` makes it non-inlinable + for GCC under -Og and even -O2, so use a non-checking version + for builtin symbols, so "apparent constants" like `Qnil` are indeed + compiled as constants. */ INLINE Lisp_Object -make_lisp_symbol (struct Lisp_Symbol *sym) +make__lisp_symbol (struct Lisp_Symbol *sym) { /* GCC 7 x86-64 generates faster code if lispsym is cast to char * rather than to intptr_t. */ char *symoffset =3D (char *) ((char *) sym - (char *) lispsym); Lisp_Object a =3D TAG_PTR (Lisp_Symbol, symoffset); + return a; +} + +INLINE Lisp_Object +make_lisp_symbol (struct Lisp_Symbol *sym) +{ + Lisp_Object a =3D make__lisp_symbol (sym); eassert (XBARE_SYMBOL (a) =3D=3D sym); return a; } @@ -1183,7 +1189,7 @@ make_lisp_symbol (struct Lisp_Symbol *sym) INLINE Lisp_Object (builtin_lisp_symbol) (int index) { - return lisp_h_builtin_lisp_symbol (index); + return make__lisp_symbol (&lispsym[index]); } =20 INLINE bool