Bidirectional shifting in VHDL efficient implementation

vhdl

I need to implement a variant of the bidirectional shifting (I basically need to process the part of the less significant bits that are being lost during the right shifting specifically). Since it is a slight variant I need to implement, I basically was wondering how efficiently could it be modelled a bidirectional shifting in vhdl, leaving the specific processing I need to do for the moment.

Assuming the shift parameter n could be both positive or negative I would perform in parallel left shifting and right shifting by n, and then using the sign of n I would select between the left or the right shift (so basically I would use the concurrent stamenent when ... else). I'm not entirely sure of the efficiency of such code because the compiler would instantiate probably both shifters. Is there a best way to achieve such result but more efficiently? (I also would like to avoid if possible working at bit level to implement such shifter, i'm just asking if there's some kind of "recipe" that it's worth to be aware of).

By the way… I'm speaking of "barrel shifter" not "shift register", I'm not interesting in keeping the result at all.

Best Answer

Don't worry about it. A barrel shifter is just an array of multiplexers. If you have N different shift amounts, then the multiplexers need to have N inputs each. It doesn't matter if the shift amounts are positive or negative. The amount of logic synthesized in any case will be exactly the same.