YosysHQ / yosys

Yosys Open SYnthesis Suite
https://yosyshq.net/yosys/
ISC License
3.42k stars 872 forks source link

hashlib: Add some more primes #4471

Closed georgerennie closed 2 months ago

georgerennie commented 3 months ago

Add some primes as suggested in comments in #4458. This allows larger hashtables to be allocated for very big designs. The new primes match the geometric ratio of ~1.25 used for the others and don't overflow 4 byte ints.

jix commented 3 months ago

463830273 and 1132398207 aren't primes. I've used the following sage math code to compute the extended the sequence:

a = [23]
def next_or_same_prime(n):
    # this matches the nextprime OEIS uses here
    # sage's next_prime always returns a greater prime and requires an integer argument
    return next_prime(ceil(n) - 1)
while a[-1] < (1<<31):
    a.append(next_or_same_prime(a[-1] + (a[-1] + 1) / 4))
a.pop() # remove the last prime that overflows a 32-bit signed int
print(a)
[23, 29, 37, 47, 59, 79, 101, 127, 163, 211, 269, 337, 431, 541, 677, 853, 1069, 1361, 1709, 2137, 2677, 3347, 4201, 5261, 6577, 8231, 10289, 12889, 16127, 20161, 25219, 31531, 39419, 49277, 61603, 77017, 96281, 120371, 150473, 188107, 235159, 293957, 367453, 459317, 574157, 717697, 897133, 1121423, 1401791, 1752239, 2190299, 2737937, 3422429, 4278037, 5347553, 6684443, 8355563, 10444457, 13055587, 16319519, 20399411, 25499291, 31874149, 39842687, 49803361, 62254207, 77817767, 97272239, 121590311, 151987889, 189984863, 237481091, 296851369, 371064217, 463830313, 579787991, 724735009, 905918777, 1132398479, 1415498113, 1769372713]
georgerennie commented 3 months ago

Oh you are totally right, I'm not even quite sure how I managed to mess that one up, I was obviously not fully awake yesterday.