Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashlib: Add some more primes #4471

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

georgerennie
Copy link
Contributor

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.

* Add some primes as suggested in YosysHQ#4458. This allows larger hashtables
  to be allocated for very big designs
@jix
Copy link
Member

jix commented Jul 2, 2024

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants