From 7be68de5d25998e7d15aaab800c40cad48eac846 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Sep 2013 21:28:06 -0700 Subject: [PATCH] Some minor cleanups of recently-added bool vector code. * conf_post.h (assume): Always return void. Use lint version only if GCC and MSC versions don't apply. * conf_post.h (assume): * data.c (USC_MSC_POPCOUNT, count_trailing_zero_bits): Depend on _MSC_VER, not __MSC_VER, for consistency with the rest of Emacs. * data.c (bool_vector_spare_mask, popcount_size_t_generic) (popcount_size_t_msc, popcount_size_t_gcc, popcount_size_t) (bool_vector_binop_driver, count_trailing_zero_bits) (size_t_to_host_endian): Now static, not static inline; the latter isn't needed with modern compilers and doesn't work with older compilers anyway. --- src/ChangeLog | 14 ++++++++++ src/alloc.c | 15 +++++------ src/conf_post.h | 19 +++++++------- src/data.c | 81 +++++++++++++++++++++++++-------------------------------- src/lisp.h | 9 +++---- src/xdisp.c | 3 +-- 6 files changed, 69 insertions(+), 72 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5676d3e8b9a..303eb4f9176 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,19 @@ 2013-09-24 Paul Eggert + Some minor cleanups of recently-added bool vector code. + * conf_post.h (assume): Always return void. Use lint version + only if GCC and MSC versions don't apply. + * conf_post.h (assume): + * data.c (USC_MSC_POPCOUNT, count_trailing_zero_bits): + Depend on _MSC_VER, not __MSC_VER, for consistency with + the rest of Emacs. + * data.c (bool_vector_spare_mask, popcount_size_t_generic) + (popcount_size_t_msc, popcount_size_t_gcc, popcount_size_t) + (bool_vector_binop_driver, count_trailing_zero_bits) + (size_t_to_host_endian): Now static, not static inline; + the latter isn't needed with modern compilers and doesn't + work with older compilers anyway. + * alloc.c (valgrind_p): Use bool for boolean. 2013-09-23 Dmitry Antipov diff --git a/src/alloc.c b/src/alloc.c index 02742c4cf4a..e380d66cb1b 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -981,7 +981,7 @@ struct ablocks #define ABLOCKS_BASE(abase) (abase) #else #define ABLOCKS_BASE(abase) \ - (1 & (intptr_t) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1]) + (1 & (intptr_t) ABLOCKS_BUSY (abase) ? abase : ((void **)abase)[-1]) #endif /* The list of free ablock. */ @@ -1036,7 +1036,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type) aligned = (base == abase); if (!aligned) - ((void**)abase)[-1] = base; + ((void **) abase)[-1] = base; #ifdef DOUG_LEA_MALLOC /* Back to a reasonable maximum of mmap'ed areas. */ @@ -2016,10 +2016,9 @@ INIT must be an integer that represents a character. */) verify (sizeof (size_t) * CHAR_BIT == BITS_PER_SIZE_T); verify ((BITS_PER_SIZE_T & (BITS_PER_SIZE_T - 1)) == 0); -static -ptrdiff_t +static ptrdiff_t bool_vector_payload_bytes (ptrdiff_t nr_bits, - ptrdiff_t* exact_needed_bytes_out) + ptrdiff_t *exact_needed_bytes_out) { ptrdiff_t exact_needed_bytes; ptrdiff_t needed_bytes; @@ -2068,7 +2067,7 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */) + total_payload_bytes), word_size) / word_size; - p = (struct Lisp_Bool_Vector* ) allocate_vector (needed_elements); + p = (struct Lisp_Bool_Vector *) allocate_vector (needed_elements); XSETVECTOR (val, p); XSETPVECTYPESIZE (XVECTOR (val), PVEC_BOOL_VECTOR, 0, 0); @@ -2617,9 +2616,9 @@ verify ((VECTOR_BLOCK_SIZE % roundup_size) == 0); verify (VECTOR_BLOCK_SIZE <= (1 << PSEUDOVECTOR_SIZE_BITS)); /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at compile time. */ -#define vroundup_ct(x) ROUNDUP((size_t)(x), roundup_size) +#define vroundup_ct(x) ROUNDUP ((size_t) (x), roundup_size) /* Round up X to nearest mult-of-ROUNDUP_SIZE --- use at runtime. */ -#define vroundup(x) (assume((x) >= 0), vroundup_ct(x)) +#define vroundup(x) (assume ((x) >= 0), vroundup_ct (x)) /* Rounding helps to maintain alignment constraints if USE_LSB_TAG. */ diff --git a/src/conf_post.h b/src/conf_post.h index 3c348d0705b..0786bdfeb33 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -252,18 +252,17 @@ extern void _DebPrint (const char *fmt, ...); # define __has_builtin(x) 0 #endif -/* assume(cond) tells the compiler (and lint) that a certain condition - * will always hold, and that it should optimize (or check) accordingly. */ -#if defined lint +/* Tell the compiler (and lint) that COND will always hold, and that + it should optimize (or check) accordingly. */ +#if (__has_builtin (__builtin_unreachable) \ + || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || __GNUC__ > 4) +# define assume(cond) ((cond) ? (void) 0 : __builtin_unreachable ()) +#elif defined _MSC_VER +# define assume(cond) __assume (cond) +#elif defined lint # define assume(cond) ((cond) ? (void) 0 : abort ()) -#elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || __GNUC__ > 4 -# define assume(cond) ((cond) || (__builtin_unreachable(), 0)) -#elif defined (__clang__) && __has_builtin (__builtin_unreachable) -# define assume(cond) ((cond) || (__builtin_unreachable(), 0)) -#elif defined __MSC_VER -# define assume(cond) __assume ((cond)) #else -# define assume(cond) (0 && (cond)) +# define assume(cond) ((void) (0 && (cond))) #endif /* Use this to suppress gcc's `...may be used before initialized' warnings. */ diff --git a/src/data.c b/src/data.c index 5a05e0652ad..82cfd74cd0f 100644 --- a/src/data.c +++ b/src/data.c @@ -617,7 +617,7 @@ global value outside of any lexical scope. */) struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); if (blv->fwd) /* In set_internal, we un-forward vars when their value is - set to Qunbound. */ + set to Qunbound. */ return Qt; else { @@ -628,7 +628,7 @@ global value outside of any lexical scope. */) } case SYMBOL_FORWARDED: /* In set_internal, we un-forward vars when their value is - set to Qunbound. */ + set to Qunbound. */ return Qt; default: emacs_abort (); } @@ -1996,7 +1996,7 @@ If the current binding is global (the default), the value is nil. */) } /* This code is disabled now that we use the selected frame to return - keyboard-local-values. */ + keyboard-local-values. */ #if 0 extern struct terminal *get_terminal (Lisp_Object display, int); @@ -2963,15 +2963,14 @@ lowercase l) for small endian machines. */) always allocate bool vectors with at least one size_t of storage so that we don't have to special-case empty bit vectors. */ -static inline -size_t +static size_t bool_vector_spare_mask (ptrdiff_t nr_bits) { eassert_and_assume (nr_bits > 0); return (((size_t) 1) << (nr_bits % BITS_PER_SIZE_T)) - 1; } -#if __MSC_VER >= 1500 && (defined _M_IX86 || defined _M_X64) +#if _MSC_VER >= 1500 && (defined _M_IX86 || defined _M_X64) # define USE_MSC_POPCOUNT #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # define USE_GCC_POPCOUNT @@ -2984,8 +2983,7 @@ bool_vector_spare_mask (ptrdiff_t nr_bits) #endif #ifdef NEED_GENERIC_POPCOUNT -static inline -unsigned int +static unsigned int popcount_size_t_generic (size_t val) { unsigned short j; @@ -2999,8 +2997,7 @@ popcount_size_t_generic (size_t val) #endif #ifdef USE_MSC_POPCOUNT -static inline -unsigned int +static unsigned int popcount_size_t_msc (size_t val) { unsigned int count; @@ -3045,8 +3042,7 @@ popcount_size_t_msc (size_t val) #endif /* USE_MSC_POPCOUNT */ #ifdef USE_GCC_POPCOUNT -static inline -unsigned int +static unsigned int popcount_size_t_gcc (size_t val) { # if BITS_PER_SIZE_T == 64 @@ -3057,9 +3053,8 @@ popcount_size_t_gcc (size_t val) } #endif /* USE_GCC_POPCOUNT */ -static inline -unsigned int -popcount_size_t(size_t val) +static unsigned int +popcount_size_t (size_t val) { #if defined USE_MSC_POPCOUNT return popcount_size_t_msc (val); @@ -3067,7 +3062,7 @@ popcount_size_t(size_t val) return popcount_size_t_gcc (val); #else return popcount_size_t_generic (val); - #endif +#endif } enum bool_vector_op { bool_vector_exclusive_or, @@ -3076,8 +3071,7 @@ enum bool_vector_op { bool_vector_exclusive_or, bool_vector_set_difference, bool_vector_subsetp }; -static inline -Lisp_Object +static Lisp_Object bool_vector_binop_driver (Lisp_Object op1, Lisp_Object op2, Lisp_Object dest, @@ -3108,11 +3102,11 @@ bool_vector_binop_driver (Lisp_Object op1, } eassert_and_assume (nr_bits >= 0); - nr_words = ROUNDUP(nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; - - adata = (size_t*) XBOOL_VECTOR (dest)->data; - bdata = (size_t*) XBOOL_VECTOR (op1)->data; - cdata = (size_t*) XBOOL_VECTOR (op2)->data; + nr_words = ROUNDUP (nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; + + adata = (size_t *) XBOOL_VECTOR (dest)->data; + bdata = (size_t *) XBOOL_VECTOR (op1)->data; + cdata = (size_t *) XBOOL_VECTOR (op2)->data; i = 0; do { @@ -3132,16 +3126,16 @@ bool_vector_binop_driver (Lisp_Object op1, if (op != bool_vector_subsetp) adata[i] = mword; - i += 1; + i++; } while (i < nr_words); + return changed ? dest : Qnil; } /* Compute the number of trailing zero bits in val. If val is zero, return the number of bits in val. */ -static inline -unsigned int +static unsigned int count_trailing_zero_bits (size_t val) { if (val == 0) @@ -3151,7 +3145,7 @@ count_trailing_zero_bits (size_t val) return __builtin_ctzll (val); #elif defined USE_GCC_POPCOUNT && BITS_PER_SIZE_T == 32 return __builtin_ctz (val); -#elif __MSC_VER && BITS_PER_SIZE_T == 64 +#elif _MSC_VER && BITS_PER_SIZE_T == 64 # pragma intrinsic _BitScanForward64 { /* No support test needed: support since 386. */ @@ -3159,7 +3153,7 @@ count_trailing_zero_bits (size_t val) _BitScanForward64 (&result, val); return (unsigned int) result; } -#elif __MSC_VER && BITS_PER_SIZE_T == 32 +#elif _MSC_VER && BITS_PER_SIZE_T == 32 # pragma intrinsic _BitScanForward { /* No support test needed: support since 386. */ @@ -3171,7 +3165,7 @@ count_trailing_zero_bits (size_t val) { unsigned int count; count = 0; - for(val = ~val; val & 1; val >>= 1) + for (val = ~val; val & 1; val >>= 1) ++count; return count; @@ -3179,8 +3173,7 @@ count_trailing_zero_bits (size_t val) #endif } -static inline -size_t +static size_t size_t_to_host_endian (size_t val) { #ifdef WORDS_BIGENDIAN @@ -3272,17 +3265,13 @@ Return the destination vector. */) nr_bits = min (nr_bits, XBOOL_VECTOR (b)->size); } - bdata = (size_t*) XBOOL_VECTOR (b)->data; - adata = (size_t*) XBOOL_VECTOR (a)->data; - i = 0; + bdata = (size_t *) XBOOL_VECTOR (b)->data; + adata = (size_t *) XBOOL_VECTOR (a)->data; eassert_and_assume (nr_bits >= 0); - while (i < nr_bits / BITS_PER_SIZE_T) - { - bdata[i] = ~adata[i]; - i += 1; - } + for (i = 0; i < nr_bits / BITS_PER_SIZE_T; i++) + bdata[i] = ~adata[i]; if (nr_bits % BITS_PER_SIZE_T) { @@ -3298,7 +3287,7 @@ Return the destination vector. */) DEFUN ("bool-vector-count-matches", Fbool_vector_count_matches, Sbool_vector_count_matches, 2, 2, 0, doc: /* Count how many elements in A equal B. -A must be a bool vector. B is a generalized bool. */) +A must be a bool vector. B is a generalized bool. */) (Lisp_Object a, Lisp_Object b) { ptrdiff_t count; @@ -3312,11 +3301,11 @@ A must be a bool vector. B is a generalized bool. */) nr_bits = XBOOL_VECTOR (a)->size; count = 0; match = NILP (b) ? (size_t) -1 : 0; - adata = (size_t*) XBOOL_VECTOR (a)->data; + adata = (size_t *) XBOOL_VECTOR (a)->data; eassert_and_assume (nr_bits >= 0); - for(i = 0; i < nr_bits / BITS_PER_SIZE_T; ++i) + for (i = 0; i < nr_bits / BITS_PER_SIZE_T; ++i) count += popcount_size_t (adata[i] ^ match); /* Mask out trailing parts of final mword. */ @@ -3335,7 +3324,7 @@ DEFUN ("bool-vector-count-matches-at", Sbool_vector_count_matches_at, 3, 3, 0, doc: /* Count how many consecutive elements in A equal B at i. A must be a bool vector. B is a generalized boolean. i is an -index into the vector.*/) +index into the vector. */) (Lisp_Object a, Lisp_Object b, Lisp_Object i) { ptrdiff_t count; @@ -3354,11 +3343,11 @@ index into the vector.*/) if (XFASTINT (i) > nr_bits) /* Allow one past the end for convenience */ args_out_of_range (a, i); - adata = (size_t*) XBOOL_VECTOR (a)->data; + adata = (size_t *) XBOOL_VECTOR (a)->data; assume (nr_bits >= 0); nr_words = ROUNDUP (nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; - + pos = XFASTINT (i) / BITS_PER_SIZE_T; offset = XFASTINT (i) % BITS_PER_SIZE_T; count = 0; @@ -3376,7 +3365,7 @@ index into the vector.*/) mword >>= offset; count = count_trailing_zero_bits (mword); count = min (count, BITS_PER_SIZE_T - offset); - pos += 1; + pos++; if (count + offset < BITS_PER_SIZE_T) return make_number (count); } diff --git a/src/lisp.h b/src/lisp.h index a9a2c259b5b..f49a2042b1b 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4359,15 +4359,13 @@ functionp (Lisp_Object object) return 0; } -INLINE -uint16_t +INLINE uint16_t swap16 (uint16_t val) { return (val << 8) | (val & 0xFF); } -INLINE -uint32_t +INLINE uint32_t swap32 (uint32_t val) { uint32_t low = swap16 (val & 0xFFFF); @@ -4376,8 +4374,7 @@ swap32 (uint32_t val) } #ifdef UINT64_MAX -INLINE -uint64_t +INLINE uint64_t swap64 (uint64_t val) { uint64_t low = swap32 (val & 0xFFFFFFFF); diff --git a/src/xdisp.c b/src/xdisp.c index e1143bec1c0..6d19531aab6 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -1882,8 +1882,7 @@ pixel_to_glyph_coords (struct frame *f, register int pix_x, register int pix_y, text, or we can't tell because W's current matrix is not up to date. */ -static -struct glyph * +static struct glyph * x_y_to_hpos_vpos (struct window *w, int x, int y, int *hpos, int *vpos, int *dx, int *dy, int *area) { -- 2.11.4.GIT