OpenCores
URL https://opencores.org/ocsvn/special_functions_unit/special_functions_unit/trunk

Subversion Repositories special_functions_unit

[/] [special_functions_unit/] [Open_source_SFU/] [cordic_vhdl/] [parts/] [fp_leading_zeros_and_shift.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 divadnauj
----------------------------------------------------------------------------------
2
-- FP leading zeros and normalization (fp_leading_zeros_and_shift.vhd)
3
--
4
-- The fractional P includes the guard digits and the sticky bit.
5
-- Returns the normalized number and the adjusted exponent
6
-- Used in FP add of section 12.5.1
7
----------------------------------------------------------------------------------
8
 
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.std_logic_arith.all;
12
use ieee.std_logic_unsigned.all;
13
 
14
entity fp_leading_zeros_and_shift is
15
    generic (P: natural:= 27; E: natural := 8; PLOG: natural := 4);
16
    Port ( frac : in  std_logic_vector (P downto 0);
17
           exp  : in  std_logic_vector (E-1 downto 0);
18
           frac_Norm : out  std_logic_vector (P downto 0);
19
           exp_Norm : out  std_logic_vector (E-1 downto 0);
20
           underFlow : out std_logic);
21
end fp_leading_zeros_and_shift;
22
 
23
architecture Behavioral of fp_leading_zeros_and_shift is
24
   constant ZEROS : std_logic_vector(P downto 0):= (others => '0');
25
   signal leadZerosBin : std_logic_vector(PLOG downto 0);
26
   signal exp_Norm_int : std_logic_vector(E-1 downto 0);
27
   signal isZ : std_logic;
28
 
29
begin
30
 
31
    --count zeros: elegant version.
32
    detectZeros: process(frac, exp)
33
       variable leadZerosBinVar : std_logic_vector(PLOG downto 0);
34
    begin
35
      leadZerosBinVar := ZEROS(PLOG downto 0);
36
      for i in P downto 1 loop
37
       if (frac(P-1 downto P-i)= ZEROS(P-1 downto P-i) ) then
38
          leadZerosBinVar := conv_std_logic_vector(i,PLOG+1);
39
          exit;
40
       end if;
41
      end loop;
42
      leadZerosBin <= leadZerosBinVar;
43
    end process;
44
 
45
 
46
   adjustExponent: process(leadZerosBin, exp, isZ)
47
   begin
48
      if isZ = '1' then
49
         exp_Norm_int <= (others => '0');
50
      else
51
         exp_Norm_int <= exp - ("000" & leadZerosBin);
52
      end if;
53
   end process;
54
 
55
   isZ <= '1' when frac(P-1 downto 0) = ZEROS (P-1 downto 0) else '0';
56
   underFlow <= '0' when isZ='0' and exp > leadZerosBin else '1';
57
   exp_Norm <= exp_Norm_int;
58
 
59
   shift: process(leadZerosBin, frac)
60
      variable temp : std_logic_vector(P downto 0);
61
      variable dtemp : std_logic_vector(P downto 0);
62
      variable fracAgnVar : std_logic_vector(P downto 0);
63
   begin
64
      temp := frac;
65
      for i in PLOG downto 0 loop
66
         if (leadZerosBin(i) = '1') then
67
            dtemp := (others => '0');
68
            dtemp(P downto 2**i) := temp(P - 2**i downto 0);
69
         else
70
            dtemp := temp;
71
         end if;
72
         temp := dtemp;
73
      end loop;
74
      frac_Norm <= dtemp;
75
   end process;
76
 
77
end Behavioral;
78
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.