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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_shftu.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 ASIP shift unit
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
use WORK.G729A_ASIP_BASIC_PKG.all;
39
use WORK.G729A_ASIP_ARITH_PKG.all;
40
 
41
entity G729A_ASIP_SHFT is
42
  port(
43
    SI_i : in LDWORD_T;
44
    SHFT_i : in SDWORD_T;
45
    --STRT_i : in std_logic;
46
    CTRL_i : in SHF_CTRL;
47
 
48
    SO_o : out LDWORD_T;
49
    OVF_o : out std_logic
50
  );
51
end G729A_ASIP_SHFT;
52
 
53
architecture ARC of G729A_ASIP_SHFT is
54
 
55
  constant ALL_ZERO_16 : SDWORD_T := (others => '0');
56
  constant ALL_ZERO_32 : LDWORD_T := (others => '0');
57
 
58
  signal LSO_S,RSO_S : SDWORD_T;
59
  signal LSO_L,RSO_L : LDWORD_T;
60
  signal NRMSO : SHORT_SHIFT_T;
61
  signal NRMLO : LONG_SHIFT_T;
62
  signal ISHFT : LONG_SHIFT_T;
63
  signal ISHFT_OVF : LONG_SHIFT_OVF_T;
64
  signal ICTRL : SHF_CTRL;
65
  signal SHFT : LONG_SHIFT_OVF_T;
66
 
67
begin
68
 
69
  -- (lower WORD_T) normalization shift amount
70
  NRMSO <= norm_s(SI_i(SDLEN-1 downto 0));
71
 
72
  -- normalization shift amount
73
  NRMLO <= norm_l(SI_i);
74
 
75
  SHFT <=
76
    LDLEN when (SHFT_i >= LDLEN) else
77
    -LDLEN when (SHFT_i <= -LDLEN) else
78
    to_integer(SHFT_i(6-1 downto 0));
79
 
80
  -- If shift amount is negative, reverse shift direction 
81
  -- (and make shift amount positive)
82
  process(SHFT_i,CTRL_i)
83
  begin
84
    if(SHFT_i < 0) then
85
      case (CTRL_i) is
86
        when SC_SHL => ICTRL <= SC_SHR;
87
        when SC_SHR => ICTRL <= SC_SHL;
88
        when SC_LSHL => ICTRL <= SC_LSHR;
89
        when SC_LSHR => ICTRL <= SC_LSHL;
90
        when others => ICTRL <= CTRL_i;
91
      end case;
92
    else
93
      ICTRL <= CTRL_i;
94
    end if;
95
  end process;
96
 
97
  -- check against -32 is needed to avoid invalid shift amount of 32
98
 
99
  --ISHFT <= 0 when (SHFT = -32 or SHFT = 32) else -SHFT when (SHFT_i < 0) else SHFT;
100
 
101
  process(SHFT_i)
102
    variable TMP : SDWORD_T;
103
  begin
104
    if(SHFT_i < 0) then
105
      TMP := -SHFT_i;
106
    else
107
      TMP := SHFT_i;
108
    end if;
109
    ISHFT <= to_integer(to_unsigned(TMP(5-1 downto 0)));
110
  end process;
111
 
112
  ISHFT_OVF <= -SHFT when (SHFT_i < 0) else SHFT;
113
 
114
  -- 16-bit left shifter
115
  LSO_S <= shift_left16(SI_i(SDLEN-1 downto 0),ISHFT);
116
 
117
  -- 16-bit right shifter
118
  RSO_S <= shift_right16(SI_i(SDLEN-1 downto 0),ISHFT);
119
 
120
  -- 32-bit left shifter
121
  LSO_L <= shift_left32(SI_i,ISHFT);
122
 
123
  -- 32-bit right shifter
124
  RSO_L <= shift_right32(SI_i,ISHFT);
125
 
