| 1 |
5 |
leonous |
--------------------------------------------------------------------------------
|
| 2 |
|
|
--------------------------------------------------------------------------------
|
| 3 |
|
|
-- Module - Introduction to VLSI Design [03ELD005]
|
| 4 |
|
|
-- Lecturer - Dr V. M. Dwyer
|
| 5 |
|
|
-- Course - MEng Electronic and Electrical Engineering
|
| 6 |
|
|
-- Year - Part D
|
| 7 |
|
|
-- Student - Sahrfili Leonous Matturi A028459 [elslm]
|
| 8 |
|
|
--------------------------------------------------------------------------------
|
| 9 |
|
|
--------------------------------------------------------------------------------
|
| 10 |
|
|
-- Final coursework 2004
|
| 11 |
|
|
--
|
| 12 |
|
|
-- Details: Design and Layout of an ALU
|
| 13 |
|
|
--------------------------------------------------------------------------------
|
| 14 |
|
|
--------------------------------------------------------------------------------
|
| 15 |
|
|
|
| 16 |
|
|
-- Description : ALU barrel shifter
|
| 17 |
|
|
-- Entity : alu_barrel_shifter
|
| 18 |
|
|
-- Architecture : structural
|
| 19 |
|
|
-- Created on : 07/03/2004
|
| 20 |
|
|
|
| 21 |
|
|
library ieee;
|
| 22 |
|
|
|
| 23 |
|
|
use ieee.std_logic_1164.all;
|
| 24 |
|
|
use ieee.std_logic_unsigned.all;
|
| 25 |
|
|
use ieee.std_logic_arith.all;
|
| 26 |
|
|
|
| 27 |
|
|
entity alu_barrel_shifter is
|
| 28 |
|
|
generic (
|
| 29 |
|
|
adder_width : integer := 8
|
| 30 |
|
|
);
|
| 31 |
|
|
port (
|
| 32 |
|
|
x : in std_logic_vector(adder_width - 1 downto 0) ;
|
| 33 |
|
|
y : in std_logic_vector(adder_width - 1 downto 0) ;
|
| 34 |
|
|
z : out std_logic_vector(adder_width - 1 downto 0) ;
|
| 35 |
|
|
c : out std_logic ;
|
| 36 |
|
|
direction : in std_logic
|
| 37 |
|
|
);
|
| 38 |
|
|
end alu_barrel_shifter;
|
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
|
|
architecture structural of alu_barrel_shifter is
|
| 42 |
|
|
|
| 43 |
|
|
signal Yor, Yreg, Xreg, Zreg, Zout
|
| 44 |
|
|
: std_logic_vector(adder_width downto 0);
|
| 45 |
|
|
signal Xrev, Zrev : std_logic_vector(adder_width downto 0);
|
| 46 |
|
|
|
| 47 |
|
|
signal Xmsb : std_logic;
|
| 48 |
|
|
|
| 49 |
|
|
|
| 50 |
|
|
function reverse(a : in std_logic_vector(Zreg'range)) return std_logic_vector is
|
| 51 |
|
|
-- reverse_range doesn't appear to work in NC-VHDL!!! but works in VHDL Simili
|
| 52 |
|
|
--variable a_reversed : std_logic_vector(Zreg'REVERSE_RANGE);
|
| 53 |
|
|
variable a_reversed : std_logic_vector(0 to adder_width);
|
| 54 |
|
|
begin
|
| 55 |
|
|
|
| 56 |
|
|
-- for i in a'reverse_range loop
|
| 57 |
|
|
for i in 0 to adder_width loop
|
| 58 |
|
|
a_reversed(i) := a(i);
|
| 59 |
|
|
end loop;
|
| 60 |
|
|
|
| 61 |
|
|
return a_reversed;
|
| 62 |
|
|
end reverse;
|
| 63 |
|
|
begin
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
----------------------------------------------------
|
| 67 |
|
|
-- shifter
|
| 68 |
|
|
----------------------------------------------------
|
| 69 |
|
|
Yreg <= '0' & (y and x"07");
|
| 70 |
|
|
Zrev <= reverse(Zreg);
|
| 71 |
|
|
Xrev <= reverse('0' & x) when (direction = '0') else
|
| 72 |
|
|
reverse(x & '0');
|
| 73 |
|
|
Xmsb <= x(x'high);
|
| 74 |
|
|
z <= Zout(Zout'high-1 downto 0) when (direction = '0') else
|
| 75 |
|
|
Xmsb & Zout(Zout'high-1 downto 1);
|
| 76 |
|
|
c <= Zout(Zout'high) when (direction = '0') else
|
| 77 |
|
|
Zout(Zout'low);
|
| 78 |
|
|
Zout <= Zreg when (direction = '0') else
|
| 79 |
|
|
Zrev;
|
| 80 |
|
|
Xreg <= '0' & x when (direction = '0') else
|
| 81 |
|
|
Xrev;
|
| 82 |
|
|
|
| 83 |
|
|
|
| 84 |
|
|
Yor(0) <= '1' when (Yreg = conv_std_logic_vector(0,adder_width + 1)) else
|
| 85 |
|
|
'0';
|
| 86 |
|
|
Yor(1) <= '1' when (Yreg = conv_std_logic_vector(1,adder_width + 1)) else
|
| 87 |
|
|
'0';
|
| 88 |
|
|
Yor(2) <= '1' when (Yreg = conv_std_logic_vector(2,adder_width + 1)) else
|
| 89 |
|
|
'0';
|
| 90 |
|
|
Yor(3) <= '1' when (Yreg = conv_std_logic_vector(3,adder_width + 1)) else
|
| 91 |
|
|
'0';
|
| 92 |
|
|
Yor(4) <= '1' when (Yreg = conv_std_logic_vector(4,adder_width + 1)) else
|
| 93 |
|
|
'0';
|
| 94 |
|
|
Yor(5) <= '1' when (Yreg = conv_std_logic_vector(5,adder_width + 1)) else
|
| 95 |
|
|
'0';
|
| 96 |
|
|
Yor(6) <= '1' when (Yreg = conv_std_logic_vector(6,adder_width + 1)) else
|
| 97 |
|
|
'0';
|
| 98 |
|
|
Yor(7) <= '1' when (Yreg = conv_std_logic_vector(7,adder_width + 1)) else
|
| 99 |
|
|
'0';
|
| 100 |
|
|
Yor(8) <= '0';
|
| 101 |
|
|
|
| 102 |
|
|
|
| 103 |
|
|
shifter : process (Xreg, Yreg, Yor)
|
| 104 |
|
|
variable Ztmp : std_logic;
|
| 105 |
|
|
begin
|
| 106 |
|
|
Zreg <= (others => '0');
|
| 107 |
|
|
for i in Zreg'range loop
|
| 108 |
|
|
Ztmp := '0';
|
| 109 |
|
|
if (i = 0) then
|
| 110 |
|
|
Zreg(i) <= Xreg(i) and Yor(0);
|
| 111 |
|
|
else
|
| 112 |
|
|
Ztmp := Xreg(i) and Yor(0);
|
| 113 |
|
|
for j in 1 to i loop
|
| 114 |
|
|
Ztmp := (Xreg(i-j) and Yor(j)) or Ztmp;
|
| 115 |
|
|
end loop;
|
| 116 |
|
|
Zreg(i) <= Ztmp;
|
| 117 |
|
|
end if;
|
| 118 |
|
|
end loop;
|
| 119 |
|
|
end process shifter;
|
| 120 |
|
|
end structural;
|
| 121 |
|
|
|
| 122 |
|
|
|
| 123 |
|
|
|