summaryrefslogtreecommitdiffstats
path: root/mpi/mpi-types.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-06-17 11:23:04 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-06-18 10:14:06 -0700
commit185d8ebc898f623acaff580eb934c6e345307a93 (patch)
treeccbd5696116a4d0a217cf6f35c80c8036472edd9 /mpi/mpi-types.h
parent7dc634268cb7e33b02462667c1827e7dc146c4ad (diff)
downloadtxr-185d8ebc898f623acaff580eb934c6e345307a93.tar.gz
txr-185d8ebc898f623acaff580eb934c6e345307a93.tar.bz2
txr-185d8ebc898f623acaff580eb934c6e345307a93.zip
mpi: fix some careless use of integer types.
MPI has a mp_size type for sizing of the digit arrays and some other uses. It is not consistently used. Moreover, it is typedef'd as a signed type. The type int is used for iterating over digits, instead of the matching mpi_size type. The int type is used as a size argument in some functions, and in functions that return the number of bits. This patch makes mp_size unsigned and replaces most uses of int with a more appropriate type. Because mp_size is now used for indexing, and is unsigned, some downward loop termination tests have to be changed; the always true condition ix >= 0 cannot be used. * arith.c (width): Use mp_size for local variable which iterates over digits inside mpi_int object, and for bit count. Use unum to convert bit count to Lisp integer: mp_size could be out of range of cnum. * mpi/mpi-types.h (mp_size): Typedef to unsigned. (MP_SIZE_MAX): New macro. (MP_DIGIT_BIT, MP_WORD_BIT): Cast the value to mp_size rather than to int. * mpi/mpi.c (s_mp_defprec): Declare variable as mp_size. (s_mp_setz, s_mp_copy, mp_size, s_highest_bit_mp, s_mp_set_bit, s_mp_ispow2, s_mp_outlen, mp_set_int, mp_set_uintptr, mp_set_double_intptr, mp_expt, mp_sqrt, mp_exptmod, mp_hash, mp_gcd, mp_shift, mp_bit, mp_to_double, mp_print, mp_read_signed_bin, mp_signed_bin_size, mp_read_unsigned_bin, mp_unsigned_bin_size, mp_to_unsigned_bin, mp_to_unsigned_buf, mp_count_bits, mp_is_pow_two, mp_read_radix, mp_radix_size, mp_value_radix_size, mp_toradix_case, s_mp_setz, s_mp_copy, mp_size, s_highest_bit_mp, s_mp_set_bit, s_mp_mul_2, s_mp_mod_2d, s_mp_div_2d, s_mp_div_d, s_mp_sqr, s_mp_sqr, s_mp_div, s_mp_cmp, s_mp_cmp_d, s_mp_ispow2, s_mp_outlen): In all these functions, use size_t for external size, mp_size for number of digits and bits, in return values, arguments and local variables. Tests in descending loops are adjusted for unsigned logic. * mpi/mpi.h (mp_get_prec, mp_set_prec, mp_read_signed_bin, mp_signed_bin_size, mp_read_unsigned_bin, mp_unsigned_bin_size, mp_to_unsigned_buf, mp_count_bits, mp_is_pow_two, mp_radix_size, mp_value_radix_size): Declarations updated. * mpi/mplogic.c (mpl_not, mpl_and, mpl_or, mpl_xor, mpl_rsh, mpl_lsh, mpl_num_set, mpl_num_clear, mpl_parity): Just like in mpi.c * rand.c (make_random_state): Use mp_size and ucnum for local variables holding digit and bit counts. * sysif.c (off_t_num): Use mp_size for digit count.
Diffstat (limited to 'mpi/mpi-types.h')
-rw-r--r--mpi/mpi-types.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/mpi/mpi-types.h b/mpi/mpi-types.h
index 36265247..5d9f21d9 100644
--- a/mpi/mpi-types.h
+++ b/mpi/mpi-types.h
@@ -3,7 +3,8 @@
* bitfields inside the mp_int struct.
*/
typedef int mp_sign;
-typedef int mp_size;
+typedef unsigned mp_size;
+#define MP_SIZE_MAX UINT_MAX
/*
* Universal. Does not need platform configuration.
@@ -48,9 +49,9 @@ typedef int mp_err;
#error Failure to configure MPI types on this target platform
#endif
-#define MP_DIGIT_BIT convert(int, CHAR_BIT*sizeof(mp_digit))
+#define MP_DIGIT_BIT convert(mp_size, CHAR_BIT*sizeof(mp_digit))
#define MP_DIGIT_MAX convert(mp_digit, -1)
-#define MP_WORD_BIT convert(int, CHAR_BIT*sizeof(mp_word))
+#define MP_WORD_BIT convert(mp_size, CHAR_BIT*sizeof(mp_word))
#define MP_WORD_MAX convert(mp_word, -1)
#define RADIX (convert(mp_word, MP_DIGIT_MAX) + 1)