126
  process(ICTRL,SI_i,ISHFT,ISHFT_OVF,LSO_S,RSO_S,LSO_L,RSO_L,NRMSO,NRMLO)
127
    variable ISO : LDWORD_T;
128
    variable INRMO : LONG_SHIFT_T;
129
    variable IOVF : std_logic;
130
  begin
131
    case ICTRL is
132
 
133
      when SC_SHL =>
134
        -- ISO high portion is set to all-0
135
        ISO(LDLEN-1 downto SDLEN) := (others => '0');
136
        -- check for overflow
137
        --if((NRMSO < ISHFT) or ((ISHFT > SDLEN-1) and 
138
        --  (SI_i(SDLEN-1 downto 0) /= ALL_ZERO_16))
139
        if((NRMSO < ISHFT) and (SI_i(SDLEN-1 downto 0) /= ALL_ZERO_16)) then
140
          -- overflow
141
          IOVF := '1';
142
          --if(SI_i(SDLEN-1 downto 0) < 0) then
143
          if(SI_i(SDLEN-1) = '1') then
144
            ISO(SDLEN-1 downto 0) := MIN_16;
145
          else
146
            ISO(SDLEN-1 downto 0) := MAX_16;
147
          end if;
148
        else
149
          -- regular result
150
          IOVF := '0';
151
          ISO(SDLEN-1 downto 0) := LSO_S; --(SDLEN-1 downto 0);
152
        end if;
153
 
154
      when SC_SHR =>
155
        -- ISO high portion is set to all-0
156
        ISO(LDLEN-1 downto SDLEN) := (others => '0');
157
        -- overflow flag is unchanged 
158
        IOVF := '0';
159
        -- check for underflow
160
        if(ISHFT_OVF >= SDLEN-1) then
161
          -- underflow
162
          --if(SI_i(SDLEN-1 downto 0) < 0) then
163
          if(SI_i(SDLEN-1) = '1') then
164
            ISO(SDLEN-1 downto 0) := to_signed(-1,SDLEN);
165
          else
166
            ISO(SDLEN-1 downto 0) := to_signed(0,SDLEN);
167
          end if;
168
        else
169
          -- regular result
170
          ISO(SDLEN-1 downto 0) := RSO_S; --(SDLEN-1 downto 0);
171
        end if;
172
 
173
      when SC_LSHL =>
174
        -- check for overflow
175
        if(NRMLO < ISHFT and SI_i /= ALL_ZERO_32) then
176
          -- overflow
177
          IOVF := '1';
178
          --if(SI_i < 0) then
179
          if(SI_i(LDLEN-1) = '1') then
180
            ISO := MIN_32;
181
          else
182
            ISO := MAX_32;
183
          end if;
184
        else
185
          -- regular result
186
          IOVF := '0';
187
          ISO := LSO_L;
188
        end if;
189
 
190
      when SC_LSHR =>
191
        -- overflow flag is unchanged 
192
        IOVF := '0';
193
        -- check for underflow
194
        if(ISHFT_OVF >= LDLEN-1) then
195
          -- underflow
196
          --if(SI_i < 0) then
197
          if(SI_i(LDLEN-1) = '1') then
198
            ISO := to_signed(-1,LDLEN);
199
          else
200
            ISO := to_signed(0,LDLEN);
201
          end if;
202
        else
203
          -- regular result
204
          ISO := RSO_L;
205
        end if;
206
 
207
      when SC_NRMS =>
208
        ISO := to_signed(NRMSO,LDLEN);
209
        IOVF := '0';
210
 
211
      when SC_NRML =>
212
        ISO := to_signed(NRMLO,LDLEN);
213
        IOVF := '0';
214
 
215
      when others => -- SC_NIL
216
        ISO := SI_i;
217
        IOVF := '0';
218
 
219
    end case;
220
 
221
    SO_o <= ISO;
222
    OVF_o <= IOVF;
223
 
224
  end process;
225
 
226
end ARC;

powered by: WebSVN 2.1.0

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