Commit 0bbf00c7 authored by Paul Eggert's avatar Paul Eggert

Prefer now-standard int width macros

* src/data.c (ULL_WIDTH):
* src/lisp.h (EMACS_INT_WIDTH, BITS_PER_BITS_WORD):
* src/lread.c (read_integer):
* src/term.c (produce_glyphless_glyph):
* src/xterm.c (x_send_scroll_bar_event):
Use *_WIDTH macros instead of CHAR_BIT * sizeof.
* src/data.c (ULL_WIDTH): Rename from BITS_PER_ULL for consistency
with the *_WIDTH standard macros.  All uses changed.
* src/gmalloc.c (INT_BIT): Remove.  All uses replaced with INT_WIDTH.
* src/lisp.h (EMACS_INT_WIDTH): Rename from BITS_PER_EMACS_INT
for consistency with the *_WIDTH standard macros.  All uses changed.
(BITS_PER_CHAR): Remove; all uses replaced by CHAR_BIT.  This must
be the same as CHAR_WIDTH and avoids confusion with Elisp
char-width, which counts columns not bits.
(BITS_PER_SHORT): Remove; all uses replaced by SHRT_WIDTH.
(BITS_PER_LONG): Remove; all uses replaced by LONG_WIDTH.
* src/lread.c: Do not include limits.h since CHAR_BIT is no longer
used directly.
parent 8f4b6a20
......@@ -2935,11 +2935,11 @@ In this case, the sign bit is duplicated. */)
CHECK_NUMBER (value);
CHECK_NUMBER (count);
if (XINT (count) >= BITS_PER_EMACS_INT)
if (XINT (count) >= EMACS_INT_WIDTH)
XSETINT (val, 0);
else if (XINT (count) > 0)
XSETINT (val, XUINT (value) << XFASTINT (count));
else if (XINT (count) <= -BITS_PER_EMACS_INT)
else if (XINT (count) <= -EMACS_INT_WIDTH)
XSETINT (val, XINT (value) < 0 ? -1 : 0);
else
XSETINT (val, XINT (value) >> -XINT (count));
......@@ -2957,11 +2957,11 @@ In this case, zeros are shifted in on the left. */)
CHECK_NUMBER (value);
CHECK_NUMBER (count);
if (XINT (count) >= BITS_PER_EMACS_INT)
if (XINT (count) >= EMACS_INT_WIDTH)
XSETINT (val, 0);
else if (XINT (count) > 0)
XSETINT (val, XUINT (value) << XFASTINT (count));
else if (XINT (count) <= -BITS_PER_EMACS_INT)
else if (XINT (count) <= -EMACS_INT_WIDTH)
XSETINT (val, 0);
else
XSETINT (val, XUINT (value) >> -XINT (count));
......@@ -3031,24 +3031,24 @@ bool_vector_spare_mask (EMACS_INT nr_bits)
/* Info about unsigned long long, falling back on unsigned long
if unsigned long long is not available. */
#if HAVE_UNSIGNED_LONG_LONG_INT && defined ULLONG_MAX
enum { BITS_PER_ULL = CHAR_BIT * sizeof (unsigned long long) };
#if HAVE_UNSIGNED_LONG_LONG_INT && defined ULLONG_WIDTH
enum { ULL_WIDTH = ULLONG_WIDTH };
# define ULL_MAX ULLONG_MAX
#else
enum { BITS_PER_ULL = CHAR_BIT * sizeof (unsigned long) };
enum { ULL_WIDTH = ULONG_WIDTH };
# define ULL_MAX ULONG_MAX
# define count_one_bits_ll count_one_bits_l
# define count_trailing_zeros_ll count_trailing_zeros_l
#endif
/* Shift VAL right by the width of an unsigned long long.
BITS_PER_ULL must be less than BITS_PER_BITS_WORD. */
ULL_WIDTH must be less than BITS_PER_BITS_WORD. */
static bits_word
shift_right_ull (bits_word w)
{
/* Pacify bogus GCC warning about shift count exceeding type width. */
int shift = BITS_PER_ULL - BITS_PER_BITS_WORD < 0 ? BITS_PER_ULL : 0;
int shift = ULL_WIDTH - BITS_PER_BITS_WORD < 0 ? ULL_WIDTH : 0;
return w >> shift;
}
......@@ -3065,7 +3065,7 @@ count_one_bits_word (bits_word w)
{
int i = 0, count = 0;
while (count += count_one_bits_ll (w),
(i += BITS_PER_ULL) < BITS_PER_BITS_WORD)
(i += ULL_WIDTH) < BITS_PER_BITS_WORD)
w = shift_right_ull (w);
return count;
}
......@@ -3210,18 +3210,18 @@ count_trailing_zero_bits (bits_word val)
{
int count;
for (count = 0;
count < BITS_PER_BITS_WORD - BITS_PER_ULL;
count += BITS_PER_ULL)
count < BITS_PER_BITS_WORD - ULL_WIDTH;
count += ULL_WIDTH)
{
if (val & ULL_MAX)
return count + count_trailing_zeros_ll (val);
val = shift_right_ull (val);
}
if (BITS_PER_BITS_WORD % BITS_PER_ULL != 0
if (BITS_PER_BITS_WORD % ULL_WIDTH != 0
&& BITS_WORD_MAX == (bits_word) -1)
val |= (bits_word) 1 << pre_value (ULONG_MAX < BITS_WORD_MAX,
BITS_PER_BITS_WORD % BITS_PER_ULL);
BITS_PER_BITS_WORD % ULL_WIDTH);
return count + count_trailing_zeros_ll (val);
}
}
......
......@@ -118,14 +118,13 @@ extern int posix_memalign (void **, size_t, size_t);
receive a fragment of a block. Fragment sizes are powers of two,
and all fragments of a block are the same size. When all the
fragments in a block have been freed, the block itself is freed. */
#define INT_BIT (CHAR_BIT * sizeof (int))
#define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
#define BLOCKLOG (INT_WIDTH > 16 ? 12 : 9)
#define BLOCKSIZE (1 << BLOCKLOG)
#define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
/* Determine the amount of memory spanned by the initial heap table
(not an absolute limit). */
#define HEAP (INT_BIT > 16 ? 4194304 : 65536)
#define HEAP (INT_WIDTH > 16 ? 4194304 : 65536)
/* Number of contiguous free blocks allowed to build up at the end of
memory before they will be returned to the system. */
......
......@@ -2525,7 +2525,7 @@ xbm_image_p (Lisp_Object object)
if (STRINGP (elt))
{
if (SCHARS (elt)
< (width + BITS_PER_CHAR - 1) / BITS_PER_CHAR)
< (width + CHAR_BIT - 1) / CHAR_BIT)
return 0;
}
else if (BOOL_VECTOR_P (elt))
......@@ -2540,7 +2540,7 @@ xbm_image_p (Lisp_Object object)
else if (STRINGP (data))
{
if (SCHARS (data)
< (width + BITS_PER_CHAR - 1) / BITS_PER_CHAR * height)
< (width + CHAR_BIT - 1) / CHAR_BIT * height)
return 0;
}
else if (BOOL_VECTOR_P (data))
......@@ -3089,7 +3089,7 @@ xbm_load (struct frame *f, struct image *img)
{
int i;
char *p;
int nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
int nbytes = (img->width + CHAR_BIT - 1) / CHAR_BIT;
SAFE_NALLOCA (bits, nbytes, img->height);
p = bits;
......@@ -3113,7 +3113,7 @@ xbm_load (struct frame *f, struct image *img)
int nbytes, i;
/* Windows mono bitmaps are reversed compared with X. */
invertedBits = bits;
nbytes = (img->width + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
nbytes = (img->width + CHAR_BIT - 1) / CHAR_BIT;
SAFE_NALLOCA (bits, nbytes, img->height);
for (i = 0; i < nbytes; i++)
bits[i] = XBM_BIT_SHUFFLE (invertedBits[i]);
......
......@@ -1876,9 +1876,9 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
}
pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
/* Don't care for VPOS... */
1 << (BITS_PER_SHORT - 1),
1 << (SHRT_WIDTH - 1),
/* ... nor HPOS. */
1 << (BITS_PER_SHORT - 1),
1 << (SHRT_WIDTH - 1),
-1, hscroll, 0, w);
vpos -= pos.vpos;
first = 0;
......@@ -1926,9 +1926,9 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
}
pos = *compute_motion (prevline, bytepos, 0, lmargin, 0, from,
/* Don't care for VPOS... */
1 << (BITS_PER_SHORT - 1),
1 << (SHRT_WIDTH - 1),
/* ... nor HPOS. */
1 << (BITS_PER_SHORT - 1),
1 << (SHRT_WIDTH - 1),
-1, hscroll, 0, w);
did_motion = 1;
}
......@@ -1939,7 +1939,7 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
did_motion = 0;
}
return compute_motion (from, from_byte, vpos, pos.hpos, did_motion,
ZV, vtarget, - (1 << (BITS_PER_SHORT - 1)),
ZV, vtarget, - (1 << (SHRT_WIDTH - 1)),
-1, hscroll, 0, w);
}
......
......@@ -68,6 +68,7 @@ DEFINE_GDB_SYMBOL_BEGIN (int, GCTYPEBITS)
DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
/* EMACS_INT - signed integer wide enough to hold an Emacs value
EMACS_INT_WIDTH - width in bits of EMACS_INT
EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
pI - printf length modifier for EMACS_INT
EMACS_UINT - unsigned variant of EMACS_INT */
......@@ -77,16 +78,19 @@ DEFINE_GDB_SYMBOL_END (GCTYPEBITS)
# elif INTPTR_MAX <= INT_MAX && !defined WIDE_EMACS_INT
typedef int EMACS_INT;
typedef unsigned int EMACS_UINT;
enum { EMACS_INT_WIDTH = INT_WIDTH };
# define EMACS_INT_MAX INT_MAX
# define pI ""
# elif INTPTR_MAX <= LONG_MAX && !defined WIDE_EMACS_INT
typedef long int EMACS_INT;
typedef unsigned long EMACS_UINT;
enum { EMACS_INT_WIDTH = LONG_WIDTH };
# define EMACS_INT_MAX LONG_MAX
# define pI "l"
# elif INTPTR_MAX <= LLONG_MAX
typedef long long int EMACS_INT;
typedef unsigned long long int EMACS_UINT;
enum { EMACS_INT_WIDTH = LLONG_WIDTH };
# define EMACS_INT_MAX LLONG_MAX
# ifdef __MINGW32__
# define pI "I64"
......@@ -107,11 +111,12 @@ enum { BOOL_VECTOR_BITS_PER_CHAR =
/* An unsigned integer type representing a fixed-length bit sequence,
suitable for bool vector words, GC mark bits, etc. Normally it is size_t
for speed, but it is unsigned char on weird platforms. */
for speed, but on weird platforms it is unsigned char and not all
its bits are used. */
#if BOOL_VECTOR_BITS_PER_CHAR == CHAR_BIT
typedef size_t bits_word;
# define BITS_WORD_MAX SIZE_MAX
enum { BITS_PER_BITS_WORD = CHAR_BIT * sizeof (bits_word) };
enum { BITS_PER_BITS_WORD = SIZE_WIDTH };
#else
typedef unsigned char bits_word;
# define BITS_WORD_MAX ((1u << BOOL_VECTOR_BITS_PER_CHAR) - 1)
......@@ -119,15 +124,6 @@ enum { BITS_PER_BITS_WORD = BOOL_VECTOR_BITS_PER_CHAR };
#endif
verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1);
/* Number of bits in some machine integer types. */
enum
{
BITS_PER_CHAR = CHAR_BIT,
BITS_PER_SHORT = CHAR_BIT * sizeof (short),
BITS_PER_LONG = CHAR_BIT * sizeof (long int),
BITS_PER_EMACS_INT = CHAR_BIT * sizeof (EMACS_INT)
};
/* printmax_t and uprintmax_t are types for printing large integers.
These are the widest integers that are supported for printing.
pMd etc. are conversions for printing them.
......@@ -232,7 +228,7 @@ enum Lisp_Bits
#define GCALIGNMENT 8
/* Number of bits in a Lisp_Object value, not counting the tag. */
VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS,
VALBITS = EMACS_INT_WIDTH - GCTYPEBITS,
/* Number of bits in a Lisp fixnum tag. */
INTTYPEBITS = GCTYPEBITS - 1,
......@@ -2027,7 +2023,7 @@ static double const DEFAULT_REHASH_SIZE = 1.5;
INLINE EMACS_UINT
sxhash_combine (EMACS_UINT x, EMACS_UINT y)
{
return (x << 4) + (x >> (BITS_PER_EMACS_INT - 4)) + y;
return (x << 4) + (x >> (EMACS_INT_WIDTH - 4)) + y;
}
/* Hash X, returning a value that fits into a fixnum. */
......@@ -2035,7 +2031,7 @@ sxhash_combine (EMACS_UINT x, EMACS_UINT y)
INLINE EMACS_UINT
SXHASH_REDUCE (EMACS_UINT x)
{
return (x ^ x >> (BITS_PER_EMACS_INT - FIXNUM_BITS)) & INTMASK;
return (x ^ x >> (EMACS_INT_WIDTH - FIXNUM_BITS)) & INTMASK;
}
/* These structures are used for various misc types. */
......
......@@ -27,7 +27,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/stat.h>
#include <sys/file.h>
#include <errno.h>
#include <limits.h> /* For CHAR_BIT. */
#include <math.h>
#include <stat-time.h>
#include "lisp.h"
......@@ -2471,7 +2470,7 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix)
{
/* Room for sign, leading 0, other digits, trailing null byte.
Also, room for invalid syntax diagnostic. */
char buf[max (1 + 1 + sizeof (uintmax_t) * CHAR_BIT + 1,
char buf[max (1 + 1 + UINTMAX_WIDTH + 1,
sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT))];
int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete. */
......
......@@ -2223,8 +2223,8 @@ get_random (void)
int i;
for (i = 0; i < (FIXNUM_BITS + RAND_BITS - 1) / RAND_BITS; i++)
val = (random () ^ (val << RAND_BITS)
^ (val >> (BITS_PER_EMACS_INT - RAND_BITS)));
val ^= val >> (BITS_PER_EMACS_INT - FIXNUM_BITS);
^ (val >> (EMACS_INT_WIDTH - RAND_BITS)));
val ^= val >> (EMACS_INT_WIDTH - FIXNUM_BITS);
return val & INTMASK;
}
......
......@@ -1821,7 +1821,7 @@ static void
produce_glyphless_glyph (struct it *it, Lisp_Object acronym)
{
int len, face_id = merge_glyphless_glyph_face (it);
char buf[sizeof "\\x" + max (6, (sizeof it->c * CHAR_BIT + 3) / 4)];
char buf[sizeof "\\x" + max (6, (INT_WIDTH + 3) / 4)];
char const *str = " ";
if (it->glyphless_method == GLYPHLESS_DISPLAY_THIN_SPACE)
......
......@@ -224,7 +224,7 @@ sigismember (const sigset_t *set, int signo)
errno = EINVAL;
return -1;
}
if (signo > sizeof (*set) * BITS_PER_CHAR)
if (signo > sizeof (*set) * CHAR_BIT)
emacs_abort ();
return (*set & (1U << signo)) != 0;
......
......@@ -737,8 +737,7 @@ the pixmap. Bits are stored row by row, each row occupies
&& RANGED_INTEGERP (1, width, INT_MAX)
&& RANGED_INTEGERP (1, height, INT_MAX))
{
int bytes_per_row = ((XINT (width) + BITS_PER_CHAR - 1)
/ BITS_PER_CHAR);
int bytes_per_row = (XINT (width) + CHAR_BIT - 1) / CHAR_BIT;
if (XINT (height) <= SBYTES (data) / bytes_per_row)
pixmap_p = true;
}
......
......@@ -5219,7 +5219,7 @@ x_window_property_intern (struct frame *f,
property and those are indeed in 32 bit quantities if format is
32. */
if (BITS_PER_LONG > 32 && actual_format == 32)
if (LONG_WIDTH > 32 && actual_format == 32)
{
unsigned long i;
int *idata = (int *) tmp_data;
......
......@@ -1318,7 +1318,7 @@ x_get_window_property (Display *display, Window window, Atom property,
data = data1;
}
if (BITS_PER_LONG > 32 && *actual_format_ret == 32)
if (LONG_WIDTH > 32 && *actual_format_ret == 32)
{
unsigned long i;
int *idata = (int *) (data + offset);
......@@ -2473,7 +2473,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
function expects them to be of size int (i.e. 32). So to be able to
use that function, put the data in the form it expects if format is 32. */
if (BITS_PER_LONG > 32 && event->format == 32)
if (LONG_WIDTH > 32 && event->format == 32)
{
for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */
idata[i] = event->data.l[i];
......
......@@ -5245,9 +5245,8 @@ x_send_scroll_bar_event (Lisp_Object window, enum scroll_bar_part part,
struct window *w = XWINDOW (window);
struct frame *f = XFRAME (w->frame);
intptr_t iw = (intptr_t) w;
enum { BITS_PER_INTPTR = CHAR_BIT * sizeof iw };
verify (BITS_PER_INTPTR <= 64);
int sign_shift = BITS_PER_INTPTR - 32;
verify (INTPTR_WIDTH <= 64);
int sign_shift = INTPTR_WIDTH - 32;
block_input ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment