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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_basic_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
-- Basic data types
30
---------------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
 
36
library WORK;
37
use WORK.G729A_ASIP_PKG.all;
38
 
39
package G729A_ASIP_BASIC_PKG is
40
 
41
  constant MIN_16 : SDWORD_T := (SDLEN-1 => '1', others => '0');
42
 
43
  constant MAX_16 : SDWORD_T := (SDLEN-1 => '0', others => '1');
44
 
45
  constant MIN_32 : LDWORD_T := (LDLEN-1 => '1', others => '0');
46
 
47
  constant MAX_32 : LDWORD_T := (LDLEN-1 => '0', others => '1');
48
 
49
  subtype SHORT_SHIFT_T is integer range -SDLEN to SDLEN-1;
50
 
51
  subtype LONG_SHIFT_T is integer range -LDLEN to LDLEN-1;
52
 
53
  -- These additional types have been defined to handle overflow
54
  -- conditions: valid range top/bottom values are used to flag
55
  -- overflow.
56
 
57
  subtype SHORT_SHIFT_OVF_T is integer range -SDLEN to SDLEN;
58
 
59
  subtype LONG_SHIFT_OVF_T is integer range -LDLEN to LDLEN;
60
 
61
  ------------------------------------
62
  -- Convert hex digit string to signed value 
63
  ------------------------------------
64
 
65
  function hex_to_signed(XSTR : string;LEN : integer) return signed;
66
 
67
  ------------------------------------
68
  -- Convert LDWORD_T-type value to SDWORD_T-type
69
  ------------------------------------
70
 
71
  procedure sature(
72
    LVAL : in LDWORD_T;
73
    SVAL : out SDWORD_T;
74
    OVF : out std_logic
75
  );
76
 
77
  ------------------------------------
78
  -- Get absolute value of SDWORD_T-type value
79
  ------------------------------------
80
 
81
  function abs_s(SVAL : SDWORD_T) return SDWORD_T;
82
 
83
  ------------------------------------
84
  -- Shift Left (WORD-type value)
85
  ------------------------------------
86
 
87
  procedure shl(
88
    SVALI : in SDWORD_T;
89
    SHFT : in  SHORT_SHIFT_T;
90
    SVALO : out SDWORD_T;
91
    OVF : out std_logic
92
  );
93
 
94
  ------------------------------------
95
  -- Shift Right (WORD-type value)
96
  ------------------------------------
97
 
98
  procedure shr(
99
    SVALI : in SDWORD_T;
100
    SHFT : in  SHORT_SHIFT_T;
101
    SVALO : out SDWORD_T;
102
    OVF : out std_logic
103
  );
104
 
105
  ------------------------------------
106
  -- Multiply (WORD-type result)
107
  ------------------------------------
108
 
109
  procedure mult(
110
    PROD : in LDWORD_T;
111
    RES : out SDWORD_T;
112
    OVF : out std_logic
113
  );
114
 
115
  ------------------------------------
116
  -- Long Multiply (DWORD-type result)
117
  ------------------------------------
118
 
119
  procedure L_mult(
120
    PROD : in LDWORD_T;
121
    RES : out LDWORD_T;
122
    OVF : out std_logic
123
  );
124
 
125
  ------------------------------------
126
  -- Get 2's complement of SDWORD_T-type value
127
  ------------------------------------
128
 
129
  function negate(SVAL : SDWORD_T) return SDWORD_T;
130
 
131
  ------------------------------------
132
  -- Long Addition/Subtraction 
133
  -- (DWORD-type result)
134
  ------------------------------------
135
 
136
  procedure L_add_sub(
137
    SUM : in LDWORD_T;
138
    AS : in std_logic;
139
    SA : in std_logic;
140
    SB : in std_logic;
141
    RES : out LDWORD_T;
142
    OVF : out std_logic
143
  );
144
 
145
  ------------------------------------
146
  -- Get 2's complement of LDWORD_T-type value
147
  ------------------------------------
148
 
149
  function L_negate(LVAL : LDWORD_T) return LDWORD_T;
150
 
151
  ------------------------------------
152
  --  Long Shift Left (DWORD-type result)
153
  ------------------------------------
154
 
155
  procedure L_shl(
156
    LVALI : in LDWORD_T;
157
    SHFT : in  LONG_SHIFT_T;
158
    LVALO : out LDWORD_T;
159
    OVF : out std_logic
160
  );
161
 
162
  ------------------------------------
163
  --  Long Shift Right (DWORD-type result)
