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

Inconsistency in Validation Framework #97

Closed
EAlexJ opened this issue Jun 20, 2023 · 1 comment
Closed

Inconsistency in Validation Framework #97

EAlexJ opened this issue Jun 20, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@EAlexJ
Copy link

EAlexJ commented Jun 20, 2023

The following statement is not allowed by the validator
extern char MEM[1 << XLEN] [[is_main_mem]];
Since << is not allowed in the "[..]" operator.
Fixing it by introducing a variable like so:

unsigned<XLEN+1> MEMSIZE = 1 << XLEN;
extern char MEM[MEMSIZE] [[is_main_mem]];

Does not work, since 'XLEN+1' is not allowed in the type declaration.

Creating a new variable like so:

unsigned int XLEN;
unsigned<33> XLENP = XLEN +1;

unsigned<XLENP> MEMSIZE = 1 << XLEN;
extern char MEM[MEMSIZE] [[is_main_mem]];

seems to be the only option, since casting in constant expressions like this is not allowed either:
unsigned int XLENP = (unsigned int)(XLEN +1);

This is counterintuitive, there should be no need for enlarged datatypes.

Casting in declarations should be allowed.
The best solution to the original problem is to allow the << Operator inside the extern array declaration.

Edit:
I have spoken too soon, the "Fix" unsigned<XLENP> MEMSIZE = 1 << XLEN; is also just a shift operation which after all is not allowed in any declarations.
This means shift operations are not usable at all in declarations.

@EAlexJ EAlexJ added the bug Something isn't working label Jun 20, 2023
@AtomCrafty
Copy link
Contributor

AtomCrafty commented Jun 20, 2023

You are right, none of the bitwise operators are currently supported in constant expressions.

If I recall correctly, we pushed it down the line due to some open questions regarding the semantics of the shift operator when used in constant expressions. Based on the the current type rules of the shift operator, expressions of the form 1 << n will always evaluate to zero for n != 0, because the result must always have type unsigned<1>.

Btw, you can use XLEN+1 in a type specifier, but it needs to be parenthesized like this, because otherwise the '>' would conflict with the greater than operator in the grammar: unsigned<(XLEN+1)>. Regarding the cast: I had previously made the proposal that type rules can be ignored for constant assignments, as long as the calculated value fits in the assignment target. It is currently tracked as #75.

@eyck eyck closed this as completed Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants