9595
9696-- NOTE: the LuaJIT bitwise operations we have are not 64-bit
9797-- so we need to implement them ourselves. Lua uses 53-bit doubles.
98+ HIGH_MASK_53 = 0x1FFFFF
9899function OR64 (a , b )
99100 -- Split into high and low 32-bit parts
100101 local ah = math.floor (a / 0x100000000 )
@@ -107,7 +108,7 @@ function OR64(a, b)
107108 local low = bit .bor (al , bl )
108109
109110 -- Combine the results
110- return bit .band (high , 0x7FF ) * 0x100000000 + low
111+ return bit .band (high , HIGH_MASK_53 ) * 0x100000000 + low
111112end
112113
113114function AND64 (a , b )
@@ -122,7 +123,7 @@ function AND64(a, b)
122123 local low = bit .band (al , bl )
123124
124125 -- Combine the results
125- return bit .band (high , 0x7FF ) * 0x100000000 + low
126+ return bit .band (high , HIGH_MASK_53 ) * 0x100000000 + low
126127end
127128
128129function XOR64 (a , b )
@@ -137,7 +138,7 @@ function XOR64(a, b)
137138 local low = bit .bxor (al , bl )
138139
139140 -- Combine the results
140- return bit .band (high , 0x7FF ) * 0x100000000 + low
141+ return bit .band (high , HIGH_MASK_53 ) * 0x100000000 + low
141142end
142143
143144function NOT64 (a )
@@ -155,7 +156,16 @@ function NOT64(a)
155156
156157 -- Use bit operations to combine the results
157158 -- This avoids potential floating-point precision issues
158- return bit .band (high , 0x7FF ) * 0x100000000 + low
159+ return bit .band (high , HIGH_MASK_53 ) * 0x100000000 + low
160+ end
161+
162+ function strHex64 (value )
163+ -- Split into high and low 32-bit parts
164+ local high = math.floor (value / 0x100000000 )
165+ local low = value % 0x100000000
166+
167+ -- Stringify as two 8-digit hex values
168+ return string.format (" 0x%08X%08X" , high , low )
159169end
160170
161171ModFlag = { }
0 commit comments