all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tags in the 3 lowest bits
@ 2003-11-19 19:15 Stefan Monnier
  2003-11-20  0:28 ` Kim F. Storm
  0 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2003-11-19 19:15 UTC (permalink / raw)


Here is my proposed patch which adds a new macro USE_LSB_TAG:
if the macro is undefined, we behave as before, otherwise we
use the lowest 3 bits of words for tags.

Additionally to the above patch we will need to #define USE_LSB_TAG
when appropriate: it seems that we'll have to put it into the
[sm]/*.h files.

Any objection to my installing this patch ?


        Stefan


PS: The point of putting the tag in the LSB is that we can then use
    the whole address space, which can be important on some systems
    such as FreeBSD.


Index: lread.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/lread.c,v
retrieving revision 1.318
diff -u -r1.318 lread.c
--- lread.c	1 Sep 2003 15:45:56 -0000	1.318
+++ lread.c	19 Nov 2003 19:09:00 -0000
@@ -3407,6 +3407,16 @@
      struct Lisp_Subr *sname;
 {
   Lisp_Object sym;
+#ifdef USE_LSB_TAG
+  /* Make sure the object has multiple-of-8 alignment.  */
+  if (XTYPE (sname) != 0)
+    {
+      struct Lisp_Subr *old_sname = sname;
+      sname = (struct Lisp_Subr *) (4 + (char*) sname);
+      memmove (sname, old_sname, sizeof (*sname) - 4);
+      eassert (XTYPE (sname) == 0);
+    }
+#endif
   sym = intern (sname->symbol_name);
   XSETSUBR (XSYMBOL (sym)->function, sname);
 }
Index: lisp.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/lisp.h,v
retrieving revision 1.472
diff -u -r1.472 lisp.h
--- lisp.h	17 Nov 2003 23:29:30 -0000	1.472
+++ lisp.h	19 Nov 2003 19:09:00 -0000
@@ -68,9 +68,6 @@
 			   : die ((msg), __FILE__, __LINE__)),	\
 			  0)
 
-/* Let's get some compile-time checking too.  */
-#undef NO_UNION_TYPE
-
 #else
 
 /* Produce same side effects and result, but don't complain.  */
@@ -299,6 +296,26 @@
 
 #ifdef NO_UNION_TYPE
 
+#ifdef USE_LSB_TAG
+
+#define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1)
+#define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK))
+#define XINT(a) (((EMACS_INT) (a)) >> GCTYPEBITS)
+#define XUINT(a) (((EMACS_UINT) (a)) >> GCTYPEBITS)
+#define XSET(var, type, ptr)				\
+  (eassert ((((EMACS_UINT) (ptr)) & TYPEMASK) == 0),	\
+   (var) = ((EMACS_INT) (type)) + ((EMACS_INT) (ptr)))
+#define make_number(N) (((EMACS_INT) (N)) << GCTYPEBITS)
+
+#define XPNTR(a) ((a) & (((EMACS_INT) -1) << GCTYPEBITS))
+
+/* For integers known to be positive, XFASTINT used to provide fast retrieval
+   and XSETFASTINT fast storage.  */
+#define XFASTINT(a) XINT (a)
+#define XSETFASTINT(a, b) ((a) = make_number (b))
+
+#else  /* not USE_LSB_TAG */
+
 #define VALMASK ((((EMACS_INT) 1) << VALBITS) - 1)
 
 /* One need to override this if there must be high bits set in data space
@@ -337,6 +354,8 @@
 #define make_number(N)		\
   ((((EMACS_INT) (N)) & VALMASK) | ((EMACS_INT) Lisp_Int) << VALBITS)
 
+#endif /* not USE_LSB_TAG */
+
 #define EQ(x, y) ((x) == (y))
 
 #else /* not NO_UNION_TYPE */
@@ -384,6 +403,7 @@
 #define XGCTYPE(a) XTYPE (a)
 #endif
 
+/* In the USE_LSB_TAG case, XPNTR is defined further above.  */
 #ifndef XPNTR
 #ifdef HAVE_SHM
 /* In this representation, data is found in two widely separated segments.  */
@@ -752,6 +772,13 @@
     char *symbol_name;
     char *prompt;
     char *doc;
+#ifdef USE_LSB_TAG
+    /* Lisp_Subrs are statically allocated, so we cannot rely on malloc
+       giving us a multiple-of-8 alignment.  Instead, we assume that we
+       get a multiple-of-4 alignment, and we memmove the object by 4 bytes
+       if needed.  The memmove is in lread.c:defsubr.  */
+    char padding[4];
+#endif
   };
 
 \f
@@ -1150,6 +1177,13 @@
     unsigned gcmarkbit : 1;
     int spacer : 15;
     union Lisp_Misc *chain;
+#ifdef USE_LSB_TAG
+    /* Try to make sure that sizeof(Lisp_Misc) is a multiple of 8.
+       This assumes that Lisp_Marker is the largest of the alternatives and
+       that Lisp_Intfwd has the same size as Lisp_Free without padding.  */
+    char padding[8 * ((sizeof (struct Lisp_Marker) - 1) / 8 + 1)
+		 - sizeof (struct Lisp_Intfwd)];
+#endif
   };
 
 /* To get the type field of a union Lisp_Misc, use XMISCTYPE.
Index: alloc.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/alloc.c,v
retrieving revision 1.328
diff -u -r1.328 alloc.c
--- alloc.c	18 Nov 2003 00:39:13 -0000	1.328
+++ alloc.c	19 Nov 2003 19:09:00 -0000
@@ -598,6 +598,7 @@
 
   val = (void *) malloc (nbytes);
 
+#ifndef USE_LSB_TAG
   /* If the memory just allocated cannot be addressed thru a Lisp
      object's pointer, and it needs to be,
      that's equivalent to running out of memory.  */
@@ -612,6 +613,7 @@
 	  val = 0;
 	}
     }
+#endif
 
 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK
   if (val && type != MEM_TYPE_NON_LISP)
@@ -772,6 +774,7 @@
       mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
 #endif
 
+#ifndef USE_LSB_TAG
       /* If the memory just allocated cannot be addressed thru a Lisp
 	 object's pointer, and it needs to be, that's equivalent to
 	 running out of memory.  */
@@ -788,6 +791,7 @@
 	      memory_full ();
 	    }
 	}
+#endif
 
       /* Initialize the blocks and put them on the free list.
 	 Is `base' was not properly aligned, we can't use the last block.  */
