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

Bad sizing of expression inside a size cast #1209

Closed
povik opened this issue Jan 11, 2025 · 2 comments
Closed

Bad sizing of expression inside a size cast #1209

povik opened this issue Jan 11, 2025 · 2 comments
Labels

Comments

@povik
Copy link
Contributor

povik commented Jan 11, 2025

Describe the bug
On occurence of a sizing cast syntax like (n)'(/expr/) where n is a positive integer, the standard says the following:

When changing the size, the cast shall return the value that a packed array type with a single [n-1:0] dimension would hold after being assigned the expression, where n is the cast size.

1800-2023, p. 141

As far as I can tell slang does not follow that, instead it might be applying self-determined sizing to /expr/ irrespective the value of n.

To Reproduce

This test fails as of f04d7a0 (current master)

TEST_CASE("Size cast upstream influence") {
    ScriptSession session;
    auto value = session.eval("(3)'(1'b1 << 2)");
    CHECK(value.integer() == 4);
}

Additional context

On p. 140 the standard also says the below, but the mention of padding/truncation is somewhat vague and not what other tools seem to be following, exactly:

If the casting type is a constant expression with a positive integral value, the expression in parentheses shall
be padded or truncated to the size specified. It shall be an error if the size specified is zero or negative.

Downstream issue povik/yosys-slang#78

@MikePopoloski
Copy link
Owner

Indeed, it looks like I misinterpreted the rule. I agree the intent is that it behave the same as an implicit cast.

@MikePopoloski
Copy link
Owner

Fixed in dfed278

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

No branches or pull requests

2 participants