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

-16'sd32768 is causing "vector literal too large error" #877

Closed
wants to merge 1 commit into from

Conversation

udif
Copy link
Contributor

@udif udif commented Jan 25, 2024

I started this PR hoping to complete it with the bug report, but it seems that slang first parses 16'sd32768, correctly assigning it a width of 17, and only then applies the unary minus, or at least that's what I think I figured out from the AST and printf-style debug code:

I put this in SVint.h:171 onwards:

            if (value < 0) {
                bitWidth = bitwidth_t(64 - std::countl_one(val) + 1);
                std::cout << "neg!\n";
            } else {
                bitWidth = bitwidth_t(64 - std::countl_zero(val) + 1);
                std::cout << "pos!\n";
            }

And ran the following code:

module t;
int t = -1;
wire [15:0]x = -16'sd32768;
endmodule

The code above only triggered the "pos" code path.
When is the "neg" code path ever used?

My best guess so far is a fix around here in OperatorExpressions.cpp:

        case SyntaxKind::UnaryMinusExpression:
            // Supported for both integral and real types. Result is same as input type.
            good = type->isNumeric();
            result->type = type;
            break;

Probably need to check the type and if it is constant integral type reduce its width by 1 if it is -2^N.

@udif
Copy link
Contributor Author

udif commented Jan 25, 2024

Closing because this is not a bug. My mistake.

@udif udif closed this Jan 25, 2024
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.

1 participant