From 7db99f963e05b8dc5a17a50833424a3a5656cc89 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 14 Jul 2024 09:05:28 -0400 Subject: [PATCH 1/2] Add additional space to store 64-bit hash codes on 32-bit machines On 32-bit machines, thread local variables are stored in arrays of 32-bit chunks of memory. But now that we use 64-bit hash codes, we were getting the hash counter by concatenating two adjacent elements of the array, giving us unexpected results. We add a new thread local variable to store these extra 32 bits, fixing this issue. --- M2/Macaulay2/d/expr.d | 3 +++ 1 file changed, 3 insertions(+) diff --git a/M2/Macaulay2/d/expr.d b/M2/Macaulay2/d/expr.d index 48792789f53..a4e581e1382 100644 --- a/M2/Macaulay2/d/expr.d +++ b/M2/Macaulay2/d/expr.d @@ -27,6 +27,9 @@ threadCounter := 0; threadLocal HashCounter := ( threadCounter = threadCounter + 1; hash_t(1000000 + 3 + (threadCounter-1) * 10000 )); +-- give 32-bit machines enough space to store a 64-bit hash code +-- TODO: instead, allow 64-bit entries in the array of thread local variables +threadLocal HashCounterExtraBits := 0; export nextHash():hash_t := ( if HashCounter == Ccode(hash_t, "18446744073709551615ull") -- check for integer overflow From 137c2269b6978282fc76ed4197366ee7799e793d Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Sun, 14 Jul 2024 09:15:44 -0400 Subject: [PATCH 2/2] Update hash code test for RR objects for 32-bit machines Also fix the comments -- these hash codes differ based on 32-bit v. 64-bit, not endianness. --- M2/Macaulay2/m2/basictests/hashcodes.m2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/M2/Macaulay2/m2/basictests/hashcodes.m2 b/M2/Macaulay2/m2/basictests/hashcodes.m2 index 435fa3f74bd..92b4f0ccbc2 100644 --- a/M2/Macaulay2/m2/basictests/hashcodes.m2 +++ b/M2/Macaulay2/m2/basictests/hashcodes.m2 @@ -22,7 +22,7 @@ assert( (hash true) === 444777 ) assert( (hash false) === 777333 ) -- these might change if our floating point implementation changes, but let's check anyway: -assert( hash 1.23p200 === 18446744072207201388 -* big endian *- or hash 1.23p200 == -640232547 -* little endian *- ) +assert( hash 1.23p200 === 18446744072207201388 -* 64-bit *- or hash 1.23p200 == 18446744073069319069 -* 32-bit *- ) -- Local Variables: -- compile-command: "make -C $M2BUILDDIR/Macaulay2/packages/Macaulay2Doc/basictests hashcodes.okay"