164
  ------------------------------------
165
 
166
  procedure L_shr(
167
    LVALI : in LDWORD_T;
168
    SHFT : in  LONG_SHIFT_T;
169
    LVALO : out LDWORD_T;
170
    OVF : out std_logic
171
  );
172
 
173
  ------------------------------------
174
  -- Get absolute value of LDWORD_T-type value
175
  ------------------------------------
176
 
177
  function L_abs(LVAL : LDWORD_T) return LDWORD_T;
178
 
179
  ------------------------------------
180
  -- Get normalization shift amount
181
  -- (for a SDWORD_T-type value)
182
  ------------------------------------
183
 
184
  function norm_s(SVAL : SDWORD_T) return  SHORT_SHIFT_T;
185
 
186
  ------------------------------------
187
  -- Divide (WORD-type operands and result)
188
  ------------------------------------
189
 
190
  --function div_s(DD,DR : SDWORD_T) return SDWORD_T;
191
 
192
  ------------------------------------
193
  -- Get normalization shift amount
194
  -- (for a LDWORD_T-type value)
195
  ------------------------------------
196
 
197
  function norm_l(LVAL : LDWORD_T) return  LONG_SHIFT_T;
198
 
199
  ------------------------------------
200
 
201
  --function pos_overflow(VAL : LDWORD_T) return std_logic;
202
 
203
  --function neg_overflow(VAL : LDWORD_T) return std_logic;
204
 
205
end G729A_ASIP_BASIC_PKG;
206
 
207
package body G729A_ASIP_BASIC_PKG is
208
 
209
  ------------------------------------
210
 
211
  function hex_to_signed(XSTR : string;LEN : integer) return signed is
