简体   繁体   中英

Difference between shift operation using concatenate operator {} and shift operator << in verilog

reg [3:0]a; reg in;

  1. a <= {a[2:0],in}; //Using Concatenate Operator

  2. a <= a<<1; //Using Shift operator

What is the difference between 1 & 2 in terms of a) Speed of operation. b) Hardware Implementation in synthesis.

Which one is prefer generally?

the << shift operators shifts bits left by the specified number. It will shift 0 in the least significant bit:

a: 0011 << 1 --> 0110
                    ^ -- shifted in bit

the concat operator from your example concatenates some bits from a and the in value:

a: 0011
in: 1
{a[2:0], in} --> 0111

however, the following does the same as the shift by one:

{a[2:0], 1'b0} --> 0110

Assuming that you replace in with 1'b0 to make the two examples behave identically, these will synthesize to the exact same hardware implementation with any modern synthesis tool. I would be surprised if there is a simulation performance difference, but it's in any case not something I would worry about. I would suggest to use the syntax you find to be most readable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM