From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: tags in the 3 lowest bits Date: 19 Nov 2003 14:15:43 -0500 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1069270167 29450 80.91.224.253 (19 Nov 2003 19:29:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 19 Nov 2003 19:29:27 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Nov 19 20:29:23 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AMY0x-0005cn-00 for ; Wed, 19 Nov 2003 20:29:23 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AMY0x-0000bN-00 for ; Wed, 19 Nov 2003 20:29:23 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AMYnf-0002tR-SM for emacs-devel@quimby.gnus.org; Wed, 19 Nov 2003 15:19:43 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AMYls-0002O9-GQ for emacs-devel@gnu.org; Wed, 19 Nov 2003 15:17:52 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AMYlI-0002Dk-Gm for emacs-devel@gnu.org; Wed, 19 Nov 2003 15:17:47 -0500 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AMYlH-0002Ct-UT for emacs-devel@gnu.org; Wed, 19 Nov 2003 15:17:16 -0500 Original-Received: from vor.iro.umontreal.ca (vor.iro.umontreal.ca [132.204.24.42]) by mercure.iro.umontreal.ca (8.12.9/8.12.9) with ESMTP id hAJJFhbj004184; Wed, 19 Nov 2003 14:15:43 -0500 Original-Received: by vor.iro.umontreal.ca (Postfix, from userid 20848) id 48D883C63E; Wed, 19 Nov 2003 14:15:43 -0500 (EST) Original-To: emacs-devel@gnu.org Original-Lines: 244 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-DIRO-MailScanner: Found to be clean X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:17925 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:17925 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 }; @@ -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);