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

Subversion Repositories qfp32

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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