2 consecutive nonblocking assignments - verilog

Can someone explain what it means to assign two consecutive nonblocking assignments in a sequential always block?
For example:
always #(posedge clk) begin
a <= b <= c;
end

That can be more clearly coded as:
a <= (c >= b);
a is assigned the value of the expression "c is greater than or equal to b".
The 1st <= is the nonblocking assignment operator, whereas, the 2nd is the comparison operator.

That is not two consecutive non-blocking assignment.
That is a <= (b<=c);
b<=c evaluates to true (1) or false (0) and that value is assigned to a.
two consecutive non-blocking assignments is not a legal Verilog syntax

Related

bit-wise negation in systemVerilog [duplicate]

This question already has an answer here:
What happened to this simple verilog ~^ operator?
(1 answer)
Closed 2 years ago.
In the code below, I was expecting "b" to be 2'b00 since "a" has fewer bits than "b" and they are unsigned wire. However, in the simulating result, "b" is 2'b10.
wire a;
wire [1:0]b;
assign a = 1'b1;
assign b = ~a;
I have tried to set "b" to width 3, and this time "b" is 3'b110.
wire a;
wire [2:0]b;
assign a = 1'b1;
assign b = ~a;
At my understanding, if RHS has fewer bits than LHS, the unused bits of the LHS should be 0s. Can anyone please explain why this is happening?
In the 1st case, a is 1 bit wide, but the LHS (b) is 2 bits wide. The assignment to b forces all values to be the maximum width (2). Before the bitwise negation, a is left-extended with 0's, becoming 2'b01. And, ~(2'b01) is 2'b10.
The same is true when b is 3 bits wide.
Refer to IEEE Std 1800-2017, section 11.6.2 Example of expression bit-length problem.

signedness vs bit size

Given example below, with the simulators I've tried, the value of d2 is created by sign extending 4'sd2 - i1. From, my reading of the standard (1800-2012) I expect 4'sd2 - i1 to be treated as unsigned and zero extended in the same way as for d1.
What am I missing? Does the unsignedness of i1 somehow change as it is being widened from 2 to 4 bits? Thanks.
module sign_test(input clk, input /*unsigned*/ [1:0] i1,
output reg [7:0] d1, output reg [7:0] d2);
always #(posedge clk) begin
d1 = $unsigned(4'sd2 - i1); // this gets zero extended; the only possible values for 'd1' are 0, 1, 2 and 0x0f
d2 = 4'sd2 - i1; // this gets sign extended; the only possible values for 'd2' are 0, 1, 2 and 0xff
// but 11.8.1 says "4'sd2 - i1" should be unsigned:
// "-- For non-self-determined operands, the following rules apply:
// [...]
// -- If any operand is unsigned, the result is unsigned,
// regardless of the operator."
// and 'i1' is unsigned by default (adding "unsigned"
// explicitly doesn't change the behaviour).
end
endmodule
I think the reason for the difference is not to do with whether each expression is signed or unsigned, but instead to do with the number of bits Verilog uses to do the calculation.
This is a context-determined expression:
d2 = 4'sd2 - i1;
That means Verilog uses the maximum of all the widths involved (the widths of d2, 4'sd2 and i1, which is 8 (the width of d2). As you say unsigned arithmetic is done. With a value of 2'b11 for i1:
d2 = 00000010 - 00000011
which is
11111111
With
d1 = $unsigned(4'sd2 - i1);
however, the width of d1 is not taken into account, because of the call to the $unsigned system function. This makes the expression 4'sd2 - i1 a self-determined expression and so the bit width used for the calculation is 4 - the maximum of the widths of 4'sd2 and i1. So
0010 - 0011
is
1111
This is then zero-padded to
00001111
https://www.edaplayground.com/x/duY

What is >>>symbol in verilog?

May I know what is this symbol >>> in verilog. When should I use it? Thanks!
e.g
always #(posedge Clock) begin
if (Clear) begin
a < = c>>>8;
b < = d>>>16;
end
end
It is an arithmetic right shift operator (see page 19-20 of the link). It is the reverse case from Java (Java >> is arithmetic right shift, while >>> is logical right shift).
Arithmetic right shift is to handle case when the number right-shifted is positive/negative with this behavior:
Shift right specified number of bits, fill with value of sign bit if
expression is signed, othewise fill with zero
To illustrate, if you have signed expression with value of, say like this:
1000 1100
--------- >>> 2
1110 0011 //note the left most bits are 1
But for unsigned:
1000 1100
--------- >>> 2
0010 0011
The left most will be filled with 0.

What is "??" in Verilog casez?

I have a module below:
module bai1c(a, b0, b1, b2, b3, c);
input [2:0] a;
input [3:0] b0, b1, b2, b3;
output reg[3:0] c;
always #(a or b0 or b1 or b2 or b3) begin
casez(a)
3'b000: c = b0;
3'b001: c = b1;
3'b010: c = b2;
3'b011: c = b3;
3'b1??: c = 4'b0000;
endcase
end
endmodule
What kind of circuit will be synthesized?
When the condition 3'b1?? happen? (what ?? is?)
? is a don't care value - i.e. it will match either 0, 1 or z. So the 3'b1?? case will occur whenever the first bit is 1, no matter what the other two bits are.
The circuit is basically a 4:1 multiplexer, selecting one of b0,b1,b2,b3, with an added select bit on a that forces the output to 0, no matter what the other two select bits are.

Fixed combinatorial logic

I have question.
my code is
module pulsing(OUT, an1, an2, or1);
input wire an1, an2, or1;
output wire OUT;
wire afa;
and andik(afa,an1,an2);
or orik(OUT,afa,or1);
endmodule
I got after synthesis one 3bit LUT result, but I really need 2 different
LUTS .
How can I implement it without any sequential logic(just wires and
LUTs)?
Thanks!
You can define LUT2 as for AND gate:
LUT2 #(.INIT(4'h1)) U1(.O(O),
.I0(I1),
.I1(I2));
And OR gate respectively as:
LUT2 #(.INIT(4'hE)) U1(.O(O),
.I0(I1),
.I1(I2));
Notice the .INIT values. These are the truth table results of these Boolean functions.
I1 I0 O
0 0 B0
0 1 B1
1 0 B2
1 1 B3
From this you can implement any 2 input Boolean function with a single LUT2. For example XOR would require .INIT(4'h6).

Resources