Skip to content
Snippets Groups Projects
shifter.vhd 1.99 KiB
Newer Older
8304_9's avatar
8304_9 committed
-------------------------------------------------------------------------------
-- Project  ELE8304 : Circuits intégrés à très grande échelle
-------------------------------------------------------------------------------
-- File     shifter.vhd
-- Authors  Titouan Luard <luardtitouan@gmail.com> 
--          Yann Roberge <yann.roberge@polymtl.ca> 
-- Lab      GRM - Polytechnique Montreal
-- Date     2021-10-29
-------------------------------------------------------------------------------
-- Brief    Single-bit half-adder with carry out
------------------------------------------------------------------------
-------
8304_9's avatar
8304_9 committed
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;

8304_9's avatar
8304_9 committed
library work;
use work.riscv_pkg.all;

entity shifter is
  port (
    i_shamt     : in  std_logic_vector(4 downto 0); -- nombre de bits décalés
    i_src1      : in  std_logic_vector(XLEN-1 downto 0); -- nombre décalé
8304_9's avatar
8304_9 committed
    i_arith     : in  std_logic; -- 0: décalage logique (bourre des 0) ; 1
    i_opcode    : in  std_logic_vector(2 downto 0);
    o_sh  : out std_logic_vector(XLEN-1 downto 0) );
8304_9's avatar
8304_9 committed

end entity shifter;

--SRL 000
--SRA 001
--SLL 010
8304_9's avatar
8304_9 committed
architecture beh of shifter is
signal temp : std_logic_vector(XLEN-1 downto 0);
8304_9's avatar
8304_9 committed
begin

shift: 
8304_9's avatar
8304_9 committed
process (all) is
begin
  case i_opcode is
    when "000" =>
      if i_arith='0' then
     --decalage a droite logique 
         o_sh <= i_src1 srl to_integer(unsigned(i_shamt));
      else
        if i_src1(XLEN-1)='0' then
8304_9's avatar
8304_9 committed
          o_sh <= i_src1 srl to_integer(unsigned(i_shamt));
          temp <= i_src1 srl to_integer(unsigned(i_shamt));
          o_sh <= not temp(temp'length - 1 downto temp'length - to_integer(unsigned(i_shamt))) & i_src1(temp'length - 1 - to_integer(unsigned(i_shamt)) downto 0);
8304_9's avatar
8304_9 committed
        end if;
      end if;
    when "001" =>
    --decalage a droite arithmetique
      o_sh <= i_src1 sll to_integer(unsigned(i_shamt));
       

8304_9's avatar
8304_9 committed
    when others=> o_sh<= i_src1;
  end case;
end process shift;
8304_9's avatar
8304_9 committed


end architecture beh;