What is the Hardware synthesized for << operator

2.3k Views Asked by At

I have recently started working on HDL , while going through right/left shift operators what i have studied in my school was they are continous D FlipFlops that shift data bit by bit to result the output.

I assumed same will be done over while synthesizing them in hdl, but i couldn't see the same hardware in verilog synthesis , its appearing like simple concatenation operations in the RTL_LSHIFT.

Could some one explain me how actually the hardware will be inside this RTL_LSHIFT. If it is FF's then why there is no clock input to the BLock.

I know all the functionality of arithmetic and logic shift, I need the hardware synthesized in HDL.

Code:

module doubt(
    input[5:0] a,
    input [5:0] b,
    input clk,
    output reg [9:0] c,
    output reg [9:0] d
    );
    reg s1,s2;
    always @ ( posedge clk)
   begin 
   
   c <= (a<<1);
   d<= (b<<4);
    end  
endmodule

enter image description here

3

There are 3 best solutions below

2
On

In hardware, a left/right shifter is a simple set of multiplexers, take a look at the barrel shifter's design. Also, it depends on the EDA synthesizer how this is inferred and possibly optimized.

Barrel Shifter

0
On

The real Flip-Flops reside in the RTL_REG. The RTL_LSHIFT rearranges bit order of input vectors. I'm not familiar with the tool you used to generate this schematic (maybe from Xilinx I think), so I don't know what I0/I1/I2 all about either. In addtion, if your question is limited to fixed shift position, like left shift by exactly 2 bits, we'd like to use this concatenation form out <= {in[3:0], 2'b0}; (givenout and in are both 6-bit signals) instead. This makes our code more precise, and reduces potential bugs. Sorry that due to time and the computer I'm currently working on, I have no suitable tools to draw a schematic.

0
On

For a constant shift, wires are used. You just wire each input bit to the right output position. No other parts are needed.

In your example, a[0] is wired to the d input of c_reg[1], a[1] is wired to the d input of c_reg[2], etc.. The unassigned bits are wired to 0. Because c[7:9] are always 0, your tool has wired the outputs directly to 0, without a flip flop.

In an FPGA, the wires are themselves multiplexers programmed by the bitstream that is downloaded to the FPGA, but conceptually a fixed shift is still a wire.

In other implementation technologies and/or optimizers, I am sure c[0] will be wired to 0 as well.

If the shift is not constant you need the barrel shifter described by m4j0rt0m.