-
Notifications
You must be signed in to change notification settings - Fork 791
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
[rom_ctrl,util] Rework memory collision check #24422
[rom_ctrl,util] Rework memory collision check #24422
Conversation
0499ba9
to
a68eac4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sensible to me (and I clearly did something a little silly with the original implementation). But I think we can be lazier: we don't actually care all that much about the collisions, only about whether they exist. So a better approach would probably be something like this: (completely untested!)
def first_collision(self) -> Optional[Tuple[int, int]]:
'''Return the address of the first pair of colliding addresses
If there is no such pair (which is hopefully the case), return None.
'''
known = {}
for idx, chunk in enumerate(self.chunks):
for word_idx, word in enumerate(chunk.words):
addr = chunk.base_addr + word_idx
if word in known:
return (known[word], addr)
else:
known[word] = addr
return None
Then the call site would look something like this:
collision = scr_mem.first_collision()
if collision is not None:
print(
'ERROR: This combination of ROM contents and scrambling\n'
' key results in one or more collisions where\n'
' different addresses have the same data.\n'
'\n'
' Looks like we\'ve been (very) unlucky with the\n'
' birthday problem. As a work-around, try again after\n'
' generating some different RndCnst* parameters.\n',
file=sys.stderr)
addr0, addr1 = collision
print(f'First colliding addresses: {addr0:#010x}, {addr1:#010x}')
return 1
Sure. I wrote the patch to get the exact same output as the original implementation. If only the first collision is of some interest, I can simplify this quite a bit. Pls let me know. |
a68eac4
to
5edaff0
Compare
Update the collision check implementation using a dict to traverse the chunks only once. Signed-off-by: Emmanuel Blot <[email protected]>
5edaff0
to
703b425
Compare
Hi @rswarbrick. Is this new version ok for you? It seems the CI fails with some unrelated issues to this change though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really sorry for not replying before. Yes, this looks really good to me!
cc @sameo |
Thanks |
As ROMs get bigger, scrambled memory collision checker in
mem.py
becomes slower.On my local machine using this revised implementation, scrambling the second rom only takes 1.75 seconds vs. 7.68 seconds with the previous implementation (> 4x speed up).
I've tested collisions detections forcing several of them and checking the collision report remains the same: