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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_pkg.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2013 Stefano Tonello                          --
6
--                                                             --
7
-- This source file may be used and distributed without        --
8
-- restriction provided that this copyright statement is not   --
9
-- removed from the file and that any derivative work contains --
10
-- the original copyright notice and the associated disclaimer.--
11
--                                                             --
12
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY         --
13
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   --
15
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      --
16
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         --
17
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    --
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   --
19
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        --
20
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  --
21
-- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  --
22
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  --
23
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         --
24
-- POSSIBILITY OF SUCH DAMAGE.                                 --
25
--                                                             --
26
-----------------------------------------------------------------
27
 
28
---------------------------------------------------------------
29
-- G.729A data types and conversion functions package
30
---------------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
 
36
package G729A_ASIP_PKG is
37
 
38
  -- short data word-length
39
  constant SDLEN : integer := 16;
40
 
41
  -- long data word-length
42
  constant LDLEN : integer := 32;
43
 
44
  -- instruction word-length
45
  constant ILEN : integer := 24;
46
 
47
  -- address word-length
48
  constant ALEN : integer := 16;
49
 
50
  -- short data word type
51
  subtype SDWORD_T is signed(SDLEN-1 downto 0);
52
 
53
  -- long data word type
54
  subtype LDWORD_T is signed(LDLEN-1 downto 0);
55
 
56
  -- Signed 16-bit integer type
57
  subtype SINT16_T is integer range -2**(SDLEN-1) to 2**(SDLEN-1)-1;
58
 
59
  -- Unsigned 16-bit integer type
60
  subtype UINT16_T is integer range 0 to 2**SDLEN-1;
61
 
62
  -- register identifier type
63
  subtype RID_T is integer range 0 to 16-1;
64
 
65
  function log2(VAL : integer range 1 to 2**20-1) return integer;
66
 
67
  function hex_to_int(XSTR : string) return integer;
68
 
69
  function hex_to_uint16(XSTR : string (1 to 4)) return UINT16_T;
70
 
71
  function pos_overflow(VAL : LDWORD_T) return std_logic;
72
 
73
  function neg_overflow(VAL : LDWORD_T) return std_logic;
74
 
75
  -- convert hex string to integer
76
  function hex_to_natural(XSTR : string) return natural;
77
 
78
  -- convert hex string to std_logic_vector
79
  function hex_to_std_logic(XSTR : string) return std_logic_vector;
80
 
81
  -- convert hex string to unsigned
82
  function hex_to_unsigned(XSTR : string) return unsigned;
83
 
84
  -- convert unsigned to std_logic_vector
85
  function to_std_logic_vector(U : unsigned) return std_logic_vector;
86
 
87
  -- convert signed to std_logic_vector
88
  function to_std_logic_vector(S : signed) return std_logic_vector;
89
 
90
  -- convert std_logic_vector to unsigned
91
  function to_unsigned(V : std_logic_vector) return unsigned;
92
 
93
  -- convert signed to unsigned
94
  function to_unsigned(S : signed) return unsigned;
95
 
96
  -- convert std_logic_vector to signed
97
  function to_signed(V : std_logic_vector) return signed;
98
 
99
end G729A_ASIP_PKG;
100
 
101
package body G729A_ASIP_PKG is
102
 
103
  function log2(VAL : integer range 1 to 2**20-1) return integer is
104
    variable LOG2 : integer range 0 to 20 := 0;
105
  begin
106
    while (VAL > 2**LOG2) loop
107
      LOG2 := LOG2 + 1;
108
    end loop;
109
    return(LOG2);
110
  end function;
111
 
112
  function hex_to_int(XSTR : string) return integer is
113
    variable VAL : integer := 0;
114
    variable DGT : integer range 0 to 15;
115
  begin
116
    for i in XSTR'length downto 1 loop
117
      case XSTR(i) is
118
        when '0' => DGT := 0;
119
        when '1' => DGT := 1;
120
        when '2' => DGT := 2;
121
        when '3' => DGT := 3;
122
        when '4' => DGT := 4;
123
        when '5' => DGT := 5;
124
        when '6' => DGT := 6;
125
        when '7' => DGT := 7;
126
        when '8' => DGT := 8;
127
        when '9' => DGT := 9;
128
        when 'a' => DGT := 10;
129
        when 'b' => DGT := 11;
130
        when 'c' => DGT := 12;
131
        when 'd' => DGT := 13;
132
        when 'e' => DGT := 14;
133
        when others => DGT := 15;
134
      end case;
135
      VAL := VAL + DGT*(16**(4-i));
136
    end loop;
137
    return(VAL);
138
  end function;
139
 
140
  function hex_to_uint16(XSTR : string(1 to 4)) return UINT16_T is
141
  begin
142
    return(hex_to_int(XSTR));
143
  end function;
144
 
145
  function pos_overflow(VAL : LDWORD_T) return std_logic is
146
    variable SVAL : LDWORD_T;
147
  begin
148
    if(VAL(LDLEN-1) = '1') then
149
      return('0');
150
    else
151
      SVAL := shift_right(VAL,SDLEN-1);
152
      if(SVAL = 0) then
153
        return('0');
154
      else
155
        return('1');
156
      end if;
157
    end if;
158
  end function;
159
 
160
  function neg_overflow(VAL : LDWORD_T) return std_logic is
161
    variable SVAL : LDWORD_T;
162
  begin
163
    if(VAL(LDLEN-1) = '0') then
164
      return('0');
165
    else
166
      SVAL := not(shift_right(VAL,SDLEN-1));
167
      if(SVAL = 0) then
168
        return('0');
169
      else
170
        return('1');
171
      end if;
172
    end if;
173
  end function;
174
 
175
  function hex_to_natural(XSTR : string) return natural is
176
    variable VAL : natural := 0;
177
    variable DGT : natural range 0 to 15;
178
  begin
179
    for i in 1 to XSTR'length loop
180
      case XSTR(i) is
181
        when '0' => DGT := 0;
182
        when '1' => DGT := 1;
183
        when '2' => DGT := 2;
184
        when '3' => DGT := 3;
185
        when '4' => DGT := 4;
186
        when '5' => DGT := 5;
187
        when '6' => DGT := 6;
188
        when '7' => DGT := 7;
189
        when '8' => DGT := 8;
190
        when '9' => DGT := 9;
191
        when 'a' => DGT := 10;
192
        when 'b' => DGT := 11;
193
        when 'c' => DGT := 12;
194
        when 'd' => DGT := 13;
195
        when 'e' => DGT := 14;
196
        when others => DGT := 15;
197
      end case;
198
      VAL := VAL + DGT*(16**(XSTR'length-i));
199
    end loop;
200
    return(VAL);
201
  end function;
202
 
203
  function hex_to_std_logic(XSTR : string) return std_logic_vector is
204
    variable VEC : unsigned(XSTR'length*4-1 downto 0);
205
    variable DGT : unsigned(4-1 downto 0);
206
  begin
207
    for i in 1 to XSTR'length loop
208
      case XSTR(i) is
209
        when '0' => DGT := "0000";
210
        when '1' => DGT := "0001";
211
        when '2' => DGT := "0010";
212
        when '3' => DGT := "0011";
213
        when '4' => DGT := "0100";
214
        when '5' => DGT := "0101";
215
        when '6' => DGT := "0110";
216
        when '7' => DGT := "0111";
217
        when '8' => DGT := "1000";
218
        when '9' => DGT := "1001";
219
        when 'a' => DGT := "1010";
220
        when 'b' => DGT := "1011";
221
        when 'c' => DGT := "1100";
222
        when 'd' => DGT := "1101";
223
        when 'e' => DGT := "1110";
224
        when others => DGT := "1111";
225
      end case;
226
      VEC(XSTR'length*4-1 downto 4) := VEC(XSTR'length*4-1-4 downto 0);
227
      VEC(4-1 downto 0) := DGT;
228
    end loop;
229
    return(to_std_logic_vector(VEC));
230
  end function;
231
 
232
  function hex_to_unsigned(XSTR : string) return unsigned is
233
    variable VEC : unsigned(XSTR'length*4-1 downto 0);
234
    variable DGT : unsigned(4-1 downto 0);
235
  begin
236
    for i in 1 to XSTR'length loop
237
      case XSTR(i) is
238
        when '0' => DGT := "0000";
239
        when '1' => DGT := "0001";
240
        when '2' => DGT := "0010";
241
        when '3' => DGT := "0011";
242
        when '4' => DGT := "0100";
243
        when '5' => DGT := "0101";
244
        when '6' => DGT := "0110";
245
        when '7' => DGT := "0111";
246
        when '8' => DGT := "1000";
247
        when '9' => DGT := "1001";
248
        when 'a' => DGT := "1010";
249
        when 'b' => DGT := "1011";
250
        when 'c' => DGT := "1100";
251
        when 'd' => DGT := "1101";
252
        when 'e' => DGT := "1110";
253
        when others => DGT := "1111";
254
      end case;
255
      VEC(XSTR'length*4-1 downto 4) := VEC(XSTR'length*4-1-4 downto 0);
256
      VEC(4-1 downto 0) := DGT;
257
    end loop;
258
    return(VEC);
259
  end function;
260
 
261
  function to_std_logic_vector(U : unsigned) return std_logic_vector is
262
    variable V : std_logic_vector(U'high downto U'low);
263
  begin
264
    for i in U'low to U'high loop
265
      V(i) := U(i);
266
    end loop;
267
    return(V);
268
  end function;
269
 
270
  function to_std_logic_vector(S : signed) return std_logic_vector is
271
     variable V : std_logic_vector(S'high downto S'low);
272
  begin
273
    for i in S'low to S'high loop
274
      V(i) := S(i);
275
    end loop;
276
    return(V);
277
  end function;
278
 
279
  function to_unsigned(V : std_logic_vector) return unsigned is
280
    variable U : unsigned(V'high downto V'low);
281
  begin
282
    for i in V'low to V'high loop
283
      U(i) := V(i);
284
    end loop;
285
    return(U);
286
  end function;
287
 
288
  function to_unsigned(S : signed) return unsigned is
289
    variable U : unsigned(S'high downto S'low);
290
  begin
291
    for i in S'low to S'high loop
292
      U(i) := S(i);
293
    end loop;
294
    return(U);
295
  end function;
296
 
297
  function to_signed(V : std_logic_vector) return signed is
298
    variable S : signed(V'high downto V'low);
299
  begin
300
    for i in V'low to V'high loop
301
      S(i) := V(i);
302
    end loop;
303
    return(S);
304
  end function;
305
 
306
end G729A_ASIP_PKG;

powered by: WebSVN 2.1.0

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