From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r107377: * src/lisp.h: Improve comment about USE_LSB_TAG. Date: Wed, 09 May 2012 10:56:54 -0700 Organization: UCLA Computer Science Department Message-ID: <4FAAAFE6.8080008@cs.ucla.edu> References: <4F459455.8070206@verizon.net> <4F45DC8C.9040607@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1336586243 5666 80.91.229.3 (9 May 2012 17:57:23 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 9 May 2012 17:57:23 +0000 (UTC) Cc: emacs-devel@gnu.org To: YAMAMOTO Mitsuharu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed May 09 19:57:22 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SSB8U-0005aX-HL for ged-emacs-devel@m.gmane.org; Wed, 09 May 2012 19:57:14 +0200 Original-Received: from localhost ([::1]:54470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSB8T-0004IW-S6 for ged-emacs-devel@m.gmane.org; Wed, 09 May 2012 13:57:13 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:41160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSB8N-0004I3-6i for emacs-devel@gnu.org; Wed, 09 May 2012 13:57:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSB8K-0003MB-QJ for emacs-devel@gnu.org; Wed, 09 May 2012 13:57:06 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:41422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSB8K-0003Ls-EI for emacs-devel@gnu.org; Wed, 09 May 2012 13:57:04 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 86E8239E8008; Wed, 9 May 2012 10:57:02 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HDESyWimGOnh; Wed, 9 May 2012 10:57:01 -0700 (PDT) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6D76939E8007; Wed, 9 May 2012 10:57:01 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 In-Reply-To: <4F45DC8C.9040607@verizon.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150404 Archived-At: On 02/22/2012 10:28 PM, Paul Eggert wrote: > On 02/22/2012 07:57 PM, YAMAMOTO Mitsuharu wrote: >> Does "untagging by subtraction instead of masking" improve the >> performance of USE_LSB_TAG in your platform? > > I'm sure it would, though I haven't measured it. > I'm surprised that this hasn't been implemented in Emacs already. I finally got around to measuring it, and it's a significant win on at least x86-64 and x86. I can't imagine a realistic platform where it would lose. So I installed the following patch on the trunk. Thanks again for reminding us about this. ====== Untag more efficiently if USE_LSB_TAG. This is based on a proposal by YAMAMOTO Mitsuharu in . For an admittedly artificial (nth 8000 longlist) benchmark on Fedora 15 x86-64, this yields a 25% CPU speedup. Also, it shrinks Emacs's overall text size by 1%. * lisp.h (XUNTAG): New macro. (XCONS, XVECTOR, XSTRING, XSYMBOL, XFLOAT, XMISC, XPROCESS, XWINDOW) (XTERMINAL, XSUBR, XBUFFER, XCHAR_TABLE, XSUB_CHAR_TABLE, XBOOL_VECTOR) (XSETTYPED_PSEUDOVECTOR, XHASH_TABLE, TYPED_PSEUDOVECTORP): Use it. * eval.c (Fautoload): * font.h (XFONT_SPEC, XFONT_ENTITY, XFONT_OBJECT): * frame.h (XFRAME): Use XUNTAG. === modified file 'src/eval.c' --- src/eval.c 2012-04-09 13:05:48 +0000 +++ src/eval.c 2012-05-09 17:17:30 +0000 @@ -2048,7 +2048,7 @@ We used to use 0 here, but that leads to accidental sharing in purecopy's hash-consing, so we use a (hopefully) unique integer instead. */ - docstring = make_number (XPNTR (function)); + docstring = make_number (XUNTAG (function, Lisp_Symbol)); return Ffset (function, Fpurecopy (list5 (Qautoload, file, docstring, interactive, type))); === modified file 'src/font.h' --- src/font.h 2012-01-19 07:21:25 +0000 +++ src/font.h 2012-05-09 17:17:30 +0000 @@ -469,11 +469,12 @@ } while (0) #define XFONT_SPEC(p) \ - (eassert (FONT_SPEC_P(p)), (struct font_spec *) XPNTR (p)) + (eassert (FONT_SPEC_P (p)), (struct font_spec *) XUNTAG (p, Lisp_Vectorlike)) #define XFONT_ENTITY(p) \ - (eassert (FONT_ENTITY_P(p)), (struct font_entity *) XPNTR (p)) + (eassert (FONT_ENTITY_P (p)), \ + (struct font_entity *) XUNTAG (p, Lisp_Vectorlike)) #define XFONT_OBJECT(p) \ - (eassert (FONT_OBJECT_P(p)), (struct font *) XPNTR (p)) + (eassert (FONT_OBJECT_P (p)), (struct font *) XUNTAG (p, Lisp_Vectorlike)) #define XSETFONT(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FONT)) /* Number of pt per inch (from the TeXbook). */ === modified file 'src/frame.h' --- src/frame.h 2012-01-19 07:21:25 +0000 +++ src/frame.h 2012-05-09 17:17:30 +0000 @@ -501,7 +501,8 @@ typedef struct frame *FRAME_PTR; -#define XFRAME(p) (eassert (FRAMEP(p)),(struct frame *) XPNTR (p)) +#define XFRAME(p) \ + (eassert (FRAMEP (p)), (struct frame *) XUNTAG (p, Lisp_Vectorlike)) #define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME)) /* Given a window, return its frame as a Lisp_Object. */ === modified file 'src/lisp.h' --- src/lisp.h 2012-05-04 23:16:47 +0000 +++ src/lisp.h 2012-05-09 17:49:17 +0000 @@ -475,6 +475,7 @@ (var) = (type) | (intptr_t) (ptr)) #define XPNTR(a) ((intptr_t) ((a) & ~TYPEMASK)) +#define XUNTAG(a, type) ((intptr_t) ((a) - (type))) #else /* not USE_LSB_TAG */ @@ -581,6 +582,13 @@ # define XSETFASTINT(a, b) (XSETINT (a, b)) #endif +/* Extract the pointer value of the Lisp object A, under the + assumption that A's type is TYPE. This is a fallback + implementation if nothing faster is available. */ +#ifndef XUNTAG +# define XUNTAG(a, type) XPNTR (a) +#endif + #define EQ(x, y) (XHASH (x) == XHASH (y)) /* Number of bits in a fixnum, including the sign bit. */ @@ -607,15 +615,20 @@ /* Extract a value or address from a Lisp_Object. */ -#define XCONS(a) (eassert (CONSP (a)), (struct Lisp_Cons *) XPNTR (a)) -#define XVECTOR(a) (eassert (VECTORLIKEP (a)), (struct Lisp_Vector *) XPNTR (a)) -#define XSTRING(a) (eassert (STRINGP (a)), (struct Lisp_String *) XPNTR (a)) -#define XSYMBOL(a) (eassert (SYMBOLP (a)), (struct Lisp_Symbol *) XPNTR (a)) -#define XFLOAT(a) (eassert (FLOATP (a)), (struct Lisp_Float *) XPNTR (a)) +#define XCONS(a) (eassert (CONSP (a)), \ + (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons)) +#define XVECTOR(a) (eassert (VECTORLIKEP (a)), \ + (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike)) +#define XSTRING(a) (eassert (STRINGP (a)), \ + (struct Lisp_String *) XUNTAG (a, Lisp_String)) +#define XSYMBOL(a) (eassert (SYMBOLP (a)), \ + (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol)) +#define XFLOAT(a) (eassert (FLOATP (a)), \ + (struct Lisp_Float *) XUNTAG (a, Lisp_Float)) /* Misc types. */ -#define XMISC(a) ((union Lisp_Misc *) XPNTR (a)) +#define XMISC(a) ((union Lisp_Misc *) XUNTAG (a, Lisp_Misc)) #define XMISCANY(a) (eassert (MISCP (a)), &(XMISC (a)->u_any)) #define XMISCTYPE(a) (XMISCANY (a)->type) #define XMARKER(a) (eassert (MARKERP (a)), &(XMISC (a)->u_marker)) @@ -635,14 +648,24 @@ /* Pseudovector types. */ -#define XPROCESS(a) (eassert (PROCESSP (a)), (struct Lisp_Process *) XPNTR (a)) -#define XWINDOW(a) (eassert (WINDOWP (a)), (struct window *) XPNTR (a)) -#define XTERMINAL(a) (eassert (TERMINALP (a)), (struct terminal *) XPNTR (a)) -#define XSUBR(a) (eassert (SUBRP (a)), (struct Lisp_Subr *) XPNTR (a)) -#define XBUFFER(a) (eassert (BUFFERP (a)), (struct buffer *) XPNTR (a)) -#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), (struct Lisp_Char_Table *) XPNTR (a)) -#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), (struct Lisp_Sub_Char_Table *) XPNTR (a)) -#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), (struct Lisp_Bool_Vector *) XPNTR (a)) +#define XPROCESS(a) (eassert (PROCESSP (a)), \ + (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike)) +#define XWINDOW(a) (eassert (WINDOWP (a)), \ + (struct window *) XUNTAG (a, Lisp_Vectorlike)) +#define XTERMINAL(a) (eassert (TERMINALP (a)), \ + (struct terminal *) XUNTAG (a, Lisp_Vectorlike)) +#define XSUBR(a) (eassert (SUBRP (a)), \ + (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike)) +#define XBUFFER(a) (eassert (BUFFERP (a)), \ + (struct buffer *) XUNTAG (a, Lisp_Vectorlike)) +#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \ + (struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike)) +#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \ + ((struct Lisp_Sub_Char_Table *) \ + XUNTAG (a, Lisp_Vectorlike))) +#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \ + ((struct Lisp_Bool_Vector *) \ + XUNTAG (a, Lisp_Vectorlike))) /* Construct a Lisp_Object from a value or address. */ @@ -669,7 +692,9 @@ /* The cast to struct vectorlike_header * avoids aliasing issues. */ #define XSETPSEUDOVECTOR(a, b, code) \ XSETTYPED_PSEUDOVECTOR(a, b, \ - ((struct vectorlike_header *) XPNTR (a))->size, \ + (((struct vectorlike_header *) \ + XUNTAG (a, Lisp_Vectorlike)) \ + ->size), \ code) #define XSETTYPED_PSEUDOVECTOR(a, b, size, code) \ (XSETVECTOR (a, b), \ @@ -1277,7 +1302,7 @@ #define XHASH_TABLE(OBJ) \ - ((struct Lisp_Hash_Table *) XPNTR (OBJ)) + ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike)) #define XSET_HASH_TABLE(VAR, PTR) \ (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE)) @@ -1735,7 +1760,7 @@ code is CODE. */ #define TYPED_PSEUDOVECTORP(x, t, code) \ (VECTORLIKEP (x) \ - && (((((struct t *) XPNTR (x))->size \ + && (((((struct t *) XUNTAG (x, Lisp_Vectorlike))->size \ & (PSEUDOVECTOR_FLAG | (code)))) \ == (PSEUDOVECTOR_FLAG | (code))))