From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#65491: [PATCH] Improve performance allocating vectors Date: Tue, 19 Sep 2023 15:28:41 +0200 Message-ID: References: <6B2EDD07-AAEB-40E8-B369-F634296BD3D9@gmail.com> <83v8cagkqv.fsf@gnu.org> <83ttrugkj2.fsf@gnu.org> <83r0mygi4y.fsf@gnu.org> <8af6fa1c-4873-bd6e-e896-ab5bb8d012a2@cs.ucla.edu> <83led5gyxa.fsf@gnu.org> <83o7i0g4i9.fsf@gnu.org> <83jzsog35g.fsf@gnu.org> <95C2D44B-BA1B-47F5-8279-B3A3B8F7EB39@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_F041D8D6-60C4-40A7-8567-C866BBB314B6" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40157"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65491@debbugs.gnu.org, Paul Eggert , monnier@iro.umontreal.ca To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 19 15:30:23 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1qiao3-000AGE-Ba for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Sep 2023 15:30:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiane-0004wc-Bl; Tue, 19 Sep 2023 09:29:58 -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 1qiana-0004vw-RE for bug-gnu-emacs@gnu.org; Tue, 19 Sep 2023 09:29:54 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiana-0005L4-J8 for bug-gnu-emacs@gnu.org; Tue, 19 Sep 2023 09:29:54 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qianj-0006YB-Cf for bug-gnu-emacs@gnu.org; Tue, 19 Sep 2023 09:30:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Sep 2023 13:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65491 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65491-submit@debbugs.gnu.org id=B65491.169513014425058 (code B ref 65491); Tue, 19 Sep 2023 13:30:03 +0000 Original-Received: (at 65491) by debbugs.gnu.org; 19 Sep 2023 13:29:04 +0000 Original-Received: from localhost ([127.0.0.1]:55632 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qiamm-0006W6-Cu for submit@debbugs.gnu.org; Tue, 19 Sep 2023 09:29:04 -0400 Original-Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]:49162) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qiamh-0006VN-8n for 65491@debbugs.gnu.org; Tue, 19 Sep 2023 09:28:59 -0400 Original-Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-5031ccf004cso3168083e87.2 for <65491@debbugs.gnu.org>; Tue, 19 Sep 2023 06:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695130124; x=1695734924; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=Wn5dotgV6xxJRxCnGMa4Nb8eHBkKFDx7cSfFFfiJ+08=; b=mlMlt3xQR1Iu+kQO3QwN+eqjYlP9ynJeQWaiZ1Xw0xlYrDvKC50Y0O0rt4UzsXIhNw SaT4DXgg+yXzWCOjxicpVyr9bxrHQWemdiGm17OvD3bGVLvp2cY2j38dmHfdPDs25M/G xM4wcJm8tlJHtf+PCkuN7kHRfg+GMDD/WRDe7q92yj1gucPTAw4bmzZM/pymTH8OhCtX JUTUcBgfSv65XyWsAUkgvKOOdsqt5C5wneROmXWd37Cy9/pwYtRs7jDFPh8dTMsVAlFC X0eC2rTXCoh9ZdKn/6UPQM1HHqi0SqgBEd34PuQK4B8buzrHUPBBVQPkXW6AiTd0xqq5 M+wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695130124; x=1695734924; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Wn5dotgV6xxJRxCnGMa4Nb8eHBkKFDx7cSfFFfiJ+08=; b=eQ6qIk0rNlgPl5QrYxRPSKPDwhGxx/p/XuNF8XdkxkMyWmkRcoj1p1T/W8UGiYt+AS xdotx7IdnHUzYO9OaV5XROIdgG8h4Dyz6Kw6bNT7huCkwP39fgQ5JIgVkPzVloF38Gpt 09nF4wq32xrQ84bOk8DAQGrln1nuG6myTkRugRpEMfoL9/DdKRkw8wPvgP852ibXdn+M EvuLCiLWy9AnINgdcmuF0yhYXhmXtV3bMH3/JMEtB5chw9GF5gZMBPkpfdBOzrh0L/YS 9Tama3qC4ARtIytsK9jmOeHfH8wxxQdO6v6LYpgNss2/JslP26ZyV3v4hDHPlBNC0vFC xAZA== X-Gm-Message-State: AOJu0YxMJmcfhsubG9JQJp+DXwSX6nMQvEUQOJRg11RZyQX1ULyAmlxi e51WkYL0flSCBT23TKxGNPU= X-Google-Smtp-Source: AGHT+IHU4bc+A/R6QhUbivfVivrbUpTJgI0SwmvjH8VDpzKzRZrfrCa0rooOvJyDvxf7R+PF96C4qg== X-Received: by 2002:ac2:5f79:0:b0:500:8fc1:8aba with SMTP id c25-20020ac25f79000000b005008fc18abamr9375772lfc.26.1695130124039; Tue, 19 Sep 2023 06:28:44 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id x27-20020ac259db000000b0050326307ed8sm498959lfn.102.2023.09.19.06.28.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2023 06:28:42 -0700 (PDT) In-Reply-To: <95C2D44B-BA1B-47F5-8279-B3A3B8F7EB39@gmail.com> X-Mailer: Apple Mail (2.3654.120.0.1.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:270875 Archived-At: --Apple-Mail=_F041D8D6-60C4-40A7-8567-C866BBB314B6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > The conversion at the other end, TAG_PTR, suffers from the same = potential problem but in reverse, which is perhaps less obvious to the = casual C programmer but nevertheless a danger of the same kind, so we'd = better do something about it as well. I'll be back with a proposed = patch. Here it is. Very straightforward: just flip a cast and remove unused = definitions. --Apple-Mail=_F041D8D6-60C4-40A7-8567-C866BBB314B6 Content-Disposition: attachment; filename=0001-Don-t-use-pointer-arithmetic-for-pointer-tagging-bug.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Don-t-use-pointer-arithmetic-for-pointer-tagging-bug.patch" Content-Transfer-Encoding: quoted-printable =46rom=209072db6ca24df50dc8dc66cd50ef638b8aac8a1b=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Mon,=2018=20Sep=202023=2019:16:05=20+0200=0A= Subject:=20[PATCH]=20Don't=20use=20pointer=20arithmetic=20for=20pointer=20= tagging=20(bug#65491)=0A=0AThis=20makes=20for=20safer=20code=20when=20= tagging=20null=20pointers=20in=20particular,=0Asince=20pointer=20= arithmetic=20on=20NULL=20is=20undefined=20and=20therefore=20can=20be=0A= assumed,=20by=20the=20compiler,=20not=20to=20occur.=0A=0A*=20src/lisp.h=20= (untagged_ptr):=20Remove.=0A(TAG_PTR):=20Cast=20to=20uintptr_t=20instead=20= of=20untagged_ptr.=0A---=0A=20src/lisp.h=20|=2015=20+++------------=0A=20= 1=20file=20changed,=203=20insertions(+),=2012=20deletions(-)=0A=0Adiff=20= --git=20a/src/lisp.h=20b/src/lisp.h=0Aindex=20de6746f1c07..f0eea0c1f28=20= 100644=0A---=20a/src/lisp.h=0A+++=20b/src/lisp.h=0A@@=20-920,20=20= +920,11=20@@=20#define=20DEFUN_ARGS_7=09(Lisp_Object,=20Lisp_Object,=20= Lisp_Object,=20Lisp_Object,=20\=0A=20#define=20DEFUN_ARGS_8=09= (Lisp_Object,=20Lisp_Object,=20Lisp_Object,=20Lisp_Object,=20\=0A=20=09=09= =09=20Lisp_Object,=20Lisp_Object,=20Lisp_Object,=20Lisp_Object)=0A=20=0A= -/*=20untagged_ptr=20represents=20a=20pointer=20before=20tagging,=20and=20= Lisp_Word_tag=0A-=20=20=20contains=20a=20possibly-shifted=20tag=20to=20= be=20added=20to=20an=20untagged_ptr=20to=0A-=20=20=20convert=20it=20to=20= a=20Lisp_Word.=20=20*/=0A+/*=20Lisp_Word_tag=20is=20big=20enough=20for=20= a=20possibly-shifted=20tag,=20to=20be=0A+=20=20=20added=20to=20a=20= pointer=20value=20for=20conversion=20to=20a=20Lisp_Word.=20=20*/=0A=20= #if=20LISP_WORDS_ARE_POINTERS=0A-/*=20untagged_ptr=20is=20a=20pointer=20= so=20that=20the=20compiler=20knows=20that=20TAG_PTR=0A-=20=20=20yields=20= a=20pointer.=20=20It=20is=20char=20*=20so=20that=20adding=20a=20tag=20= uses=20simple=0A-=20=20=20machine=20addition.=20=20*/=0A-typedef=20char=20= *untagged_ptr;=0A=20typedef=20uintptr_t=20Lisp_Word_tag;=0A=20#else=0A= -/*=20untagged_ptr=20is=20an=20unsigned=20integer=20instead=20of=20a=20= pointer,=20so=20that=0A-=20=20=20it=20can=20be=20added=20to=20the=20= possibly-wider=20Lisp_Word_tag=20type=20without=0A-=20=20=20losing=20= information.=20=20*/=0A-typedef=20uintptr_t=20untagged_ptr;=0A=20typedef=20= EMACS_UINT=20Lisp_Word_tag;=0A=20#endif=0A=20=0A@@=20-943,7=20+934,7=20= @@=20#define=20LISP_WORD_TAG(tag)=20\=0A=20=0A=20/*=20An=20initializer=20= for=20a=20Lisp_Object=20that=20contains=20TAG=20along=20with=20PTR.=20=20= */=0A=20#define=20TAG_PTR(tag,=20ptr)=20\=0A-=20=20LISP_INITIALLY=20= ((Lisp_Word)=20((untagged_ptr)=20(ptr)=20+=20LISP_WORD_TAG=20(tag)))=0A+=20= =20LISP_INITIALLY=20((Lisp_Word)=20((uintptr_t)=20(ptr)=20+=20= LISP_WORD_TAG=20(tag)))=0A=20=0A=20/*=20LISPSYM_INITIALLY=20(Qfoo)=20is=20= equivalent=20to=20Qfoo=20except=20it=20is=0A=20=20=20=20designed=20for=20= use=20as=20an=20initializer,=20even=20for=20a=20constant=20initializer.=20= =20*/=0A--=20=0A2.32.0=20(Apple=20Git-132)=0A=0A= --Apple-Mail=_F041D8D6-60C4-40A7-8567-C866BBB314B6 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_F041D8D6-60C4-40A7-8567-C866BBB314B6--