emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Untagging by subtraction instead of masking on USE_LSB_TAG


From: YAMAMOTO Mitsuharu
Subject: Untagging by subtraction instead of masking on USE_LSB_TAG
Date: Mon, 28 Jan 2008 11:07:28 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/23.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

Sorry if this has already been discussed before.

On USE_LSB_TAG environments, untagging of Lisp_Object can be performed
by subtracting a small number instead of bit masking.  The subtraction
enables us to optimize the typical sequence of untagging ->
dereference -> struct-member-access into a single instruction.  Below
is the result of gcc -Os in PowerPC with masking (left) and
subtraction (right).

  _cons_to_long:                  _cons_to_long:
          andi. r0,r3,7                   andi. r0,r3,7
          srawi r0,r3,3                   srawi r0,r3,3
          beq cr0,L592                    beq cr0,L592
          rlwinm r2,r3,0,0,28
          lwz r9,4(r2)                    lwz r9,-1(r3)
          lwz r3,0(r2)                    lwz r3,-5(r3)
          rlwinm r0,r9,0,29,31            rlwinm r0,r9,0,29,31
          cmpwi cr7,r0,5                  cmpwi cr7,r0,5
          bne cr7,L593                    bne cr7,L593
          rlwinm r2,r9,0,0,28
          lwz r9,0(r2)                    lwz r9,-5(r9)
  L593:                           L593:
          rlwinm r2,r3,13,0,15            rlwinm r2,r3,13,0,15
          srawi r0,r9,3                   srawi r0,r9,3
          or r0,r2,r0                     or r0,r2,r0
  L592:                           L592:
          mr r3,r0                        mr r3,r0
          blr                             blr

This would make sense if the latency of load/store does not depend on
its displacement (I'm not sure if that is the case in general).
Comments?

                                     YAMAMOTO Mitsuharu
                                address@hidden

Index: src/lisp.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/lisp.h,v
retrieving revision 1.605
diff -c -r1.605 lisp.h
*** src/lisp.h  13 Jan 2008 22:08:06 -0000      1.605
--- src/lisp.h  28 Jan 2008 00:18:18 -0000
***************
*** 397,402 ****
--- 397,403 ----
  #define XSETFASTINT(a, b) ((a) = make_number (b))
  
  #define XPNTR(a) ((EMACS_INT) ((a) & ~TYPEMASK))
+ #define XUNTAG(a, type) ((EMACS_UINT) (a) - (type))
  
  #else  /* not USE_LSB_TAG */
  
***************
*** 509,514 ****
--- 510,516 ----
  #define XPNTR(a) ((EMACS_INT) XUINT (a))
  #endif
  #endif /* not HAVE_SHM */
+ #define XUNTAG(a, type) XPNTR (a)
  #endif /* no XPNTR */
  
  /* Largest and smallest representable fixnum values.  These are the C
***************
*** 528,542 ****
  
  /* Extract a value or address from a Lisp_Object.  */
  
! #define XCONS(a) (eassert (GC_CONSP(a)),(struct Lisp_Cons *) XPNTR(a))
! #define XVECTOR(a) (eassert (GC_VECTORLIKEP(a)),(struct Lisp_Vector *) 
XPNTR(a))
! #define XSTRING(a) (eassert (GC_STRINGP(a)),(struct Lisp_String *) XPNTR(a))
! #define XSYMBOL(a) (eassert (GC_SYMBOLP(a)),(struct Lisp_Symbol *) XPNTR(a))
! #define XFLOAT(a) (eassert (GC_FLOATP(a)),(struct Lisp_Float *) XPNTR(a))
  
  /* Misc types.  */
  
! #define XMISC(a)   ((union Lisp_Misc *) XPNTR(a))
  #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))
--- 530,549 ----
  
  /* Extract a value or address from a Lisp_Object.  */
  
