diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-01-23 06:58:38 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-01-23 06:58:38 -0800 |
commit | b333ea2900a2e7c10d7b5cd35bf250c8e2d8d40f (patch) | |
tree | f0cd73c36dd467cefe1506326e6d0c23bda28a8d /rand.c | |
parent | f64d0bb5e0bfff833936d63849f86510a2328fee (diff) | |
download | txr-b333ea2900a2e7c10d7b5cd35bf250c8e2d8d40f.tar.gz txr-b333ea2900a2e7c10d7b5cd35bf250c8e2d8d40f.tar.bz2 txr-b333ea2900a2e7c10d7b5cd35bf250c8e2d8d40f.zip |
Fix some instances of 4 bytes = 32 bits assumption.
* hash.c (equal_hash, eql_hash, cobj_eq_hash_op,
hash_hash_op): Multiply object size by CHAR_BIT and switch on
number of bits, rather than bytes.
* sysif.c (off_t_num): Likewise.
* arith.c, ffi.c, itypes.c, rand.c: In numerous #if directive,
fix size tests from bytes to bits.
* configure: in the test that detects integer types, and in
the test for enabling large file offsets, detect one more
variable from the system: the value of CHAR_BIT. This
turns into SIZEOF_BYTE. We use that value instead of a
hard-coded 8.
Diffstat (limited to 'rand.c')
-rw-r--r-- | rand.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -44,9 +44,9 @@ #define random_warmup (deref(lookup_var_l(nil, random_warmup_s))) -#if SIZEOF_INT == 4 +#if CHAR_BIT * SIZEOF_INT == 32 typedef unsigned int rand32_t; -#elif SIZEOF_LONG == 4 +#elif CHAR_BIT * SIZEOF_LONG == 32 typedef unsigned long rand32_t; #endif @@ -136,11 +136,11 @@ val make_random_state(val seed, val warmup) r->state[0] = s & 0xFFFFFFFFul; i = 1; -#if SIZEOF_PTR == 8 +#if CHAR_BIT * SIZEOF_PTR == 64 s >>= 32; r->state[1] = s & 0xFFFFFFFFul; i = 2; -#elif SIZEOF_PTR > 8 +#elif CHAR_BIT * SIZEOF_PTR > 64 #error port me! #endif } else if (nilp(seed)) { @@ -304,14 +304,14 @@ val random(val state, val modulus) return zero; } else if (m > 1) { int bits = highest_bit(m - 1); -#if SIZEOF_PTR >= 8 +#if CHAR_BIT * SIZEOF_PTR >= 64 ucnum rands_needed = (bits + 32 - 1) / 32; #endif ucnum msb_rand_bits = bits % 32; rand32_t msb_rand_mask = convert(rand32_t, -1) >> (32 - msb_rand_bits); for (;;) { cnum out = 0; -#if SIZEOF_PTR >= 8 +#if CHAR_BIT * SIZEOF_PTR >= 64 ucnum i; for (i = 0; i < rands_needed; i++) { |