diff options
| author | Paul Eggert | 2013-11-13 18:39:28 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-11-13 18:39:28 -0800 |
| commit | 2cf00efc1b0db0ddc26fa14239026dd2d12c7d59 (patch) | |
| tree | 1bd3fcc233230eb7e2ffdee78da9433b3915623e /src/lisp.h | |
| parent | d672ac3c611453c624948ed8cc2ced65cadc3400 (diff) | |
| download | emacs-2cf00efc1b0db0ddc26fa14239026dd2d12c7d59.tar.gz emacs-2cf00efc1b0db0ddc26fa14239026dd2d12c7d59.zip | |
Simplify, port and tune bool vector implementation.
* configure.ac (BITSIZEOF_SIZE_T, SIZEOF_SIZE_T): Remove.
* src/alloc.c (bool_vector_exact_payload_bytes)
(bool_vector_payload_bytes): Remove.
(bool_vector_fill): Return its argument.
* src/alloc.c (bool_vector_fill):
* src/lread.c (read1):
* src/print.c (print_object):
Simplify by using bool_vector_bytes.
* src/alloc.c (make_uninit_bool_vector):
New function, broken out from Fmake_bool_vector.
(Fmake_bool_vector): Use it. Use tail call.
(make_uninit_bool_vector, vector_nbytes): Simplify size calculations.
* src/data.c (BITS_PER_ULL): New constant.
(ULLONG_MAX, count_one_bits_ll): Fall back on long counterparts
if long long versions don't exist.
(shift_right_ull): New function.
(count_one_bits_word): New function, replacing popcount_bits_word
macro. Don't assume that bits_word is no wider than long long.
(count_one_bits_word, count_trailing_zero_bits):
Don't assume that bits_word is no wider than long long.
* src/data.c (bool_vector_binop_driver, bool_vector_not):
* src/fns.c (Fcopy_sequence):
* src/lread.c (read1):
Create an uninitialized destination, to avoid needless work.
(internal_equal): Simplify.
(Ffillarray): Prefer tail call.
* src/data.c (bool_vector_binop_driver): Don't assume bit vectors always
contain at least one word.
(bits_word_to_host_endian): Prefer if to #if. Don't assume
chars are narrower than ints.
* src/data.c (Fbool_vector_count_matches, Fbool_vector_count_matches_at):
* src/fns.c (Fcopy_sequence):
Simplify and tune.
* src/lisp.h (bits_word, BITS_WORD_MAX, BITS_PER_BITS_WORD):
Don't try to port to hosts where bits_word values have holes; the
code wouldn't work there anyway. Verify this assumption, though.
(bool_vector_bytes): New function.
(make_uninit_bool_vector): New decl.
(bool_vector_fill): Now returns Lisp_Object.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lisp.h b/src/lisp.h index 2b197cd32b1..72e5dad8ca3 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -92,16 +92,16 @@ enum { BOOL_VECTOR_BITS_PER_CHAR = | |||
| 92 | /* An unsigned integer type representing a fixed-length bit sequence, | 92 | /* An unsigned integer type representing a fixed-length bit sequence, |
| 93 | suitable for words in a Lisp bool vector. Normally it is size_t | 93 | suitable for words in a Lisp bool vector. Normally it is size_t |
| 94 | for speed, but it is unsigned char on weird platforms. */ | 94 | for speed, but it is unsigned char on weird platforms. */ |
| 95 | #if (BITSIZEOF_SIZE_T == CHAR_BIT * SIZEOF_SIZE_T \ | 95 | #if BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT |
| 96 | && BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT) | ||
| 97 | typedef size_t bits_word; | 96 | typedef size_t bits_word; |
| 98 | #define BITS_WORD_MAX SIZE_MAX | 97 | # define BITS_WORD_MAX SIZE_MAX |
| 99 | enum { BITS_PER_BITS_WORD = CHAR_BIT * sizeof (bits_word) }; | 98 | enum { BITS_PER_BITS_WORD = CHAR_BIT * sizeof (bits_word) }; |
| 100 | #else | 99 | #else |
| 101 | typedef unsigned char bits_word; | 100 | typedef unsigned char bits_word; |
| 102 | #define BITS_WORD_MAX ((1u << BOOL_VECTOR_BITS_PER_CHAR) - 1) | 101 | # define BITS_WORD_MAX ((1u << BOOL_VECTOR_BITS_PER_CHAR) - 1) |
| 103 | enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR }; | 102 | enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR }; |
| 104 | #endif | 103 | #endif |
| 104 | verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1); | ||
| 105 | 105 | ||
| 106 | /* Number of bits in some machine integer types. */ | 106 | /* Number of bits in some machine integer types. */ |
| 107 | enum | 107 | enum |
| @@ -1212,7 +1212,9 @@ struct Lisp_Bool_Vector | |||
| 1212 | struct vectorlike_header header; | 1212 | struct vectorlike_header header; |
| 1213 | /* This is the size in bits. */ | 1213 | /* This is the size in bits. */ |
| 1214 | EMACS_INT size; | 1214 | EMACS_INT size; |
| 1215 | /* This contains the actual bits, packed into bytes. */ | 1215 | /* The actual bits, packed into bytes. |
| 1216 | The bits are in little-endian order in the bytes, and | ||
| 1217 | the bytes are in little-endian order in the words. */ | ||
| 1216 | bits_word data[FLEXIBLE_ARRAY_MEMBER]; | 1218 | bits_word data[FLEXIBLE_ARRAY_MEMBER]; |
| 1217 | }; | 1219 | }; |
| 1218 | 1220 | ||
| @@ -1236,7 +1238,7 @@ bool_vector_uchar_data (Lisp_Object a) | |||
| 1236 | return (unsigned char *) bool_vector_data (a); | 1238 | return (unsigned char *) bool_vector_data (a); |
| 1237 | } | 1239 | } |
| 1238 | 1240 | ||
| 1239 | /* The number of data words in a bool vector with SIZE bits. */ | 1241 | /* The number of data words and bytes in a bool vector with SIZE bits. */ |
| 1240 | 1242 | ||
| 1241 | INLINE EMACS_INT | 1243 | INLINE EMACS_INT |
| 1242 | bool_vector_words (EMACS_INT size) | 1244 | bool_vector_words (EMACS_INT size) |
| @@ -1245,6 +1247,13 @@ bool_vector_words (EMACS_INT size) | |||
| 1245 | return (size + BITS_PER_BITS_WORD - 1) / BITS_PER_BITS_WORD; | 1247 | return (size + BITS_PER_BITS_WORD - 1) / BITS_PER_BITS_WORD; |
| 1246 | } | 1248 | } |
| 1247 | 1249 | ||
| 1250 | INLINE EMACS_INT | ||
| 1251 | bool_vector_bytes (EMACS_INT size) | ||
| 1252 | { | ||
| 1253 | eassume (0 <= size && size <= EMACS_INT_MAX - (BITS_PER_BITS_WORD - 1)); | ||
| 1254 | return (size + BOOL_VECTOR_BITS_PER_CHAR - 1) / BOOL_VECTOR_BITS_PER_CHAR; | ||
| 1255 | } | ||
| 1256 | |||
| 1248 | /* True if A's Ith bit is set. */ | 1257 | /* True if A's Ith bit is set. */ |
| 1249 | 1258 | ||
| 1250 | INLINE bool | 1259 | INLINE bool |
| @@ -3588,7 +3597,8 @@ list4i (EMACS_INT x, EMACS_INT y, EMACS_INT w, EMACS_INT h) | |||
| 3588 | make_number (w), make_number (h)); | 3597 | make_number (w), make_number (h)); |
| 3589 | } | 3598 | } |
| 3590 | 3599 | ||
| 3591 | extern void bool_vector_fill (Lisp_Object, Lisp_Object); | 3600 | extern Lisp_Object make_uninit_bool_vector (EMACS_INT); |
| 3601 | extern Lisp_Object bool_vector_fill (Lisp_Object, Lisp_Object); | ||
| 3592 | extern _Noreturn void string_overflow (void); | 3602 | extern _Noreturn void string_overflow (void); |
| 3593 | extern Lisp_Object make_string (const char *, ptrdiff_t); | 3603 | extern Lisp_Object make_string (const char *, ptrdiff_t); |
| 3594 | extern Lisp_Object make_formatted_string (char *, const char *, ...) | 3604 | extern Lisp_Object make_formatted_string (char *, const char *, ...) |