Advertisement
madegoff

Shifter

Jun 26th, 2023 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Barrelshifter fuer LSL, LSR, ASR, ROR mit Shiftweiten von 0 bis 3 (oder
  3. -- generisch n-1) Bit.
  4. --------------------------------------------------------------------------------
  5. -- Datum: ??.??.2013
  6. -- Version: ?.?
  7. --------------------------------------------------------------------------------
  8. library ieee;
  9. use ieee.std_logic_1164.all;
  10. use ieee.numeric_std.all;
  11. use ieee.std_logic_signed.all;
  12. --use ieee.math_real.all;
  13.  
  14. entity ArmBarrelShifter is
  15. --------------------------------------------------------------------------------
  16. -- Breite der Operanden (n) und die Zahl der notwendigen
  17. -- Multiplexerstufen (m) um Shifts von 0 bis n-1 Stellen realisieren zu
  18. -- koennen. Es muss gelten: ???
  19. --------------------------------------------------------------------------------
  20. generic (OPERAND_WIDTH : integer := 4;
  21. SHIFTER_DEPTH : integer := 2;
  22. );
  23. port ( OPERAND : in std_logic_vector(OPERAND_WIDTH-1 downto 0);
  24. MUX_CTRL : in std_logic_vector(1 downto 0);
  25. AMOUNT : in std_logic_vector(SHIFTER_DEPTH-1 downto 0);
  26. ARITH_SHIFT : in std_logic;
  27. C_IN : in std_logic;
  28. DATA_OUT : out std_logic_vector(OPERAND_WIDTH-1 downto 0);
  29. C_OUT : out std_logic
  30. );
  31. end entity ArmBarrelShifter;
  32.  
  33. architecture structure of ArmBarrelShifter is
  34.  
  35. signal data: std_logic_vector(OPERAND_WIDTH-1 downto 0);
  36.  
  37. begin
  38.  
  39.  
  40. --Linksshifter
  41. lsl_k : for k in 0 to SHIFTER_DEPTH-1 generate
  42. --erste ebene
  43. lsl_i : for i in 0 to OPERAND_WIDTH-1 generate
  44.  
  45. С_OUT <= C_IN when C_IN = '0' else
  46. data(OPERAND_WIDTH); --MSB
  47. data(i) <= OPERAND(i) when AMOUNT(k) = '0' else
  48. C_IN when i <= k else
  49. OPERAND(i-1);
  50.  
  51.  
  52. end generate;
  53.  
  54. end generate;
  55.  
  56. --Rechtsshifter hier benutzen wir OPERAND(i) wobei es eig data(i) sein muss damit es auch bei ebenen > 1 funktioniert
  57. lsr_k : for k in 0 to SHIFTER_DEPTH-1 generate
  58. --erste ebene
  59. lsr_i: for i in OPERAND_WIDTH-1 downto 0 generate
  60.  
  61. С_OUT <= C_IN when C_IN = '0' else
  62. data(0); --LSB
  63. data(i) <= OPERAND(i) when AMOUNT(k) = '0' else
  64. C_IN when i > (SHIFTER_DEPTH - k) else
  65. OPERAND(i+1);
  66.  
  67. end generate;
  68.  
  69. end generate;
  70.  
  71. --Rechtsshifter A
  72. asr_k : for k in 0 to SHIFTER_DEPTH-1 generate
  73. --erste ebene
  74. asr_i: for i in OPERAND_WIDTH-1 downto 0 generate
  75.  
  76. data(i) <= OPERAND(i) when AMOUNT(k) = '0' else
  77. OPERAND(OPERAND_WIDTH-1) when i > (SHIFTER_DEPTH - k) else
  78. OPERAND(i+1);
  79.  
  80. end generate;
  81.  
  82. end generate;
  83.  
  84.  
  85. --ROTATION
  86. rotate_k : for k in 0 to SHIFTER_DEPTH-1 generate
  87. -- Erste Ebene
  88. rotate_i : for i in 0 to OPERAND_WIDTH-1 generate
  89.  
  90. С_OUT <= C_IN when C_IN = '0' else
  91. data(0); --LSB
  92. data(i) <= OPERAND(i) when AMOUNT(k) = '0' else
  93. OPERAND((i + 1 + k) mod OPERAND_WIDTH);
  94. end generate;
  95. end generate;
  96.  
  97. DATA_OUT <= data;
  98. end architecture structure;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement