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

Subversion Repositories qfp32

[/] [qfp32/] [trunk/] [Units/] [misc.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mgraep
library IEEE;
2
use IEEE.std_logic_1164.all;
3
 
4
library work;
5
use work.qfp_p.all;
6
 
7
package qfp32_misc_p is
8
 
9
  constant QFP_SCMD_Q2I : qfp_scmd_t := "00";
10
  constant QFP_SCMD_I2Q : qfp_scmd_t := "01";
11
 
12
end package qfp32_misc_p;
13
 
14
library IEEE;
15
use IEEE.std_logic_1164.all;
16
use IEEE.numeric_std.all;
17
 
18
library work;
19
use work.qfp_p.all;
20
use work.qfp32_misc_p.all;
21
 
22
entity qfp32_misc is
23
 
24
  port (
25
    clk_i     : in  std_ulogic;
26
    reset_n_i : in  std_ulogic;
27
 
28
    cmd_i : in qfp_scmd_t;
29
 
30
    start_i : in  std_ulogic;
31
    ready_o : out std_ulogic;
32
 
33
    regA_i : in  qfp32_t;
34
    regB_i : in  qfp32_t;
35
 
36
    complete_o : out std_ulogic;
37
    result_o   : out qfp32_raw_t);
38
 
39
end qfp32_misc;
40
 
41
architecture Rtl of qfp32_misc is
42
 
43
  -- integer input int(31 downto 0) mapped to
44
  -- mant = int(28 downto 0)
45
  -- exp = int(30 downto 29)
46
  -- sign = int(31)
47
 
48
  signal p1_sign : std_ulogic;
49
  signal p1_cy : std_ulogic;
50
  signal p1_mant : unsigned(28 downto 0);
51
  signal p1_shft : unsigned(1 downto 0);
52
  signal p1_pre_add : unsigned(28 downto 0);
53
  signal p1_mant_shft : unsigned(29 downto 0);
54
  signal p1_fmt : qfp_fmt_t;
55
  signal p1_result : unsigned(29 downto 0);
56
  signal p1_ov : std_ulogic;
57
 
58
  signal p2_fmt : qfp_fmt_t;
59
  signal p2_result : unsigned(29 downto 0);
60
  signal p2_ov : std_ulogic;
61
 
62
  signal complete : std_ulogic;
63
 
64
begin  -- Rtl
65
 
66
  process (cmd_i, p1_cy, p1_mant, p1_mant_shft(0), p1_mant_shft(29 downto 1),
67
           p1_pre_add, p1_shft, p1_sign, p2_fmt.exp, p2_fmt.sign, p2_ov,
68
           p2_result(28 downto 0), rega_i.fmt.exp, rega_i.fmt.sign,
69
           rega_i.mant)
70
  begin  -- process
71
 
72
    -- stage 1
73
    p1_sign <= rega_i.fmt.sign;
74
    p1_mant <= rega_i.mant;
75
 
76
    p1_cy <= '0';
77
    p1_ov <= '0';
78
    p1_shft <= to_unsigned(0,2);
79
    p1_fmt.sign <= p1_sign;
80
    p1_fmt.exp <= to_unsigned(3,2);
81
    if cmd_i = QFP_SCMD_Q2I then
82
      p1_shft <= to_unsigned(3,2)-rega_i.fmt.exp;
83
      -- result is integer => fill upper bits with sign at unit
84
      p1_fmt.exp <= to_unsigned(0,2); -- forced zero cause otherwise normalization would take effect
85
      p1_cy <= p1_mant_shft(0) xor p1_sign;
86
    else
87
      p1_cy <= p1_sign;
88
      p1_ov <= to_ulogic(regA_i.fmt.exp /= p1_sign & p1_sign);
89
    end if;
90
 
91
     -- extend mant for rounding bit
92
    p1_mant_shft <= fast_shift(p1_mant & '0',to_integer(p1_shft)*8,'1','0');-- if p1_shft = 0 => fill is not used!
93
 
94
     -- make 2's complement if needed
95
    p1_pre_add <= p1_mant_shft(29 downto 1);
96
    if p1_sign = '1' then
97
      p1_pre_add <= not p1_mant_shft(29 downto 1);
98
    end if;
99
 
100
    -- add one to make two's complement complete
101
    p1_result <= fast_add(p1_pre_add,to_unsigned(0,29),p1_cy);-- negate
102
 
103
    -- stage 2
104
 
105
    -- as qfp raw format
106
    result_o.extMant <= p2_result(28 downto 0) & (23 downto 0 => '0');
107
    result_o.ov <= "0000" & p2_ov;
108
    result_o.exp <= '0' & p2_fmt.exp;
109
    result_o.sign <= p2_fmt.sign;
110
  end process;
111
 
112
  process (clk_i, reset_n_i) is
113
  begin  -- process
114
    if reset_n_i = '0' then             -- asynchronous reset (active low)
115
      complete <= '0';
116
      p2_fmt <= (to_unsigned(0,2),'0');
117
      p2_result <= to_unsigned(0,30);
118
      p2_ov <= '0';
119
    elsif clk_i'event and clk_i = '1' then  -- rising clock edge
120
      complete <= '0';
121
      if start_i = '1' then
122
        p2_ov <= p1_ov;
123
        p2_fmt <= p1_fmt;
124
        p2_result <= p1_result;
125
        complete <= '1';
126
      end if;
127
    end if;
128
  end process;
129
 
130
  ready_o <= '1';
131
  complete_o <= complete;--start_i;
132
 
133
end Rtl;
134
 
135
 

powered by: WebSVN 2.1.0

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