@@ -1343,8 +1347,8 @@
 
 struct string_block
 {
-  struct string_block *next;
   struct Lisp_String strings[STRING_BLOCK_SIZE];
+  struct string_block *next;
 };
 
 /* Head and tail of the list of sblock structures holding Lisp string
@@ -2749,8 +2753,8 @@
 
 struct symbol_block
 {
-  struct symbol_block *next;
   struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE];
+  struct symbol_block *next;
 };
 
 /* Current symbol block and index of first unused Lisp_Symbol
@@ -2841,8 +2845,8 @@
 
 struct marker_block
 {
-  struct marker_block *next;
   union Lisp_Misc markers[MARKER_BLOCK_SIZE];
+  struct marker_block *next;
 };
 
 struct marker_block *marker_block;
@@ -3422,6 +3426,7 @@
       /* P must point to the start of a Lisp_String structure, and it
 	 must not be on the free-list.  */
       return (offset >= 0
+	      && offset < (STRING_BLOCK_SIZE * sizeof b->strings[0])
 	      && offset % sizeof b->strings[0] == 0
 	      && ((struct Lisp_String *) p)->data != NULL);
     }
@@ -3476,6 +3481,7 @@
 	 and not be on the free-list.  */
       return (offset >= 0
 	      && offset % sizeof b->symbols[0] == 0
+	      && offset < (SYMBOL_BLOCK_SIZE * sizeof b->symbols[0])
 	      && (b != symbol_block
 		  || offset / sizeof b->symbols[0] < symbol_block_index)
 	      && !EQ (((struct Lisp_Symbol *) p)->function, Vdead));
@@ -3529,6 +3535,7 @@
 	 and not be on the free-list.  */
       return (offset >= 0
 	      && offset % sizeof b->markers[0] == 0
+	      && offset < (MARKER_BLOCK_SIZE * sizeof b->markers[0])
 	      && (b != marker_block
 		  || offset / sizeof b->markers[0] < marker_block_index)
 	      && ((union Lisp_Misc *) p)->u_marker.type != Lisp_Misc_Free);
@@ -4063,6 +4070,10 @@
      int type;
 {
   POINTER_TYPE *result;
+#ifdef USE_LSB_TAG
+  /* Ensure a minimum of 3 bits for tags. */
+  size_t alignment = max (8, sizeof (EMACS_INT));
+#else
   size_t alignment = sizeof (EMACS_INT);
 
   /* Give Lisp_Floats an extra alignment.  */
@@ -4074,6 +4085,7 @@
       alignment = sizeof (struct Lisp_Float);
 #endif
     }
+#endif
 
  again:
   result = ALIGN (purebeg + pure_bytes_used, alignment);

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-11-24  0:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-19 19:15 tags in the 3 lowest bits Stefan Monnier
2003-11-20  0:28 ` Kim F. Storm
2003-11-19 23:32   ` Miles Bader
2003-11-20  5:14   ` Stefan Monnier
2003-11-20 10:21     ` Kim F. Storm
2003-11-20  9:31       ` Miles Bader
2003-11-20 10:49         ` Kim F. Storm
2003-11-22 21:18           ` Richard Stallman
2003-11-20 14:52       ` Stefan Monnier
2003-11-21 15:32         ` Stefan Monnier
2003-11-22  0:31           ` Kim F. Storm
2003-11-21 23:56             ` David Kastrup
2003-11-22  1:45               ` Kim F. Storm
2003-11-24  0:08             ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.