From 9c23779a9d8474af16cfadb1a08d2c05ececcbec Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 28 Apr 2014 09:59:41 -0700 Subject: [PATCH] Use bits_word for gcmarkbits. * alloc.c (struct cons_block, struct float_block): On 64-bit hosts, bits_word is typically a tad more efficient for mark bits than unsigned is, so use bits_word. All uses changed. * lisp.h (BITS_PER_INT): Remove; no longer used. --- src/ChangeLog | 6 ++++++ src/alloc.c | 38 +++++++++++++++++++------------------- src/lisp.h | 3 +-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 90223d6d103..619dce7a731 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2014-04-28 Paul Eggert + Use bits_word for gcmarkbits. + * alloc.c (struct cons_block, struct float_block): On 64-bit hosts, + bits_word is typically a tad more efficient for mark bits than + unsigned is, so use bits_word. All uses changed. + * lisp.h (BITS_PER_INT): Remove; no longer used. + Avoid undefined behavior in signed left shift. This ports to GCC 4.9.0 with -fsanitize=undefined. * alloc.c (bool_vector_fill, SETMARKBIT, UNSETMARKBIT): diff --git a/src/alloc.c b/src/alloc.c index 32d3333cea8..7159d1fa747 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2332,21 +2332,21 @@ make_formatted_string (char *buf, const char *format, ...) #define FLOAT_BLOCK_SIZE \ (((BLOCK_BYTES - sizeof (struct float_block *) \ /* The compiler might add padding at the end. */ \ - - (sizeof (struct Lisp_Float) - sizeof (int))) * CHAR_BIT) \ + - (sizeof (struct Lisp_Float) - sizeof (bits_word))) * CHAR_BIT) \ / (sizeof (struct Lisp_Float) * CHAR_BIT + 1)) #define GETMARKBIT(block,n) \ - (((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ - >> ((n) % (sizeof (unsigned) * CHAR_BIT))) \ + (((block)->gcmarkbits[(n) / BITS_PER_BITS_WORD] \ + >> ((n) % BITS_PER_BITS_WORD)) \ & 1) #define SETMARKBIT(block,n) \ - ((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ - |= 1u << ((n) % (sizeof (unsigned) * CHAR_BIT))) + ((block)->gcmarkbits[(n) / BITS_PER_BITS_WORD] \ + |= (bits_word) 1 << ((n) % BITS_PER_BITS_WORD)) #define UNSETMARKBIT(block,n) \ - ((block)->gcmarkbits[(n) / (sizeof (unsigned) * CHAR_BIT)] \ - &= ~(1u << ((n) % (sizeof (unsigned) * CHAR_BIT)))) + ((block)->gcmarkbits[(n) / BITS_PER_BITS_WORD] \ + &= ~((bits_word) 1 << ((n) % BITS_PER_BITS_WORD))) #define FLOAT_BLOCK(fptr) \ ((struct float_block *) (((uintptr_t) (fptr)) & ~(BLOCK_ALIGN - 1))) @@ -2358,7 +2358,7 @@ struct float_block { /* Place `floats' at the beginning, to ease up FLOAT_INDEX's job. */ struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; - unsigned gcmarkbits[1 + FLOAT_BLOCK_SIZE / (sizeof (unsigned) * CHAR_BIT)]; + bits_word gcmarkbits[1 + FLOAT_BLOCK_SIZE / BITS_PER_BITS_WORD]; struct float_block *next; }; @@ -2439,7 +2439,7 @@ make_float (double float_value) #define CONS_BLOCK_SIZE \ (((BLOCK_BYTES - sizeof (struct cons_block *) \ /* The compiler might add padding at the end. */ \ - - (sizeof (struct Lisp_Cons) - sizeof (int))) * CHAR_BIT) \ + - (sizeof (struct Lisp_Cons) - sizeof (bits_word))) * CHAR_BIT) \ / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1)) #define CONS_BLOCK(fptr) \ @@ -2452,7 +2452,7 @@ struct cons_block { /* Place `conses' at the beginning, to ease up CONS_INDEX's job. */ struct Lisp_Cons conses[CONS_BLOCK_SIZE]; - unsigned gcmarkbits[1 + CONS_BLOCK_SIZE / (sizeof (unsigned) * CHAR_BIT)]; + bits_word gcmarkbits[1 + CONS_BLOCK_SIZE / BITS_PER_BITS_WORD]; struct cons_block *next; }; @@ -6436,27 +6436,27 @@ NO_INLINE /* For better stack traces */ static void sweep_conses (void) { - register struct cons_block *cblk; + struct cons_block *cblk; struct cons_block **cprev = &cons_block; - register int lim = cons_block_index; + int lim = cons_block_index; EMACS_INT num_free = 0, num_used = 0; cons_free_list = 0; for (cblk = cons_block; cblk; cblk = *cprev) { - register int i = 0; + int i = 0; int this_free = 0; - int ilim = (lim + BITS_PER_INT - 1) / BITS_PER_INT; + int ilim = (lim + BITS_PER_BITS_WORD - 1) / BITS_PER_BITS_WORD; /* Scan the mark bits an int at a time. */ for (i = 0; i < ilim; i++) { - if (cblk->gcmarkbits[i] == -1) + if (cblk->gcmarkbits[i] == BITS_WORD_MAX) { /* Fast path - all cons cells for this int are marked. */ cblk->gcmarkbits[i] = 0; - num_used += BITS_PER_INT; + num_used += BITS_PER_BITS_WORD; } else { @@ -6464,10 +6464,10 @@ sweep_conses (void) Find which ones, and free them. */ int start, pos, stop; - start = i * BITS_PER_INT; + start = i * BITS_PER_BITS_WORD; stop = lim - start; - if (stop > BITS_PER_INT) - stop = BITS_PER_INT; + if (stop > BITS_PER_BITS_WORD) + stop = BITS_PER_BITS_WORD; stop += start; for (pos = start; pos < stop; pos++) diff --git a/src/lisp.h b/src/lisp.h index 5e0f141cc9c..f47fb0c2a24 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -115,7 +115,7 @@ enum { BOOL_VECTOR_BITS_PER_CHAR = }; /* An unsigned integer type representing a fixed-length bit sequence, - suitable for words in a Lisp bool vector. Normally it is size_t + suitable for bool vector words, GC mark bits, etc. Normally it is size_t for speed, but it is unsigned char on weird platforms. */ #if BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT typedef size_t bits_word; @@ -133,7 +133,6 @@ enum { BITS_PER_CHAR = CHAR_BIT, BITS_PER_SHORT = CHAR_BIT * sizeof (short), - BITS_PER_INT = CHAR_BIT * sizeof (int), BITS_PER_LONG = CHAR_BIT * sizeof (long int), BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT) }; -- 2.39.5