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

Subversion Repositories qfp32

[/] [qfp32/] [trunk/] [qfp_p.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
use IEEE.numeric_std.all;
4
 
5
use IEEE.std_logic_1164.all;            -- basic logic types
6
use STD.textio.all;                     -- basic I/O
7
use IEEE.std_logic_textio.all;          -- I/O for logic types
8
 
9
library work;
10
use work.cla_p.all;
11
 
12
package qfp_p is
13
 
14
  -- support 8 different formates
15
  type qfp_fmt_t is record
16
    exp  : unsigned(1 downto 0);
17
    sign : std_ulogic;
18
  end record;
19
 
20
  type qfp32_t is record
21
    mant : unsigned(28 downto 0);
22
    fmt  : qfp_fmt_t;
23
  end record;
24
 
25
  -- intermediate format (unnormalized)
26
  type qfp32_raw_t is record
27
    extMant : unsigned(52 downto 0);-- mant+x
28
    ov   : unsigned(4 downto 0);
29
    exp  : unsigned(2 downto 0);
30
    sign : std_ulogic;
31
  end record;
32
 
33
  subtype qfp_scmd_t is std_ulogic_vector(1 downto 0);-- sub command
34
 
35
  constant qfp_x0 : unsigned(1 downto 0) := to_unsigned(0,2);
36
  constant qfp_x8 : unsigned(1 downto 0) := to_unsigned(1,2);
37
  constant qfp_x16 : unsigned(1 downto 0) := to_unsigned(2,2);
38
  constant qfp_x24 : unsigned(1 downto 0) := to_unsigned(3,2);
39
 
40
  -- greater than
41
  function fast_gt (
42
    a : unsigned;
43
    b : unsigned)
44
    return boolean;
45
 
46
  -- add
47
  function fast_add (
48
    a : unsigned;
49
    b : unsigned;
50
    cy_in : std_ulogic)
51
    return unsigned;
52
 
53
  constant fast_shift_left : std_ulogic := '0';
54
  constant fast_shift_rigtht : std_ulogic := '1';
55
 
56
  -- implements a barrel shifter
57
  function fast_shift (
58
    data_in : unsigned;
59
    shft : natural;
60
    mode  : std_ulogic; -- left=0
61
    extend : std_ulogic := '0')
62
    return unsigned;
63
 
64
  function to_ulogic (
65
    cond : boolean)
66
    return std_ulogic;
67
 
68
  function min (
69
    a : unsigned;
70
    b : unsigned)
71
    return unsigned;
72
 
73
  function max (
74
    a : unsigned;
75
    b : unsigned)
76
    return unsigned;
77
 
78
  function log2 (
79
    x : integer)
80
    return integer;
81
 
82
end package qfp_p;
83
 
84
package body qfp_p is
85
 
86
   -- greater than a > b SURE
87
  function fast_gt (
88
    a : unsigned;
89
    b : unsigned)
90
    return boolean is
91
 
92
    variable l1 : cla_level_t((a'length-1)/4 downto 0);
93
    variable l2 : cla_level_t((a'length-1)/16 downto 0);
94
    variable l3 : cla_level_t((a'length-1)/32 downto 0);
95
    variable cy : std_ulogic_vector(l3'length downto 0);-- groupsize+1
96
 
97
    variable a_inv : unsigned(a'length-1 downto 0);
98
 
99
  begin  -- function fast_gt
100
 
101
    a_inv := not a;
102
    l1 := CLALevelMk(a_inv,b,4);
103
    l2 := CLALevelMk(l1,4);
104
    l3 := CLALevelMk(l2,2);
105
 
106
    cy := CLAExpandCy(l3,'1');
107
 
108
    return cy(cy'length-1) = '0';
109
 
110
  end function fast_gt;
111
 
112
  function fast_add (
113
    a : unsigned;
114
    b : unsigned;
115
    cy_in : std_ulogic)
116
    return unsigned is
117
 
118
    variable l1 : cla_level_t((a'length-1)/4 downto 0);
119
    variable l2 : cla_level_t((a'length-1)/16 downto 0);
120
    variable l3 : cla_level_t((a'length-1)/32 downto 0);
121
    variable cy : std_ulogic_vector(l3'length downto 0);-- groupsize+1
122
    variable result : unsigned(a'length downto 0);
123
 
124
  begin  -- function fast_add
125
 
126
    l1 := CLALevelMk(a,b,4);
127
    l2 := CLALevelMk(l1,4);
128
    l3 := CLALevelMk(l2,2);
129
 
130
    cy := CLAExpandCy(l3,cy_in);
131
 
132
    return cy(cy'length-1) & CLAParallelAdd(a,b,CLAExpandCy(l1,CLAExpandCy(l2,cy)));
133
 
134
  end function fast_add;
135
 
136
  -- implements a barrel shifter
137
  function fast_shift (
138
    data_in : unsigned;
139
    shft : natural;
140
    mode  : std_ulogic; -- left=0
141
    extend : std_ulogic := '0')
142
    return unsigned is
143
 
144
    constant size_lg2 : integer := log2(data_in'length);
145
 
146
    variable shft_rem : natural;
147
    variable data : unsigned(data_in'length-1 downto 0);
148
  begin  -- fast_shift
149
 
150
    shft_rem := shft;
151
 
152
    data := data_in;
153
 
154
    for i in size_lg2-1 downto 0 loop
155
      if shft_rem >= 2**i then
156
        case mode is
157
          when '0' => -- shift left
158
            data := shift_left(data,2**i);
159
          when '1' => -- shift right 
160
            data := shift_right(data,2**i);
161
            -- overwrite top bits with extend
162
            data(data'length-1 downto (data'length-2**i)) := (others => extend);
163
          when others => null;
164
        end case;
165
        shft_rem := shft_rem-2**i;
166
      end if;
167
    end loop;  -- i
168
 
169
    return data;
170
 
171
  end fast_shift;
172
 
173
  function to_ulogic (
174
    cond : boolean)
175
    return std_ulogic is
176
  begin
177
    if cond then
178
      return '1';
179
    end if;
180
 
181
    return '0';
182
  end to_ulogic;
183
 
184
  function min (
185
    a : unsigned;
186
    b : unsigned)
187
    return unsigned is
188
  begin  -- function min
189
    if a < b then
190
      return a;
191
    end if;
192
    return b;
193
  end function min;
194
 
195
  function max (
196
    a : unsigned;
197
    b : unsigned)
198
    return unsigned is
199
  begin  -- function max
200
    if a > b then
201
      return a;
202
    end if;
203
    return b;
204
  end function max;
205
 
206
  function log2 (
207
    x : integer)
208
    return integer is
209
 
210
    variable i : integer;
211
    variable result : integer;
212
 
213
  begin  -- log2
214
    i := 1;
215
    result := x-1;
216
    while result >= 2 loop
217
      i := i+1;
218
      result := result/2;
219
    end loop;
220
    return i;
221
  end log2;
222
 
223
end package body qfp_p;

powered by: WebSVN 2.1.0

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