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

Handling of upper bits for array indices wider than 32 bits #1196

Open
larsclausen opened this issue Jan 1, 2025 · 2 comments
Open

Handling of upper bits for array indices wider than 32 bits #1196

larsclausen opened this issue Jan 1, 2025 · 2 comments

Comments

@larsclausen
Copy link
Collaborator

The current behavior for array indices wider than 32 bits is that the upper bits are silently truncated and the lower bits are used as the index E.g.

reg [32:0] i = {1'b1,32'h1};
integer a[2];
a[1] = 10;
$display(a[i]); // -> 10

In my opinion this should be treated as out-of-bounds instead. And it is if the index is constant. E.g.

integer a[2];
a[1] = 10;
$display(a[{1'b1,32'h1}]); // -> x

But we have a test that explicitly checks that upper bits for dynamic indices are discarded.

@caryr its been a while, but you created that test. Any thoughts on this?

@martinwhitaker
Copy link
Collaborator

I would be inclined to agree with you, but a quick test on some other simulators indicates they also truncate, either silently or with a warning. I found this discussion which relates, but doesn't reach any conclusion.

@caryr
Copy link
Collaborator

caryr commented Jan 3, 2025

I'll need to take a look. I don't remember the details without more context, but I think we are implicitly assuming that all this eventually gets flattened, normalized and limited to something that is addressed by 32-bits. Maybe the limiting is happening too early. There's also the issue that we do not use types with explicit widths (e.g. uint32_t, int64_t, etc.) so there is some variation depending on the environment.

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

No branches or pull requests

3 participants