mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 04:15:36 +02:00
Support for x86_64-w64-mingw32.
On x86-64-MinGW the size of long is 4. As long is used for SCM_FIXNUM_BIT, that would mean incompatible .go files, and waste of cell space. So we would like to use long long, but the GMP interface uses long. To get around this, the x86-64-MinGW port now requires the use of mini-GMP. Mini-GMP has been changed to use intptr_t and uintptr_t. Likewise, "integers.{h,c}" and "numbers.{h,c}" now use intptr_t instead of scm_t_inum or long, and uintptr_t instead of unsigned long. * configure.ac: When x86_64-w64-mingw32, require mini-GMP. * libguile/mini-gmp.h: Use intptr_t instead of long, uintptr_t instead of unsigned long throughout. * libguile/mini-gmp.c: Likewise. * libguile/scm.h (SCM_INTPTR_T_BIT): New define. * libguile/numbers.h (SCM_FIXNUM_BIT): Use it. * libguile/numbers.c (L1, UL1): New macros. Use them thoughout instead of 1L, 1UL. (verify): Use SCM_INTPTR_T_BIT. (verify): Use SCM_INTPTR_T_MAX and SCM_INTPTR_T_MIN. (scm_from_inum): Remove macro. Use intptr_t and uintptr_t instead of scm_t_inum or long, and unsigned long. * libguile/numbers.h (scm_from_intptr, scm_from_uintptr, scm_to_intptr, scm_to_uintptr): New defines. * libguile/integers.h: Use intptr_t and uintptr_t instead of scm_t_inum and unsigned long. * libguile/integers.c (L1) : New macro. Use it thoughout instead of 1L. Use intptr_t and uintptr_t instead of long and unsigned long. (long_magnitude): Rename to... (intptr_t_magnitude): ...this. Use intptr_t, uintptr_t. (negative_long): Rename to... (negative_t_intptr): ...this. Use uintptr_t, INTPTR_MIN. (inum_magnitude): Use intptr_t. (ulong_to_bignum): Rename to... (uintptr_t_to_bignum): ...this. Use uintptr_t. (long_to_bignum): Rename to... (intptr_t_to_bignum): ...this. Use intptr_t. (long_to_scm): Rename to... (intptr_t_to_scm): ...this. Use intptr_to_bignum. (ulong_to_scm): Rename to... (uintptr_t_to_scm): ...this. Use uintptr_to_bignum. (long_sign): Rename to.. (intptr_t_sign): ...this. Use SCM_SIZEOF_INTPTR_T. (bignum_cmp_long): Rename to... (bignum_cmp_intptr_t): ...this. Use uintptr_t. * libguile/array-map.c (array_compare): Use uintptr_t instead of unsigned long and intptr_t instead of long. * libguile/arrays.c (make-shared-array): Use ssize_t instead of long. * libguile/bytevectors.c (is_signed_int32, is_unsigned_int32) [MINGW32 && __x86_64__]: Use ULL. (twos_complement): Use uintptr_t instead of unsigned long. * libguile/hash.c (JENKINS_LOOKUP3_HASHWORD2): Likewise. (narrow_string_hash, wide_string_hash, scm_i_string_hash, scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash, scm_i_struct_hash, scm_raw_ihashq, scm_raw_ihash): Use and return uintptr_t instead of unsigned long. (scm_hashv, scm_hash): Use SCM_UINTPTR_T_MAX. * libguile/hash.h (scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash): update prototypes. * libguile/scmsigs.c (sigaction): Use intptr_t instead of long. * libguile/strings.c (scm_i_make_symbol, (scm_i_c_make_symbol): Use uintptr_t instead of unsigned long. * libguile/strings.h (scm_i_make_symbol, (scm_i_c_make_symbol): Update declacations. * libguile/srfi-60.c: Use scm_to_uintptr, scm_from_intptr and variants throughout. * libguile/symbols.c (symbol-hash): Use scm_from_uintptr. Co-authored-by: Mike Gran <spk121@yahoo.com> Co-authored-by: Andy Wingo <wingo@pobox.com>
This commit is contained in:
parent
d58c9411ae
commit
76950b4281
19 changed files with 623 additions and 597 deletions
|
@ -1,6 +1,6 @@
|
|||
/* srfi-60.c --- Integers as Bits
|
||||
|
||||
Copyright 2005-2006,2008,2010,2014,2018,2022
|
||||
Copyright 2005-2006,2008,2010,2014,2018,2021,2022
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Guile.
|
||||
|
@ -76,10 +76,10 @@ SCM_DEFINE (scm_srfi60_copy_bit, "copy-bit", 3, 0, 0,
|
|||
"@end example")
|
||||
#define FUNC_NAME s_scm_srfi60_copy_bit
|
||||
{
|
||||
unsigned long ii;
|
||||
uintptr_t ii;
|
||||
int bb;
|
||||
|
||||
ii = scm_to_ulong (index);
|
||||
ii = scm_to_uintptr_t (index);
|
||||
bb = scm_to_bool (newbit);
|
||||
|
||||
if (SCM_I_INUMP (n))
|
||||
|
@ -113,9 +113,9 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
|
|||
"@end example")
|
||||
#define FUNC_NAME s_scm_srfi60_rotate_bit_field
|
||||
{
|
||||
unsigned long ss = scm_to_ulong (start);
|
||||
unsigned long ee = scm_to_ulong (end);
|
||||
unsigned long ww, cc;
|
||||
uintptr_t ss = scm_to_uintptr_t (start);
|
||||
uintptr_t ee = scm_to_uintptr_t (end);
|
||||
uintptr_t ww, cc;
|
||||
|
||||
SCM_ASSERT_RANGE (3, end, (ee >= ss));
|
||||
ww = ee - ss;
|
||||
|
@ -125,45 +125,46 @@ SCM_DEFINE (scm_srfi60_rotate_bit_field, "rotate-bit-field", 4, 0, 0,
|
|||
if (ww <= 1)
|
||||
cc = 0;
|
||||
else
|
||||
cc = scm_to_ulong (scm_modulo (count, scm_difference (end, start)));
|
||||
cc = scm_to_uintptr_t (scm_modulo (count, scm_difference (end, start)));
|
||||
|
||||
mpz_t zn;
|
||||
|
||||
if (SCM_I_INUMP (n))
|
||||
{
|
||||
long nn = SCM_I_INUM (n);
|
||||
intptr_t nn = SCM_I_INUM (n);
|
||||
|
||||
if (ee <= SCM_LONG_BIT-1)
|
||||
if (ee <= SCM_INTPTR_T_BIT-1)
|
||||
{
|
||||
/* Everything fits within a long. To avoid undefined behavior
|
||||
when shifting negative numbers, we do all operations using
|
||||
unsigned values, and then convert to signed at the end. */
|
||||
unsigned long unn = nn;
|
||||
unsigned long below = unn & ((1UL << ss) - 1); /* below start */
|
||||
unsigned long above = unn & ~((1UL << ee) - 1); /* above end */
|
||||
unsigned long fmask = ((1UL << ww) - 1) << ss; /* field mask */
|
||||
unsigned long ff = unn & fmask; /* field */
|
||||
unsigned long uresult = (above
|
||||
/* Everything fits within a intptr_t. To avoid undefined
|
||||
behavior when shifting negative numbers, we do all
|
||||
operations using unsigned values, and then convert to
|
||||
signed at the end. */
|
||||
uintptr_t unn = nn;
|
||||
uintptr_t below = unn & ((1UL << ss) - 1); /* below start */
|
||||
uintptr_t above = unn & ~((1UL << ee) - 1); /* above end */
|
||||
uintptr_t fmask = ((1UL << ww) - 1) << ss; /* field mask */
|
||||
uintptr_t ff = unn & fmask; /* field */
|
||||
uintptr_t uresult = (above
|
||||
| ((ff << cc) & fmask)
|
||||
| ((ff >> (ww-cc)) & fmask)
|
||||
| below);
|
||||
long result;
|
||||
intptr_t result;
|
||||
|
||||
if (uresult > LONG_MAX)
|
||||
if (uresult > INTPTR_MAX)
|
||||
/* The high bit is set in uresult, so the result is
|
||||
negative. We have to handle the conversion to signed
|
||||
integer carefully, to avoid undefined behavior. First we
|
||||
compute ~uresult, equivalent to (ULONG_MAX - uresult),
|
||||
which will be between 0 and LONG_MAX (inclusive): exactly
|
||||
the set of numbers that can be represented as both signed
|
||||
and unsigned longs and thus convertible between them. We
|
||||
the set of numbers that can be represented as both intptr_t
|
||||
and uintptr_p and thus convertible between them. We
|
||||
cast that difference to a signed long and then substract
|
||||
it from -1. */
|
||||
result = -1 - (long) ~uresult;
|
||||
result = -1 - (intptr_t) ~uresult;
|
||||
else
|
||||
result = (long) uresult;
|
||||
result = (intptr_t) uresult;
|
||||
|
||||
return scm_from_long (result);
|
||||
return scm_from_intptr_t (result);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -230,31 +231,31 @@ SCM_DEFINE (scm_srfi60_reverse_bit_field, "reverse-bit-field", 3, 0, 0,
|
|||
"@end example")
|
||||
#define FUNC_NAME s_scm_srfi60_reverse_bit_field
|
||||
{
|
||||
long ss = scm_to_long (start);
|
||||
long ee = scm_to_long (end);
|
||||
long swaps = (ee - ss) / 2; /* number of swaps */
|
||||
intptr_t ss = scm_to_intptr_t (start);
|
||||
intptr_t ee = scm_to_intptr_t (end);
|
||||
intptr_t swaps = (ee - ss) / 2; /* number of swaps */
|
||||
mpz_t b;
|
||||
|
||||
if (SCM_I_INUMP (n))
|
||||
{
|
||||
long nn = SCM_I_INUM (n);
|
||||
intptr_t nn = SCM_I_INUM (n);
|
||||
|
||||
if (ee <= SCM_LONG_BIT-1)
|
||||
if (ee <= SCM_INTPTR_T_BIT-1)
|
||||
{
|
||||
/* all within a long */
|
||||
long smask = 1L << ss;
|
||||
long emask = 1L << (ee-1);
|
||||
/* all within a intptr_t */
|
||||
intptr_t smask = 1L << ss;
|
||||
intptr_t emask = 1L << (ee-1);
|
||||
for ( ; swaps > 0; swaps--)
|
||||
{
|
||||
long sbit = nn & smask;
|
||||
long ebit = nn & emask;
|
||||
intptr_t sbit = nn & smask;
|
||||
intptr_t ebit = nn & emask;
|
||||
nn ^= sbit ^ (ebit ? smask : 0) /* zap sbit, put ebit value */
|
||||
^ ebit ^ (sbit ? emask : 0); /* zap ebit, put sbit value */
|
||||
|
||||
smask <<= 1;
|
||||
emask >>= 1;
|
||||
}
|
||||
return scm_from_long (nn);
|
||||
return scm_from_intptr_t (nn);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -319,22 +320,22 @@ SCM_DEFINE (scm_srfi60_integer_to_list, "integer->list", 1, 1, 0,
|
|||
#define FUNC_NAME s_scm_srfi60_integer_to_list
|
||||
{
|
||||
SCM ret = SCM_EOL;
|
||||
unsigned long ll;
|
||||
uintptr_t ll;
|
||||
|
||||
if (SCM_UNBNDP (len))
|
||||
len = scm_integer_length (n);
|
||||
ll = scm_to_ulong (len);
|
||||
ll = scm_to_uintptr_t (len);
|
||||
|
||||
if (SCM_I_INUMP (n))
|
||||
{
|
||||
scm_t_inum nn = SCM_I_INUM (n);
|
||||
for (unsigned long i = 0; i < ll; i++)
|
||||
intptr_t nn = SCM_I_INUM (n);
|
||||
for (uintptr_t i = 0; i < ll; i++)
|
||||
ret = scm_cons (scm_from_bool (scm_integer_logbit_ui (i, nn)), ret);
|
||||
}
|
||||
else if (SCM_BIGP (n))
|
||||
{
|
||||
struct scm_bignum *nn = scm_bignum (n);
|
||||
for (unsigned long i = 0; i < ll; i++)
|
||||
for (uintptr_t i = 0; i < ll; i++)
|
||||
ret = scm_cons (scm_from_bool (scm_integer_logbit_uz (i, nn)), ret);
|
||||
}
|
||||
else
|
||||
|
@ -357,7 +358,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer", 1, 0, 0,
|
|||
"@end example")
|
||||
#define FUNC_NAME s_scm_srfi60_list_to_integer
|
||||
{
|
||||
long len;
|
||||
intptr_t len;
|
||||
|
||||
/* strip high zero bits from lst; after this the length tells us whether
|
||||
an inum or bignum is required */
|
||||
|
@ -369,7 +370,7 @@ SCM_DEFINE (scm_srfi60_list_to_integer, "list->integer", 1, 0, 0,
|
|||
if (len <= SCM_I_FIXNUM_BIT - 1)
|
||||
{
|
||||
/* fits an inum (a positive inum) */
|
||||
long n = 0;
|
||||
intptr_t n = 0;
|
||||
while (scm_is_pair (lst))
|
||||
{
|
||||
n <<= 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue