Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.87 KB | None | 0 0
  1.  
  2. library ieee;
  3. use ieee.std_logic_1164.all;
  4. use ieee.numeric_std.all;
  5. use work.bspline_pckg.all;
  6.  
  7. -- p = (a +/- b) * c    + if addsub = '1', - if addsub = '0'
  8. -- a and b must be same width
  9.  
  10. entity preadd_mult_round is
  11.  
  12.     generic(
  13.             Wa : natural;
  14.             Wb : natural;
  15.             Wc : natural;
  16.             Wo : natural;
  17.             round_mode : string
  18.             );
  19.     port(
  20.         clk : in std_logic;
  21.         rst : in std_logic;
  22.         addsub : in std_logic;
  23.         a : in signed(Wa-1 downto 0);
  24.         b : in signed(Wb-1 downto 0);
  25.         c : in signed(Wc-1 downto 0);
  26.         p : out signed(Wo-1 downto 0)
  27.         );
  28.        
  29. end entity;
  30.  
  31. architecture rtl of preadd_mult_round is
  32.    
  33.     constant zeros : signed(Wo-1 downto 1) := (others => '0');
  34.     constant Ws : natural := max(Wa, Wb);
  35.  
  36.     signal c_del : signed(Wc-1 downto 0);
  37.     signal sum  : signed(Ws-1 downto 0);
  38.     signal mult : signed(Ws+Wc-1 downto 0);
  39.     signal mult_r : signed(Wo-1 downto 0);
  40.  
  41. begin
  42.  
  43.     process(clk) is
  44.     begin
  45.         if rising_edge(clk) then
  46.             if rst = '1' then
  47.                 sum <= (others => '0');
  48.             else
  49.                 if addsub = '1' then
  50.                     sum <= resize(a, Ws) + resize(b, Ws);
  51.                 else
  52.                     sum <= resize(a, Ws) - resize(b, Ws);
  53.                 end if;
  54.             end if;
  55.         end if;
  56.     end process;
  57.    
  58.     process(clk) is
  59.     begin
  60.         if rising_edge(clk) then
  61.             if rst = '1' then
  62.                 c_del <= (others => '0');
  63.             else
  64.                 c_del <= c;
  65.             end if;
  66.         end if;
  67.     end process;
  68.    
  69.     process(clk) is
  70.     begin
  71.         if rising_edge(clk) then
  72.             if rst = '1' then
  73.                 mult <= (others => '0');
  74.             else
  75.                 mult <= c_del * sum;
  76.             end if;
  77.         end if;
  78.     end process;
  79.    
  80.     process(clk) is
  81.     begin
  82.         if rising_edge(clk) then
  83.             if rst = '1' then
  84.                 mult_r <= (others => '0');
  85.             else
  86.                 if round_mode = "trunc" then
  87.                     mult_r <= mult(Ws+Wc-2 downto Ws+Wc-Wo-1);
  88.                 else
  89.                     mult_r <= mult(Ws+Wc-2 downto Ws+Wc-Wo-1) + (zeros & mult(Ws+Wc-Wo-2));
  90.                 end if;
  91.             end if;
  92.         end if;
  93.     end process;
  94.    
  95.     p <= mult_r;
  96.    
  97. end rtl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement