2

Say I have 2 std_logic_vectors:

inputA : std_logic_vector(31 downto 0)
inputB:  std_logic_vector(31 downto 0)

How do I shift inputA by inputB using concatenation?

I know how to shift left or right by 1 place but can't figure out how to shift N places to the right (or left). Note: this is a clockless circuit, and can't use standard vhdl shift operators.

Other techniques or ideas other than concatenation would be appreciated as well.

4
  • You probably can't do this in a clockless manner, since you'd need to have a programmable shift register or perform multiple rounds in a normal shift register. Doing this in a clockless manner wouldn't make sense since you would require 2^32 different shift registers for each possible path, and even then you would probably still require a clock. Commented Sep 17, 2012 at 14:01
  • @slugonamission: It's perfectly feasible without a clock - it's just a big bag of muxes... also known as a barrel-shifter Commented Sep 17, 2012 at 14:25
  • @MartinThompson - don't you ideally need to clock the value into the muxes to prevent hazards though? Commented Sep 17, 2012 at 14:29
  • @slugonamission: at some point, yes it'll need some registers on the extremities of the shifter. Once they are there, the timing tools will sort the rest out for you. Commented Sep 17, 2012 at 14:34

2 Answers 2

7

The simplest way to do this would be to something like this:

library ieee;
use ieee.numeric_std.all;
...
output <= std_logic_vector(unsigned(inputA) srl to_integer(unsigned(inputB)));

(BTW, being a clockless circuit has nothing to do with being able to use shift operators or not. What determines that is data types. This shift operation will be turned into the same logic by a synthesizer as you would get if you wrote something more complex with case statements all expanded out by hand.)

Sign up to request clarification or add additional context in comments.

Comments

3

I prefer wjl's approach, but given you asked specifically for a method using concatenation, try this:

function variable_shift(i : std_logic_vector, num_bits : integer) 
   return std_logic_vector is
   constant zeros : std_logic_vector(num_bits-1 downto 0) := (others => '0');
begin
   return i(i'high-num_bits downto i'low) & zeros;
end function;

(It could be written to take a second std_logic_vector for the num_bits parameter, but as it's fundamentally a number, I'd always use a number-based type for it)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.