212
    variable VAL : signed(XSTR'length*4-1 downto 0);
213
    variable DGT : std_logic_vector(3 downto 0);
214
  begin
215
    for i in 1 to XSTR'length loop
216
      case XSTR(i) is
217
        when '0' => DGT := "0000";
218
        when '1' => DGT := "0001";
219
        when '2' => DGT := "0010";
220
        when '3' => DGT := "0011";
221
        when '4' => DGT := "0100";
222
        when '5' => DGT := "0101";
223
        when '6' => DGT := "0110";
224
        when '7' => DGT := "0111";
225
        when '8' => DGT := "1000";
226
        when '9' => DGT := "1001";
227
        when 'a' => DGT := "1010";
228
        when 'b' => DGT := "1011";
229
        when 'c' => DGT := "1100";
230
        when 'd' => DGT := "1101";
231
        when 'e' => DGT := "1110";
232
        when others => DGT := "1111";
233
      end case;
234
      for j in 3 downto 0 loop
235
        VAL((XSTR'length-i)*4+j) := DGT(j);
236
      end loop;
237
    end loop;
238
    return(VAL(LEN-1 downto 0));
239
  end function;
240
 
241
  ------------------------------------
242
 
243
  procedure sature(
244
    LVAL : in LDWORD_T;
245
    SVAL : out SDWORD_T;
246
    OVF : out std_logic
247
  ) is
248
    constant ALL_ZERO : LDWORD_T := to_signed(0,LDLEN);
249
    constant ALL_ONE : LDWORD_T := not(ALL_ZERO);
250
    variable TMP : LDWORD_T;
251
  begin
252
    TMP := shift_right(LVAL,SDLEN-1);
253
    if((LVAL > 0) and not(TMP = ALL_ZERO)) then
254
      -- positive overflow
255
      SVAL := MAX_16;
256
      OVF := '1';
257
    elsif((LVAL < 0) and  not(TMP = ALL_ONE)) then
258
      -- negative overflow
259
      SVAL := MIN_16;
260
      OVF := '1';
261
    else
262
      -- exact result
263
      SVAL := LVAL(SDLEN-1 downto 0);
264
      OVF := '0';
265
    end if;
266
  end sature;
267
 
268
  ------------------------------------
269
 
270
  function abs_s(SVAL : SDWORD_T) return SDWORD_T is
271
  begin
272
    if(SVAL = MIN_16) then
273
      return(MAX_16);
274
    elsif(SVAL < 0) then
275
      return(-SVAL);
276
    else
277
      return(SVAL);
278
    end if;
279
  end function;
280
 
281
  ------------------------------------
282
 
283
  procedure shl(
284
    SVALI : in SDWORD_T;
285
    SHFT : in  SHORT_SHIFT_T;
286
    SVALO : out SDWORD_T;
287
    OVF : out std_logic
288
  ) is
289
    constant ALL_ZERO : SDWORD_T := to_signed(0,SDLEN);
290
    variable TMP : SDWORD_T;
291
  begin
292
    if(SVALI = ALL_ZERO) then
293
      SVALO := SVALI;
294
      OVF := '0';
295
    elsif(SHFT >= 0) then
296
      TMP := shift_left(SVALI,SHFT);
297
      if(TMP = ALL_ZERO)then
298
        if(SVALI < 0) then
299
          SVALO := MIN_16;
300
        else
301
          SVALO := MAX_16;
302
        end if;
303
        OVF := '1';
304
      else
305
        SVALO := TMP;
306
        OVF := '0';
307
      end if;
308
    else
309
      SVALO := shift_right(SVALI,-SHFT);
310
      OVF := '0';
311
    end if;
312
  end shl;
313
 
314
  ------------------------------------
315
 
316
  procedure shr(
317
    SVALI : in SDWORD_T;
318
    SHFT : in  SHORT_SHIFT_T;
319
    SVALO : out SDWORD_T;
320
    OVF : out std_logic
321
  ) is
322
    constant ALL_ZERO : SDWORD_T := to_signed(0,SDLEN);
323
    variable TMP : SDWORD_T;
324
  begin
325
    if(SVALI = ALL_ZERO) then
326
      SVALO := SVALI;
327
      OVF := '0';
328
    elsif(SHFT <= 0) then
329
      TMP := shift_left(SVALI,-SHFT);
330
      if(TMP = ALL_ZERO)then
331
        if(SVALI < 0) then
332
          SVALO := MIN_16;
333
        else
334
          SVALO := MAX_16;
335
        end if;
336
        OVF := '1';
337
      else
338
        SVALO := TMP;
339
        OVF := '0';
340
      end if;
341
    else
342
      SVALO := shift_right(SVALI,SHFT);
343
      OVF := '0';
344
    end if;
345
  end shr;
346
 
347
  ------------------------------------
348
 
349
  -- This procedure takes WLEN x WLEN multiplication
350
  -- result, right-shift it by WLEN-1 bits and
351
  -- convert it to WLEN-bits with saturation.
352
  -- Actual multiplication must be performed before
353
  -- invoking this procedure.
354
 
355
  procedure mult(
356
    PROD : in LDWORD_T;
357
    RES : out SDWORD_T;
358
    OVF : out std_logic
359
  ) is
360
    variable TMP : LDWORD_T;
361
  begin
362
    TMP := shift_right(PROD,SDLEN-1);
363
    sature(TMP,RES,OVF);
364
  end mult;
365
 
366
  ------------------------------------
367
 
368
  -- This procedure takes WLEN x WLEN multiplication
369
  -- result and left-shift it by 1, checking for 
370
  -- overflow
371
 
372
  procedure L_mult(
373
    PROD : in LDWORD_T;
374
    RES : out LDWORD_T;
375
    OVF : out std_logic
376
  ) is
377
    constant OVFVAL : LDWORD_T := hex_to_signed("40000000",LDLEN);
378
  begin
379
    if(PROD = OVFVAL) then
380
      RES := MAX_32;
381
      OVF := '1';
382
    else
383
      RES := shift_left(PROD,1);
384
      OVF := '0';
385
    end if;
386
  end L_mult;
387
 
388
  ------------------------------------
389
 
390
  -- This procedure generates -SVAL value.
391
  -- If SVAL = MIN_16 (minimum signed integer)
392
  -- negate result can't be exact, and is
393
  -- approximated to MAX_16.
394
 
395
  function negate(SVAL : SDWORD_T) return SDWORD_T is
396
  begin
397
    if(SVAL = MIN_16) then
398
      return(MAX_16);
399
    else
400
      return(-SVAL);
401
    end if;
402
  end function;
403
 
404
  ------------------------------------
405
 
406
  -- This procedure takes LDLEN-bit
407
  -- addition/subtraction result and
408
  -- operand signs, and checks for overflow.
409
 
410
  procedure L_add_sub(
411
    SUM : in LDWORD_T;
412
    AS : in std_logic;
413
    SA : in std_logic;
414
    SB : in std_logic;
415
    RES : out LDWORD_T;
416
    OVF : out std_logic
417
  ) is
418
    variable ST : std_logic;
419
    variable IOVF : std_logic;
420
  begin
421
    ST := SUM(LDLEN-1);
422
    -- overflow flag
423
    if(AS = '1') then
424
      -- addition
425
      if(ST = '1') then
426
        IOVF := not(SA or SB);
427
      else
428
        IOVF := (SA and SB);
429
      end if;
430
    else
431
      -- subtraction
432
      if(ST = '1') then
433
        IOVF := (not(SA) and SB);
434
      else
435
        IOVF := (SA and not(SB));
436
      end if;
437
    end if;
438
    -- saturated result
439
    if(IOVF = '0') then
440
      RES := SUM;
441
    elsif(ST = '0') then
442
      RES := MIN_32;
443
    else
444
      RES := MAX_32;
445
    end if;
446
    OVF := IOVF;
447
  end L_add_sub;
448
 
449
  ------------------------------------
450
 
451
  -- This procedure generates -LVAL value.
452
  -- If LVAL = MIN_32 (minimum signed integer)
453
  -- negate result can't be exact, and is
454
  -- approximated to MAX_32.
455
 
456
  function L_negate(LVAL : LDWORD_T) return LDWORD_T is
457
  begin
458
    if(LVAL = MIN_32) then
459
      return(MAX_32);
460
    else
461
      return(-LVAL);
462
    end if;
463
  end function;
464
 
465
  ------------------------------------
466
 
467
  procedure L_shl(
468
    LVALI : in LDWORD_T;
469
    SHFT : in  LONG_SHIFT_T;
470
    LVALO : out LDWORD_T;
471
    OVF : out std_logic
472
  ) is
473
    constant ALL_ZERO : LDWORD_T := to_signed(0,LDLEN);
474
    variable TMP : LDWORD_T;
475
  begin
476
    if(LVALI = ALL_ZERO) then
477
      LVALO := LVALI;
478
      OVF := '0';
479
    elsif(SHFT >= 0) then
480
      TMP := shift_left(LVALI,SHFT);
481
      if(TMP = ALL_ZERO)then
482
        if(LVALI < 0) then
483
          LVALO := MIN_32;
484
        else
485
          LVALO := MAX_32;
486
        end if;
487
        OVF := '1';
488
      else
489
        LVALO := TMP;
490
        OVF := '0';
491
      end if;
492
    else
493
      LVALO := shift_right(LVALI,-SHFT);
494
      OVF := '0';
495
    end if;
496
  end L_shl;
497
 
498
  ------------------------------------
499
 
500
  procedure L_shr(
501
    LVALI : in LDWORD_T;
502
    SHFT : in  LONG_SHIFT_T;
503
    LVALO : out LDWORD_T;
504
    OVF : out std_logic
505
  ) is
506
    constant ALL_ZERO : LDWORD_T := to_signed(0,LDLEN);
507
    variable TMP : LDWORD_T;
508
  begin
509
    if(LVALI = ALL_ZERO) then
510
      LVALO := LVALI;
511
      OVF := '0';
512
    elsif(SHFT <= 0) then
513
      TMP := shift_left(LVALI,-SHFT);
514
      if(TMP = ALL_ZERO)then
515
        if(LVALI < 0) then
516
          LVALO := MIN_32;
517
        else
518
          LVALO := MAX_32;
519
        end if;
520
        OVF := '1';
521
      else
522
        LVALO := TMP;
523
        OVF := '0';
524
      end if;
525
    else
526
      LVALO := shift_right(LVALI,SHFT);
527
      OVF := '0';
528
    end if;
529
  end L_shr;
530
 
531
  ------------------------------------
532
 
533
  function L_abs(LVAL : LDWORD_T) return LDWORD_T is
534
  begin
535
    if(LVAL = MIN_32) then
536
      return(MAX_32);
537
    elsif(LVAL < 0) then
538
      return(-LVAL);
539
    else
540
      return(LVAL);
541
    end if;
542
  end function;
543
 
544
  ------------------------------------
545
 
546
  function norm_s(SVAL : SDWORD_T) return  SHORT_SHIFT_T is
547
    constant ALL_ZERO : SDWORD_T := to_signed(0,SDLEN);
548
    constant ALL_ONE : SDWORD_T := not(ALL_ZERO);
549
    variable TMP : SDWORD_T;
550
    variable NRM :  SHORT_SHIFT_T;
551
  begin
552
    if(SVAL = ALL_ZERO) then
553
      return(0);
554
    elsif(SVAL = ALL_ONE) then
555
      return(SDLEN-1);
556
    else
557
      if(SVAL < 0) then
558
        TMP := not(SVAL);
559
      else
560
        TMP := SVAL;
561
      end if;
562
 
563
      if(TMP(SDLEN-2) = '1') then NRM := 0;
564
      elsif(TMP(SDLEN-3) = '1') then NRM := 1;
565
      elsif(TMP(SDLEN-4) = '1') then NRM := 2;
566
      elsif(TMP(SDLEN-5) = '1') then NRM := 3;
567
      elsif(TMP(SDLEN-6) = '1') then NRM := 4;
568
      elsif(TMP(SDLEN-7) = '1') then NRM := 5;
569
      elsif(TMP(SDLEN-8) = '1') then NRM := 6;
570
      elsif(TMP(SDLEN-9) = '1') then NRM := 7;
571
      elsif(TMP(SDLEN-10) = '1') then NRM := 8;
572
      elsif(TMP(SDLEN-11) = '1') then NRM := 9;
573
      elsif(TMP(SDLEN-12) = '1') then NRM := 10;
574
      elsif(TMP(SDLEN-13) = '1') then NRM := 11;
575
      elsif(TMP(SDLEN-14) = '1') then NRM := 12;
576
      elsif(TMP(SDLEN-15) = '1') then NRM := 13;
577
      else NRM := 14;
578
      end if;
579
 
580
--      case TMP is
581
--        when "0000000000000001" => NRM := 15; 
582
--        when "000000000000001-" => NRM := 14; 
583
--        when "00000000000001--" => NRM := 13; 
584
--        when "0000000000001---" => NRM := 12; 
585
--        when "000000000001----" => NRM := 11; 
586
--        when "00000000001-----" => NRM := 10; 
587
--        when "0000000001------" => NRM := 9; 
588
--        when "000000001-------" => NRM := 8; 
589
--        when "00000001--------" => NRM := 7; 
590
--        when "0000001---------" => NRM := 6; 
591
--        when "000001----------" => NRM := 5; 
592
--        when "00001-----------" => NRM := 4; 
593
--        when "0001------------" => NRM := 3; 
594
--        when "001-------------" => NRM := 2; 
595
--        when others => NRM := 1; 
596
--      end case;
597
      return(NRM);
598
    end if;
599
  end function;
600
 
601
  ------------------------------------
602
 
603
  function norm_l(LVAL : LDWORD_T) return  LONG_SHIFT_T is
604
    constant ALL_ZERO : LDWORD_T := to_signed(0,LDLEN);
605
    constant ALL_ONE : LDWORD_T := not(ALL_ZERO);
606
    variable TMP : LDWORD_T;
607
    variable NRM :  LONG_SHIFT_T;
608
  begin
609
    if(LVAL = ALL_ZERO) then
610
      return(0);
611
    elsif(LVAL = ALL_ONE) then
612
      return(LDLEN-1);
613
    else
614
      if(LVAL < 0) then
615
        TMP := not(LVAL);
616
      else
617
        TMP := LVAL;
618
      end if;
619
      NRM := 0;
620
      for i in 0 to LDLEN-2 loop
621
        if(TMP (i) = '1') then
622
          NRM := (LDLEN-2)-i;
623
        end if;
624
      end loop;
625
 
626
      if(TMP(LDLEN-2) = '1') then NRM := 0;
627
      elsif(TMP(LDLEN-3)  = '1') then NRM := 1;
628
      elsif(TMP(LDLEN-4)  = '1') then NRM := 2;
629
      elsif(TMP(LDLEN-5)  = '1') then NRM := 3;
630
      elsif(TMP(LDLEN-6)  = '1') then NRM := 4;
631
      elsif(TMP(LDLEN-7)  = '1') then NRM := 5;
632
      elsif(TMP(LDLEN-8)  = '1') then NRM := 6;
633
      elsif(TMP(LDLEN-9)  = '1') then NRM := 7;
634
      elsif(TMP(LDLEN-10) = '1') then NRM := 8;
635
      elsif(TMP(LDLEN-11) = '1') then NRM := 9;
636
      elsif(TMP(LDLEN-12) = '1') then NRM := 10;
637
      elsif(TMP(LDLEN-13) = '1') then NRM := 11;
638
      elsif(TMP(LDLEN-14) = '1') then NRM := 12;
639
      elsif(TMP(LDLEN-15) = '1') then NRM := 13;
640
      elsif(TMP(LDLEN-16) = '1') then NRM := 14;
641
      elsif(TMP(LDLEN-17) = '1') then NRM := 15;
642
      elsif(TMP(LDLEN-18) = '1') then NRM := 16;
643
      elsif(TMP(LDLEN-19) = '1') then NRM := 17;
644
      elsif(TMP(LDLEN-20) = '1') then NRM := 18;
645
      elsif(TMP(LDLEN-21) = '1') then NRM := 19;
646
      elsif(TMP(LDLEN-22) = '1') then NRM := 20;
647
      elsif(TMP(LDLEN-23) = '1') then NRM := 21;
648
      elsif(TMP(LDLEN-24) = '1') then NRM := 22;
649
      elsif(TMP(LDLEN-25) = '1') then NRM := 23;
650
      elsif(TMP(LDLEN-26) = '1') then NRM := 24;
651
      elsif(TMP(LDLEN-27) = '1') then NRM := 25;
652
      elsif(TMP(LDLEN-28) = '1') then NRM := 26;
653
      elsif(TMP(LDLEN-29) = '1') then NRM := 27;
654
      elsif(TMP(LDLEN-30) = '1') then NRM := 28;
655
      elsif(TMP(LDLEN-31) = '1') then NRM := 29;
656
      else NRM := 30;
657
      end if;
658
 
659
--      case TMP is
660
--        when "00000000000000000000000000000001" => NRM := 31; 
661
--        when "0000000000000000000000000000001-" => NRM := 30; 
662
--        when "000000000000000000000000000001--" => NRM := 29; 
663
--        when "00000000000000000000000000001---" => NRM := 28; 
664
--        when "0000000000000000000000000001----" => NRM := 27; 
665
--        when "000000000000000000000000001-----" => NRM := 26; 
666
--        when "00000000000000000000000001------" => NRM := 25; 
667
--        when "0000000000000000000000001-------" => NRM := 24; 
668
--        when "000000000000000000000001--------" => NRM := 23; 
669
--        when "00000000000000000000001---------" => NRM := 22; 
670
--        when "0000000000000000000001----------" => NRM := 21; 
671
--        when "000000000000000000001-----------" => NRM := 20; 
672
--        when "00000000000000000001------------" => NRM := 19; 
673
--        when "0000000000000000001-------------" => NRM := 18; 
674
--        when "000000000000000001--------------" => NRM := 17; 
675
--        when "00000000000000001---------------" => NRM := 16; 
676
--        when "0000000000000001----------------" => NRM := 15; 
677
--        when "000000000000001-----------------" => NRM := 14; 
678
--        when "00000000000001------------------" => NRM := 13; 
679
--        when "0000000000001-------------------" => NRM := 12; 
680
--        when "000000000001--------------------" => NRM := 11; 
681
--        when "00000000001---------------------" => NRM := 10; 
682
--        when "0000000001----------------------" => NRM := 9; 
683
--        when "000000001-----------------------" => NRM := 8; 
684
--        when "00000001------------------------" => NRM := 7; 
685
--        when "0000001-------------------------" => NRM := 6; 
686
--        when "000001--------------------------" => NRM := 5; 
687
--        when "00001---------------------------" => NRM := 4; 
688
--        when "0001----------------------------" => NRM := 3; 
689
--        when "001-----------------------------" => NRM := 2; 
690
--        when others => NRM := 1; 
691
--      end case;
692
      return(NRM);
693
    end if;
694
  end function;
695
 
696
  ------------------------------------
697
 
698
--  function pos_overflow(VAL : LDWORD_T) return std_logic is
699
--    variable SVAL : LDWORD_T;
700
--  begin
701
--    if(VAL(LDLEN-1) = '1') then
702
--      return('0');
703
--    else
704
--      SVAL := shift_right(VAL,SDLEN-1);
705
--      if(SVAL = 0) then
706
--        return('0');
707
--      else
708
--        return('1');
709
--      end if;
710
--    end if;
711
--  end function;
712
--
713
--  function neg_overflow(VAL : LDWORD_T) return std_logic is
714
--    variable SVAL : LDWORD_T;
715
--  begin
716
--    if(VAL(LDLEN-1) = '0') then
717
--      return('0');
718
--    else
719
--      SVAL := not(shift_right(VAL,SDLEN-1));
720
--      if(SVAL = 0) then
721
--        return('0');
722
--      else
723
--        return('1');
724
--      end if;
725
--    end if;
726
--  end function;
727
 
728
end G729A_ASIP_BASIC_PKG;

powered by: WebSVN 2.1.0

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