0
\$\begingroup\$

I have the same question as here: How to truncate an expression bit width in Verilog?

But I was hoping that in 2023, there would be more interesting answers that in 2013!

My specific use-case:

localparam logic [31:0] BAR0_OFFSET_MASK = {32{1'b1}} << (10);

Some tools complains that LHS is 32 whereas RHS is 42, and I would like to select part of the result of the shift operation without creating a temporary variable or a function.

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Nov 27, 2023 at 16:02
\$\endgroup\$
1
  • \$\begingroup\$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. \$\endgroup\$ Commented Nov 27, 2023 at 22:45

1 Answer 1

1
\$\begingroup\$

Tools that complain that the RHS of the assignment width is 42 bits are incorrect. The width of a shift operation is determined by the width of its left operand.

Regardless, SystemVerilog added a select in a concatenation

localparam logic [31:0] BAR0_OFFSET_MASK = { {32{1'b1}} << (10) }[31:0];

You could also use casts

localparam logic [31:0] BAR0_OFFSET_MASK = 32'( 32'('1) << (10)) ;
answered Nov 27, 2023 at 18:33
\$\endgroup\$
1
  • \$\begingroup\$ Many thanks for the very fast answer! I won't name the tool that begins with Spy and finish with drink... Great to see that the language advanced. \$\endgroup\$ Commented Nov 28, 2023 at 7:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.