Skip to content

Conversation

@andreaskurth
Copy link
Contributor

These were flagged by CI lint checks in lowRISC/opentitan#28997.

Copy link
Member

@nasahlpa nasahlpa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Andreas, adding a , should fix the failing CI.

Copy link
Contributor

@vogelpi vogelpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andreaskurth for the PR, I think we need another fix for the negative offsets as I don't think this is safe and as it doesn't comply with our style guide. See comments for details.

logic [11:0] neg_offset;
logic [31:0] instr;
neg_offset = ~{5'b00000, sp_offset, 2'b00} + 12'd1;
neg_offset = -{5'b00000, sp_offset, 2'b00};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is okay. I don't think it complies with our style guide, see https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md#signed-arithmetic

The term within { } is probably an unsigned logic and then you invert the sign. How it was before seems safer to me, but I am not sure what the lint warnings/errors were, the width seems fully defined for both operands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So according to the style guide maybe this would be a good substitution?

logic signed [11:0] neg_offset;
logic [31:0] instr;
neg_offset = 12'sh000 - signed'({5'b00000, sp_offset, 2'b00});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. The lint error that gets fixed here is on the explicit calculation of a two's complement, in the form of ~value + 1. I replaced this with -value, as suggested in the linter's manual. I also ran it through simulation to check that the result is correct.

The problem with a signed variable -- that is

logic signed [11:0] neg_offset;
neg_offset = -signed'({5'b00000, sp_offset, 2'b00});

is that the linter then complains about the subsequent part selects (e.g., neg_offset[4:0]) of that signed variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting back and forth between signed and unsigned should make everyone happy. Not pretty, but let's go with that.

imm[11:7] = '0;
imm[ 6:0] = cm_stack_adj(.rlist(rlist), .spimm(spimm));
if (decr) imm = ~imm + 12'd1;
if (decr) imm = -imm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, you're changing the sign of an unsigned logic, see https://github.com/lowRISC/style-guides/blob/master/VerilogCodingStyle.md#signed-arithmetic .

Copy link
Contributor Author

@andreaskurth andreaskurth Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an application of the linter's suggestion, and it behaves correctly in simulation.

If I make imm signed, the linter flags the subsequent assignment to an unsigned target (instr[31:20]) as well as the part selects.

Copy link
Contributor

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a suggestion for dealing with the signed variables.

logic [11:0] neg_offset;
logic [31:0] instr;
neg_offset = ~{5'b00000, sp_offset, 2'b00} + 12'd1;
neg_offset = -{5'b00000, sp_offset, 2'b00};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So according to the style guide maybe this would be a good substitution?

logic signed [11:0] neg_offset;
logic [31:0] instr;
neg_offset = 12'sh000 - signed'({5'b00000, sp_offset, 2'b00});

@andreaskurth
Copy link
Contributor Author

Merging to unblock lowRISC/opentitan#28997. If anyone thinks this should be done differently, we can follow up with another PR.

@andreaskurth andreaskurth added this pull request to the merge queue Jan 21, 2026
Merged via the queue into lowRISC:master with commit 75ef275 Jan 21, 2026
12 checks passed
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.

4 participants