Reputation: 184
What are the round braces doing in this code in Verilog?
rx_wb_valid <= (wb_memaddr <= { rx_len[(10+1):2] });
rx_wb_valid
is a 1-bit register
wb_memaddr
is a 10-bit register
rx_len
is a 12-bit register
Upvotes: 1
Views: 344
Reputation: 42798
You really need to show more context than what you have written. If you had the statement:
begin
some_var <= rx_wb_valid <= (wb_memaddr <= { rx_len[(10+1):2] });
end
The round braces change the default left-to-right precedence rules which would have been interpreted as
begin
some_var <= (rx_wb_valid <= wb_memaddr) <= { rx_len[(10+1):2] };
end
The compiler sees the first variable name followed by an assignment operator (=, <=) at the beginning of a statement and it knows what follows must be an expression. You are not allowed to have assignment operators within an expression in Verilog (SystemVerilog does allow certain cases). Within an expression, round parenthesis ()
are used to change the default precedence, but can also be used for clarity as in your example.
Curly braces {}
are the concatenation operator. Normally a concatenation has several operands, but there is one particular use with only one operand. Since each operand of a concatenation is self-determined, you can use it to prevent extensions before applying operations. For example, if you had the following:
rx_wb_valid <= wb_memaddr <= ~rx_len[3:2];
Since wb_memaddr
is a 10-bit variable, it would extend rx_len[3:2]
by padding 8 bits with 0 before negating the 10-bits. Those padded bits would become 1's. But by writing:
rx_wb_valid <= wb_memaddr <= {~rx_len[3:2]};
it would negate the 2-bits of rx_len[3:2]
before padding the the 8-bits, leaving those bits 0's.
Upvotes: 1
Reputation: 62236
The parentheses, ()
, are optional in your line of code. Your code should behave the same without them. However, I think they make your code more readable since they clearly separate the left <=
operator (nonblocking assignment) from the right <=
operator (comparison).
The curly braces, {}
, are also optional there. I think it is better to remove them in this case.
Upvotes: 2