The operator "<<" in verilog

I have Verilog code that has a line like this:

 parameter ADDR_WIDTH = 8 ; parameter RAM_DEPTH = 1 << ADDR_WIDTH; 

here that will be stored in RAM_DEPTH and making the operator << here.

+4
source share
3 answers

<< - a binary shift left Offset 1 8 seats.

 4'b0001 << 1 => 4'b0010 

>> - binary right shift, adding 0 to the MSB.
>>> - a shift from fixing that supports MSB value if left input signed.

 4'sb1011 >> 1 => 0101 4'sb1011 >>> 1 => 1101 

Three ways to specify the left operand:

 module shift; logic [3:0] test1 = 4'b1000; logic signed [3:0] test2 = 4'b1000; initial begin $display("%b", $signed(test1) >>> 1 ); //Explicitly set as signed $display("%b", test2 >>> 1 ); //Declared as signed type $display("%b", 4'sb1000 >>> 1 ); //Signed constant $finish; end endmodule $ signed (test1) >>> module shift; logic [3:0] test1 = 4'b1000; logic signed [3:0] test2 = 4'b1000; initial begin $display("%b", $signed(test1) >>> 1 ); //Explicitly set as signed $display("%b", test2 >>> 1 ); //Declared as signed type $display("%b", 4'sb1000 >>> 1 ); //Signed constant $finish; end endmodule 4'sb1000 >>> module shift; logic [3:0] test1 = 4'b1000; logic signed [3:0] test2 = 4'b1000; initial begin $display("%b", $signed(test1) >>> 1 ); //Explicitly set as signed $display("%b", test2 >>> 1 ); //Declared as signed type $display("%b", 4'sb1000 >>> 1 ); //Signed constant $finish; end endmodule 
+14
source

1 << ADDR_WIDTH means that 1 will be shifted by 8 bits to the left and will be assigned as the value for RAM_DEPTH .

In addition, 1 << ADDR_WIDTH also means 2 ^ ADDR_WIDTH.

Given ADDR_WIDTH = 8 , then 2^8 = 256 and it will be important for RAM_DEPTH

+4
source

<< - left shift operator, as in many other languages.

Here RAM_DEPTH is 1 is shifted to the left on 8 bits , which is equivalent to 2^8 or 256 .

+3
source

Source: https://habr.com/ru/post/1491769/


All Articles