diff options
| author | Paul Eggert | 2013-09-23 21:28:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-09-23 21:28:06 -0700 |
| commit | 7be68de5d25998e7d15aaab800c40cad48eac846 (patch) | |
| tree | 881c8cdf8c60ee5c11bb3f00c7e27c09e162142b /src/data.c | |
| parent | d160dd0c71db061d819ce5ac337e4de8bd4f7d11 (diff) | |
| download | emacs-7be68de5d25998e7d15aaab800c40cad48eac846.tar.gz emacs-7be68de5d25998e7d15aaab800c40cad48eac846.zip | |
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.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 81 |
1 files changed, 35 insertions, 46 deletions
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. */) | |||
| 617 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | 617 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); |
| 618 | if (blv->fwd) | 618 | if (blv->fwd) |
| 619 | /* In set_internal, we un-forward vars when their value is | 619 | /* In set_internal, we un-forward vars when their value is |
| 620 | set to Qunbound. */ | 620 | set to Qunbound. */ |
| 621 | return Qt; | 621 | return Qt; |
| 622 | else | 622 | else |
| 623 | { | 623 | { |
| @@ -628,7 +628,7 @@ global value outside of any lexical scope. */) | |||
| 628 | } | 628 | } |
| 629 | case SYMBOL_FORWARDED: | 629 | case SYMBOL_FORWARDED: |
| 630 | /* In set_internal, we un-forward vars when their value is | 630 | /* In set_internal, we un-forward vars when their value is |
| 631 | set to Qunbound. */ | 631 | set to Qunbound. */ |
| 632 | return Qt; | 632 | return Qt; |
| 633 | default: emacs_abort (); | 633 | default: emacs_abort (); |
| 634 | } | 634 | } |
| @@ -1996,7 +1996,7 @@ If the current binding is global (the default), the value is nil. */) | |||
| 1996 | } | 1996 | } |
| 1997 | 1997 | ||
| 1998 | /* This code is disabled now that we use the selected frame to return | 1998 | /* This code is disabled now that we use the selected frame to return |
| 1999 | keyboard-local-values. */ | 1999 | keyboard-local-values. */ |
| 2000 | #if 0 | 2000 | #if 0 |
| 2001 | extern struct terminal *get_terminal (Lisp_Object display, int); | 2001 | extern struct terminal *get_terminal (Lisp_Object display, int); |
| 2002 | 2002 | ||
| @@ -2963,15 +2963,14 @@ lowercase l) for small endian machines. */) | |||
| 2963 | always allocate bool vectors with at least one size_t of storage so | 2963 | always allocate bool vectors with at least one size_t of storage so |
| 2964 | that we don't have to special-case empty bit vectors. */ | 2964 | that we don't have to special-case empty bit vectors. */ |
| 2965 | 2965 | ||
| 2966 | static inline | 2966 | static size_t |
| 2967 | size_t | ||
| 2968 | bool_vector_spare_mask (ptrdiff_t nr_bits) | 2967 | bool_vector_spare_mask (ptrdiff_t nr_bits) |
| 2969 | { | 2968 | { |
| 2970 | eassert_and_assume (nr_bits > 0); | 2969 | eassert_and_assume (nr_bits > 0); |
| 2971 | return (((size_t) 1) << (nr_bits % BITS_PER_SIZE_T)) - 1; | 2970 | return (((size_t) 1) << (nr_bits % BITS_PER_SIZE_T)) - 1; |
| 2972 | } | 2971 | } |
| 2973 | 2972 | ||
| 2974 | #if __MSC_VER >= 1500 && (defined _M_IX86 || defined _M_X64) | 2973 | #if _MSC_VER >= 1500 && (defined _M_IX86 || defined _M_X64) |
| 2975 | # define USE_MSC_POPCOUNT | 2974 | # define USE_MSC_POPCOUNT |
| 2976 | #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) | 2975 | #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) |
| 2977 | # define USE_GCC_POPCOUNT | 2976 | # define USE_GCC_POPCOUNT |
| @@ -2984,8 +2983,7 @@ bool_vector_spare_mask (ptrdiff_t nr_bits) | |||
| 2984 | #endif | 2983 | #endif |
| 2985 | 2984 | ||
| 2986 | #ifdef NEED_GENERIC_POPCOUNT | 2985 | #ifdef NEED_GENERIC_POPCOUNT |
| 2987 | static inline | 2986 | static unsigned int |
| 2988 | unsigned int | ||
| 2989 | popcount_size_t_generic (size_t val) | 2987 | popcount_size_t_generic (size_t val) |
| 2990 | { | 2988 | { |
| 2991 | unsigned short j; | 2989 | unsigned short j; |
| @@ -2999,8 +2997,7 @@ popcount_size_t_generic (size_t val) | |||
| 2999 | #endif | 2997 | #endif |
| 3000 | 2998 | ||
| 3001 | #ifdef USE_MSC_POPCOUNT | 2999 | #ifdef USE_MSC_POPCOUNT |
| 3002 | static inline | 3000 | static unsigned int |
| 3003 | unsigned int | ||
| 3004 | popcount_size_t_msc (size_t val) | 3001 | popcount_size_t_msc (size_t val) |
| 3005 | { | 3002 | { |
| 3006 | unsigned int count; | 3003 | unsigned int count; |
| @@ -3045,8 +3042,7 @@ popcount_size_t_msc (size_t val) | |||
| 3045 | #endif /* USE_MSC_POPCOUNT */ | 3042 | #endif /* USE_MSC_POPCOUNT */ |
| 3046 | 3043 | ||
| 3047 | #ifdef USE_GCC_POPCOUNT | 3044 | #ifdef USE_GCC_POPCOUNT |
| 3048 | static inline | 3045 | static unsigned int |
| 3049 | unsigned int | ||
| 3050 | popcount_size_t_gcc (size_t val) | 3046 | popcount_size_t_gcc (size_t val) |
| 3051 | { | 3047 | { |
| 3052 | # if BITS_PER_SIZE_T == 64 | 3048 | # if BITS_PER_SIZE_T == 64 |
| @@ -3057,9 +3053,8 @@ popcount_size_t_gcc (size_t val) | |||
| 3057 | } | 3053 | } |
| 3058 | #endif /* USE_GCC_POPCOUNT */ | 3054 | #endif /* USE_GCC_POPCOUNT */ |
| 3059 | 3055 | ||
| 3060 | static inline | 3056 | static unsigned int |
| 3061 | unsigned int | 3057 | popcount_size_t (size_t val) |
| 3062 | popcount_size_t(size_t val) | ||
| 3063 | { | 3058 | { |
| 3064 | #if defined USE_MSC_POPCOUNT | 3059 | #if defined USE_MSC_POPCOUNT |
| 3065 | return popcount_size_t_msc (val); | 3060 | return popcount_size_t_msc (val); |
| @@ -3067,7 +3062,7 @@ popcount_size_t(size_t val) | |||
| 3067 | return popcount_size_t_gcc (val); | 3062 | return popcount_size_t_gcc (val); |
| 3068 | #else | 3063 | #else |
| 3069 | return popcount_size_t_generic (val); | 3064 | return popcount_size_t_generic (val); |
| 3070 | #endif | 3065 | #endif |
| 3071 | } | 3066 | } |
| 3072 | 3067 | ||
| 3073 | enum bool_vector_op { bool_vector_exclusive_or, | 3068 | enum bool_vector_op { bool_vector_exclusive_or, |
| @@ -3076,8 +3071,7 @@ enum bool_vector_op { bool_vector_exclusive_or, | |||
| 3076 | bool_vector_set_difference, | 3071 | bool_vector_set_difference, |
| 3077 | bool_vector_subsetp }; | 3072 | bool_vector_subsetp }; |
| 3078 | 3073 | ||
| 3079 | static inline | 3074 | static Lisp_Object |
| 3080 | Lisp_Object | ||
| 3081 | bool_vector_binop_driver (Lisp_Object op1, | 3075 | bool_vector_binop_driver (Lisp_Object op1, |
| 3082 | Lisp_Object op2, | 3076 | Lisp_Object op2, |
| 3083 | Lisp_Object dest, | 3077 | Lisp_Object dest, |
| @@ -3108,11 +3102,11 @@ bool_vector_binop_driver (Lisp_Object op1, | |||
| 3108 | } | 3102 | } |
| 3109 | 3103 | ||
| 3110 | eassert_and_assume (nr_bits >= 0); | 3104 | eassert_and_assume (nr_bits >= 0); |
| 3111 | nr_words = ROUNDUP(nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; | 3105 | nr_words = ROUNDUP (nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; |
| 3112 | 3106 | ||
| 3113 | adata = (size_t*) XBOOL_VECTOR (dest)->data; | 3107 | adata = (size_t *) XBOOL_VECTOR (dest)->data; |
| 3114 | bdata = (size_t*) XBOOL_VECTOR (op1)->data; | 3108 | bdata = (size_t *) XBOOL_VECTOR (op1)->data; |
| 3115 | cdata = (size_t*) XBOOL_VECTOR (op2)->data; | 3109 | cdata = (size_t *) XBOOL_VECTOR (op2)->data; |
| 3116 | i = 0; | 3110 | i = 0; |
| 3117 | do | 3111 | do |
| 3118 | { | 3112 | { |
| @@ -3132,16 +3126,16 @@ bool_vector_binop_driver (Lisp_Object op1, | |||
| 3132 | if (op != bool_vector_subsetp) | 3126 | if (op != bool_vector_subsetp) |
| 3133 | adata[i] = mword; | 3127 | adata[i] = mword; |
| 3134 | 3128 | ||
| 3135 | i += 1; | 3129 | i++; |
| 3136 | } | 3130 | } |
| 3137 | while (i < nr_words); | 3131 | while (i < nr_words); |
| 3132 | |||
| 3138 | return changed ? dest : Qnil; | 3133 | return changed ? dest : Qnil; |
| 3139 | } | 3134 | } |
| 3140 | 3135 | ||
| 3141 | /* Compute the number of trailing zero bits in val. If val is zero, | 3136 | /* Compute the number of trailing zero bits in val. If val is zero, |
| 3142 | return the number of bits in val. */ | 3137 | return the number of bits in val. */ |
| 3143 | static inline | 3138 | static unsigned int |
| 3144 | unsigned int | ||
| 3145 | count_trailing_zero_bits (size_t val) | 3139 | count_trailing_zero_bits (size_t val) |
| 3146 | { | 3140 | { |
| 3147 | if (val == 0) | 3141 | if (val == 0) |
| @@ -3151,7 +3145,7 @@ count_trailing_zero_bits (size_t val) | |||
| 3151 | return __builtin_ctzll (val); | 3145 | return __builtin_ctzll (val); |
| 3152 | #elif defined USE_GCC_POPCOUNT && BITS_PER_SIZE_T == 32 | 3146 | #elif defined USE_GCC_POPCOUNT && BITS_PER_SIZE_T == 32 |
| 3153 | return __builtin_ctz (val); | 3147 | return __builtin_ctz (val); |
| 3154 | #elif __MSC_VER && BITS_PER_SIZE_T == 64 | 3148 | #elif _MSC_VER && BITS_PER_SIZE_T == 64 |
| 3155 | # pragma intrinsic _BitScanForward64 | 3149 | # pragma intrinsic _BitScanForward64 |
| 3156 | { | 3150 | { |
| 3157 | /* No support test needed: support since 386. */ | 3151 | /* No support test needed: support since 386. */ |
| @@ -3159,7 +3153,7 @@ count_trailing_zero_bits (size_t val) | |||
| 3159 | _BitScanForward64 (&result, val); | 3153 | _BitScanForward64 (&result, val); |
| 3160 | return (unsigned int) result; | 3154 | return (unsigned int) result; |
| 3161 | } | 3155 | } |
| 3162 | #elif __MSC_VER && BITS_PER_SIZE_T == 32 | 3156 | #elif _MSC_VER && BITS_PER_SIZE_T == 32 |
| 3163 | # pragma intrinsic _BitScanForward | 3157 | # pragma intrinsic _BitScanForward |
| 3164 | { | 3158 | { |
| 3165 | /* No support test needed: support since 386. */ | 3159 | /* No support test needed: support since 386. */ |
| @@ -3171,7 +3165,7 @@ count_trailing_zero_bits (size_t val) | |||
| 3171 | { | 3165 | { |
| 3172 | unsigned int count; | 3166 | unsigned int count; |
| 3173 | count = 0; | 3167 | count = 0; |
| 3174 | for(val = ~val; val & 1; val >>= 1) | 3168 | for (val = ~val; val & 1; val >>= 1) |
| 3175 | ++count; | 3169 | ++count; |
| 3176 | 3170 | ||
| 3177 | return count; | 3171 | return count; |
| @@ -3179,8 +3173,7 @@ count_trailing_zero_bits (size_t val) | |||
| 3179 | #endif | 3173 | #endif |
| 3180 | } | 3174 | } |
| 3181 | 3175 | ||
| 3182 | static inline | 3176 | static size_t |
| 3183 | size_t | ||
| 3184 | size_t_to_host_endian (size_t val) | 3177 | size_t_to_host_endian (size_t val) |
| 3185 | { | 3178 | { |
| 3186 | #ifdef WORDS_BIGENDIAN | 3179 | #ifdef WORDS_BIGENDIAN |
| @@ -3272,17 +3265,13 @@ Return the destination vector. */) | |||
| 3272 | nr_bits = min (nr_bits, XBOOL_VECTOR (b)->size); | 3265 | nr_bits = min (nr_bits, XBOOL_VECTOR (b)->size); |
| 3273 | } | 3266 | } |
| 3274 | 3267 | ||
| 3275 | bdata = (size_t*) XBOOL_VECTOR (b)->data; | 3268 | bdata = (size_t *) XBOOL_VECTOR (b)->data; |
| 3276 | adata = (size_t*) XBOOL_VECTOR (a)->data; | 3269 | adata = (size_t *) XBOOL_VECTOR (a)->data; |
| 3277 | i = 0; | ||
| 3278 | 3270 | ||
| 3279 | eassert_and_assume (nr_bits >= 0); | 3271 | eassert_and_assume (nr_bits >= 0); |
| 3280 | 3272 | ||
| 3281 | while (i < nr_bits / BITS_PER_SIZE_T) | 3273 | for (i = 0; i < nr_bits / BITS_PER_SIZE_T; i++) |
| 3282 | { | 3274 | bdata[i] = ~adata[i]; |
| 3283 | bdata[i] = ~adata[i]; | ||
| 3284 | i += 1; | ||
| 3285 | } | ||
| 3286 | 3275 | ||
| 3287 | if (nr_bits % BITS_PER_SIZE_T) | 3276 | if (nr_bits % BITS_PER_SIZE_T) |
| 3288 | { | 3277 | { |
| @@ -3298,7 +3287,7 @@ Return the destination vector. */) | |||
| 3298 | DEFUN ("bool-vector-count-matches", Fbool_vector_count_matches, | 3287 | DEFUN ("bool-vector-count-matches", Fbool_vector_count_matches, |
| 3299 | Sbool_vector_count_matches, 2, 2, 0, | 3288 | Sbool_vector_count_matches, 2, 2, 0, |
| 3300 | doc: /* Count how many elements in A equal B. | 3289 | doc: /* Count how many elements in A equal B. |
| 3301 | A must be a bool vector. B is a generalized bool. */) | 3290 | A must be a bool vector. B is a generalized bool. */) |
| 3302 | (Lisp_Object a, Lisp_Object b) | 3291 | (Lisp_Object a, Lisp_Object b) |
| 3303 | { | 3292 | { |
| 3304 | ptrdiff_t count; | 3293 | ptrdiff_t count; |
| @@ -3312,11 +3301,11 @@ A must be a bool vector. B is a generalized bool. */) | |||
| 3312 | nr_bits = XBOOL_VECTOR (a)->size; | 3301 | nr_bits = XBOOL_VECTOR (a)->size; |
| 3313 | count = 0; | 3302 | count = 0; |
| 3314 | match = NILP (b) ? (size_t) -1 : 0; | 3303 | match = NILP (b) ? (size_t) -1 : 0; |
| 3315 | adata = (size_t*) XBOOL_VECTOR (a)->data; | 3304 | adata = (size_t *) XBOOL_VECTOR (a)->data; |
| 3316 | 3305 | ||
| 3317 | eassert_and_assume (nr_bits >= 0); | 3306 | eassert_and_assume (nr_bits >= 0); |
| 3318 | 3307 | ||
| 3319 | for(i = 0; i < nr_bits / BITS_PER_SIZE_T; ++i) | 3308 | for (i = 0; i < nr_bits / BITS_PER_SIZE_T; ++i) |
| 3320 | count += popcount_size_t (adata[i] ^ match); | 3309 | count += popcount_size_t (adata[i] ^ match); |
| 3321 | 3310 | ||
| 3322 | /* Mask out trailing parts of final mword. */ | 3311 | /* Mask out trailing parts of final mword. */ |
| @@ -3335,7 +3324,7 @@ DEFUN ("bool-vector-count-matches-at", | |||
| 3335 | Sbool_vector_count_matches_at, 3, 3, 0, | 3324 | Sbool_vector_count_matches_at, 3, 3, 0, |
| 3336 | doc: /* Count how many consecutive elements in A equal B at i. | 3325 | doc: /* Count how many consecutive elements in A equal B at i. |
| 3337 | A must be a bool vector. B is a generalized boolean. i is an | 3326 | A must be a bool vector. B is a generalized boolean. i is an |
| 3338 | index into the vector.*/) | 3327 | index into the vector. */) |
| 3339 | (Lisp_Object a, Lisp_Object b, Lisp_Object i) | 3328 | (Lisp_Object a, Lisp_Object b, Lisp_Object i) |
| 3340 | { | 3329 | { |
| 3341 | ptrdiff_t count; | 3330 | ptrdiff_t count; |
| @@ -3354,11 +3343,11 @@ index into the vector.*/) | |||
| 3354 | if (XFASTINT (i) > nr_bits) /* Allow one past the end for convenience */ | 3343 | if (XFASTINT (i) > nr_bits) /* Allow one past the end for convenience */ |
| 3355 | args_out_of_range (a, i); | 3344 | args_out_of_range (a, i); |
| 3356 | 3345 | ||
| 3357 | adata = (size_t*) XBOOL_VECTOR (a)->data; | 3346 | adata = (size_t *) XBOOL_VECTOR (a)->data; |
| 3358 | 3347 | ||
| 3359 | assume (nr_bits >= 0); | 3348 | assume (nr_bits >= 0); |
| 3360 | nr_words = ROUNDUP (nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; | 3349 | nr_words = ROUNDUP (nr_bits, BITS_PER_SIZE_T) / BITS_PER_SIZE_T; |
| 3361 | 3350 | ||
| 3362 | pos = XFASTINT (i) / BITS_PER_SIZE_T; | 3351 | pos = XFASTINT (i) / BITS_PER_SIZE_T; |
| 3363 | offset = XFASTINT (i) % BITS_PER_SIZE_T; | 3352 | offset = XFASTINT (i) % BITS_PER_SIZE_T; |
| 3364 | count = 0; | 3353 | count = 0; |
| @@ -3376,7 +3365,7 @@ index into the vector.*/) | |||
| 3376 | mword >>= offset; | 3365 | mword >>= offset; |
| 3377 | count = count_trailing_zero_bits (mword); | 3366 | count = count_trailing_zero_bits (mword); |
| 3378 | count = min (count, BITS_PER_SIZE_T - offset); | 3367 | count = min (count, BITS_PER_SIZE_T - offset); |
| 3379 | pos += 1; | 3368 | pos++; |
| 3380 | if (count + offset < BITS_PER_SIZE_T) | 3369 | if (count + offset < BITS_PER_SIZE_T) |
| 3381 | return make_number (count); | 3370 | return make_number (count); |
| 3382 | } | 3371 | } |