! #define XCONS(a) (eassert (GC_CONSP(a)), \
!                 (struct Lisp_Cons *) XUNTAG(a, Lisp_Cons))
! #define XVECTOR(a) (eassert (GC_VECTORLIKEP(a)), \
!                   (struct Lisp_Vector *) XUNTAG(a, Lisp_Vectorlike))
! #define XSTRING(a) (eassert (GC_STRINGP(a)), \
!                   (struct Lisp_String *) XUNTAG(a, Lisp_String))
! #define XSYMBOL(a) (eassert (GC_SYMBOLP(a)), \
!                   (struct Lisp_Symbol *) XUNTAG(a, Lisp_Symbol))
! #define XFLOAT(a) (eassert (GC_FLOATP(a)), \
!                  (struct Lisp_Float *) XUNTAG(a, Lisp_Float))
  
  /* Misc types.  */
  
! #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))
***************
*** 554,566 ****
  
  /* Pseudovector types.  */
  
! #define XPROCESS(a) (eassert (GC_PROCESSP(a)),(struct Lisp_Process *) 
XPNTR(a))
! #define XWINDOW(a) (eassert (GC_WINDOWP(a)),(struct window *) XPNTR(a))
! #define XTERMINAL(a) (eassert (GC_TERMINALP(a)),(struct terminal *) XPNTR(a))
! #define XSUBR(a) (eassert (GC_SUBRP(a)),(struct Lisp_Subr *) XPNTR(a))
! #define XBUFFER(a) (eassert (GC_BUFFERP(a)),(struct buffer *) XPNTR(a))
! #define XCHAR_TABLE(a) (eassert (GC_CHAR_TABLE_P (a)), (struct 
Lisp_Char_Table *) XPNTR(a))
! #define XBOOL_VECTOR(a) (eassert (GC_BOOL_VECTOR_P (a)), (struct 
Lisp_Bool_Vector *) XPNTR(a))
  
  /* Construct a Lisp_Object from a value or address.  */
  
--- 561,580 ----
  
  /* Pseudovector types.  */
  
! #define XPROCESS(a) (eassert (GC_PROCESSP(a)), \
!                    (struct Lisp_Process *) XUNTAG(a, Lisp_Vectorlike))
! #define XWINDOW(a) (eassert (GC_WINDOWP(a)), \
!                   (struct window *) XUNTAG(a, Lisp_Vectorlike))
! #define XTERMINAL(a) (eassert (GC_TERMINALP(a)), \
!                     (struct terminal *) XUNTAG(a, Lisp_Vectorlike))
! #define XSUBR(a) (eassert (GC_SUBRP(a)), \
!                 (struct Lisp_Subr *) XUNTAG(a, Lisp_Vectorlike))
! #define XBUFFER(a) (eassert (GC_BUFFERP(a)), \
!                   (struct buffer *) XUNTAG(a, Lisp_Vectorlike))
! #define XCHAR_TABLE(a) (eassert (GC_CHAR_TABLE_P (a)), \
!                       (struct Lisp_Char_Table *) XUNTAG(a, Lisp_Vectorlike))
! #define XBOOL_VECTOR(a) (eassert (GC_BOOL_VECTOR_P (a)), \
!                        (struct Lisp_Bool_Vector *) XUNTAG(a, Lisp_Vectorlike))
  
  /* Construct a Lisp_Object from a value or address.  */
  
***************
*** 1089,1095 ****
  
  
  #define XHASH_TABLE(OBJ) \
!      ((struct Lisp_Hash_Table *) XPNTR (OBJ))
  
  #define XSET_HASH_TABLE(VAR, PTR) \
       (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
--- 1103,1109 ----
  
  
  #define XHASH_TABLE(OBJ) \
!      ((struct Lisp_Hash_Table *) XUNTAG(OBJ, Lisp_Vectorlike))
  
  #define XSET_HASH_TABLE(VAR, PTR) \
       (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
Index: src/frame.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/frame.h,v
retrieving revision 1.131
diff -c -r1.131 frame.h
*** src/frame.h 8 Jan 2008 20:44:17 -0000       1.131
--- src/frame.h 28 Jan 2008 00:18:18 -0000
***************
*** 475,481 ****
  
  typedef struct frame *FRAME_PTR;
  
! #define XFRAME(p) (eassert (GC_FRAMEP(p)),(struct frame *) XPNTR (p))
  #define XSETFRAME(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_FRAME))
  
  /* Given a window, return its frame as a Lisp_Object.  */
--- 475,482 ----
  
  typedef struct frame *FRAME_PTR;
  
! #define XFRAME(p) (eassert (GC_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.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]