2021-10-27 14:25:32 +02:00
|
|
|
library ieee;
|
|
|
|
use ieee.math_real.all;
|
|
|
|
use ieee.numeric_std.all;
|
|
|
|
use ieee.std_logic_1164.all;
|
|
|
|
|
|
|
|
entity Shifter is
|
|
|
|
port(
|
|
|
|
shift_lsl : in Std_Logic;
|
|
|
|
shift_lsr : in Std_Logic;
|
|
|
|
|
|
|
|
shift_asr : in Std_Logic;
|
|
|
|
|
|
|
|
shift_ror : in Std_Logic; -- rotation sans extension
|
|
|
|
shift_rrx : in Std_Logic; -- avec extension
|
|
|
|
|
|
|
|
shift_val : in Std_Logic_Vector(4 downto 0);
|
|
|
|
|
|
|
|
din : in Std_Logic_Vector(31 downto 0);
|
|
|
|
cin : in Std_Logic;
|
|
|
|
|
|
|
|
dout : out Std_Logic_Vector(31 downto 0);
|
|
|
|
cout : out Std_Logic;
|
|
|
|
|
|
|
|
-- global interface
|
|
|
|
vdd : in bit;
|
|
|
|
vss : in bit );
|
|
|
|
end Shifter;
|
|
|
|
|
|
|
|
-- TODO:
|
|
|
|
-- changer les "000" et "temp_dout(31)& temp_dout(31)& ..." par la synthaxe
|
|
|
|
-- (n1 downto n0 => '0') ou (n1 downto n0 => '0')
|
|
|
|
|
|
|
|
architecture Shifter_bhvr of Shifter is
|
|
|
|
begin
|
|
|
|
process(shift_lsl, shift_lsr, shift_asr, shift_ror, shift_rrx,shift_val,
|
|
|
|
din, cin, vdd, vss)
|
|
|
|
variable temp_dout : Std_Logic_Vector(31 downto 0);
|
|
|
|
variable temp_cout : Std_Logic;
|
|
|
|
begin
|
|
|
|
temp_dout := din;
|
|
|
|
temp_cout := cin;
|
|
|
|
-- LSL -------------------------------------------------------------
|
|
|
|
-- 1
|
|
|
|
if(shift_lsl='1' and shift_val(0)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(31);
|
|
|
|
temp_dout := (temp_dout(30 downto 0)&'0');
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 2
|
|
|
|
if(shift_lsl='1' and shift_val(1)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(30);
|
|
|
|
temp_dout := (temp_dout(29 downto 0)&"00");
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 4
|
|
|
|
if(shift_lsl='1' and shift_val(2)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(28);
|
|
|
|
temp_dout := (temp_dout(27 downto 0)&"0000");
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 8
|
|
|
|
if(shift_lsl='1' and shift_val(3)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(24);
|
|
|
|
temp_dout :=(temp_dout(23 downto 0)&"00000000");
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
-- 16
|
|
|
|
if(shift_lsl='1' and shift_val(4)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(16);
|
|
|
|
temp_dout :=
|
|
|
|
(temp_dout(15 downto 0)&"0000000000000000");
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- LSR -------------------------------------------------------------
|
|
|
|
-- 1
|
|
|
|
if(shift_lsr='1' and shift_val(0)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout := ('0'&temp_dout(31 downto 1));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 2
|
|
|
|
if(shift_lsr='1' and shift_val(1)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout := ("00"&temp_dout(31 downto 2));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 4
|
|
|
|
if(shift_lsr='1' and shift_val(2)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout := ("0000"&temp_dout(31 downto 4));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 8
|
|
|
|
if(shift_lsr='1' and shift_val(3)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=("00000000"&temp_dout(31 downto 8));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 16
|
|
|
|
if(shift_lsr='1' and shift_val(4)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=
|
|
|
|
("0000000000000000"&temp_dout(31 downto 16));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
|
|
|
|
-- ASR -------------------------------------------------------------
|
|
|
|
-- 1
|
|
|
|
if(shift_asr='1' and shift_val(0)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout := (temp_dout(31)
|
|
|
|
&temp_dout(31 downto 1));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 2
|
|
|
|
if(shift_asr='1' and shift_val(1)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=
|
|
|
|
( temp_dout(31)& temp_dout(31)
|
|
|
|
&temp_dout(31 downto 2));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 4
|
|
|
|
if(shift_asr='1' and shift_val(2)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=
|
|
|
|
( temp_dout(31)& temp_dout(31)
|
|
|
|
&temp_dout(31)& temp_dout(31)
|
|
|
|
&temp_dout(27 downto 0));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 8
|
|
|
|
if(shift_asr='1' and shift_val(3)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=
|
|
|
|
( temp_dout(31)&temp_dout(31)&temp_dout(31)
|
|
|
|
&temp_dout(31)&temp_dout(31)&temp_dout(31)
|
|
|
|
&temp_dout(31)&temp_dout(31)
|
|
|
|
&temp_dout(23 downto 0));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 16
|
|
|
|
if(shift_asr='1' and shift_val(4)='1')
|
|
|
|
then
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
temp_dout :=
|
|
|
|
( temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(31)& temp_dout(31)&
|
|
|
|
temp_dout(15 downto 0));
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- ROR -------------------------------------------------------------
|
|
|
|
-- 1
|
|
|
|
if(shift_ror='1' and shift_val(0)='1')
|
|
|
|
then temp_dout := (temp_dout(0)
|
|
|
|
&temp_dout(31 downto 1));
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 2
|
|
|
|
if(shift_ror='1' and shift_val(1)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_dout(1 downto 0)
|
|
|
|
&temp_dout(31 downto 2));
|
|
|
|
temp_cout := temp_dout(1);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 4
|
|
|
|
if(shift_ror='1' and shift_val(2)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_dout(3 downto 0)
|
|
|
|
&temp_dout(31 downto 4));
|
|
|
|
temp_cout := temp_dout(3);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 8
|
|
|
|
if(shift_ror='1' and shift_val(3)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_dout(7 downto 0)
|
|
|
|
&temp_dout(31 downto 8));
|
|
|
|
temp_cout := temp_dout(7);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 16
|
|
|
|
if(shift_ror='1' and shift_val(4)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_dout(15 downto 0)
|
|
|
|
&temp_dout(31 downto 16));
|
|
|
|
temp_cout := temp_dout(15);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- RRX -------------------------------------------------------------
|
|
|
|
-- 1
|
|
|
|
if(shift_rrx='1' and shift_val(0)='1')
|
|
|
|
then temp_dout := (temp_cout
|
|
|
|
&temp_dout(31 downto 1));
|
|
|
|
temp_cout := temp_dout(0);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 2
|
|
|
|
if(shift_rrx='1' and shift_val(1)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_cout
|
|
|
|
&temp_dout(0)
|
|
|
|
&temp_dout(31 downto 2));
|
|
|
|
temp_cout := temp_dout(1);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 4
|
|
|
|
if(shift_rrx='1' and shift_val(2)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_cout
|
|
|
|
&temp_dout(2 downto 0)
|
|
|
|
&temp_dout(31 downto 4));
|
|
|
|
temp_cout := temp_dout(3);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 8
|
|
|
|
if(shift_rrx='1' and shift_val(3)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_cout
|
|
|
|
&temp_dout(6 downto 0)
|
|
|
|
&temp_dout(31 downto 8));
|
|
|
|
temp_cout := temp_dout(7);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
-- 16
|
|
|
|
if(shift_rrx='1' and shift_val(4)='1')
|
|
|
|
then temp_dout :=
|
|
|
|
(temp_cout
|
|
|
|
&temp_dout(14 downto 0)
|
|
|
|
&temp_dout(31 downto 16));
|
|
|
|
temp_cout := temp_dout(15);
|
|
|
|
else NULL;
|
|
|
|
end if;
|
|
|
|
|
|
|
|
cout <= temp_cout;
|
|
|
|
dout <= temp_dout;
|
|
|
|
end process;
|
|
|
|
end Shifter_bhvr;
|