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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_regfile_16x16_2w.vhd] - Blame information for rev 3

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 16x16 Register File
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
entity G729A_ASIP_REGFILE_16X16_2W is
40
  port(
41
    CLK_i : in std_logic;
42
    RA0_i : in RID_T;
43
    RA1_i : in RID_T;
44
    RA2_i : in RID_T;
45
    RA3_i : in RID_T;
46
    WA0_i : in RID_T;
47
    WA1_i : in RID_T;
48
    LR0_i : in std_logic;
49
    LR1_i : in std_logic;
50
    LR2_i : in std_logic;
51
    LR3_i : in std_logic;
52
    LW0_i : in std_logic;
53
    LW1_i : in std_logic;
54
    WE0_i : in std_logic;
55
    WE1_i : in std_logic;
56
    D0_i : in std_logic_vector(LDLEN-1 downto 0);
57
    D1_i : in std_logic_vector(LDLEN-1 downto 0);
58
 
59
    Q0_o : out std_logic_vector(LDLEN-1 downto 0);
60
    Q1_o : out std_logic_vector(LDLEN-1 downto 0);
61
    Q2_o : out std_logic_vector(LDLEN-1 downto 0);
62
    Q3_o : out std_logic_vector(LDLEN-1 downto 0)
63
  );
64
end G729A_ASIP_REGFILE_16X16_2W;
65
 
66
architecture ARC of G729A_ASIP_REGFILE_16X16_2W is
67
 
68
  constant REGNUM : natural := 16;
69
 
70
  subtype WORD_T is std_logic_vector(SDLEN-1 downto 0);
71
  type MEM_T is array (REGNUM/2-1 downto 0) of WORD_T;
72 3 madsilicon
  type RID_VEC_T is array (natural range <>) of RID_T;
73
  type WORD_VEC_T is array (natural range <>) of WORD_T;
74 2 madsilicon
 
75
  signal REG_EVEN,REG_ODD : MEM_T;
76
  signal WE0_EVEN,WE0_ODD : std_logic;
77
  signal WE1_EVEN,WE1_ODD : std_logic;
78
  signal IWA0,IWA1 : natural range 0 to REGNUM/2-1;
79
  signal WA0_LSB,WA1_LSB : std_logic;
80
  signal IRA0,IRA1,IRA2,IRA3 : natural range 0 to REGNUM/2-1;
81
  signal RA0_LSB,RA1_LSB,RA2_LSB,RA3_LSB : std_logic;
82
  signal D0_LO,D0_HI : std_logic_vector(SDLEN-1 downto 0);
83 3 madsilicon
  signal WE_EVEN,WE_ODD : std_logic_vector(REGNUM/2-1 downto 0);
84
  signal D_EVEN,D_ODD : WORD_VEC_T(REGNUM/2-1 downto 0);
85 2 madsilicon
  signal D0_EVEN,D0_ODD : std_logic_vector(SDLEN-1 downto 0);
86
  signal D1_LO,D1_HI : std_logic_vector(SDLEN-1 downto 0);
87
  signal D1_EVEN,D1_ODD : std_logic_vector(SDLEN-1 downto 0);
88
  signal Q0_EVEN,Q1_EVEN : std_logic_vector(SDLEN-1 downto 0);
89
  signal Q0_ODD,Q1_ODD : std_logic_vector(SDLEN-1 downto 0);
90
  signal Q2_EVEN,Q3_EVEN : std_logic_vector(SDLEN-1 downto 0);
91
  signal Q2_ODD,Q3_ODD : std_logic_vector(SDLEN-1 downto 0);
92
 
93
  function GET_LSB(N : natural range 0 to 16-1) return std_logic is
94
    variable U : unsigned(4-1 downto 0);
95
  begin
96
    U := to_unsigned(N,4);
97
    return(U(0));
98
  end function;
99
 
100
begin
101
 
102
  ---------------------------------------------
103
 
104
  D0_LO <= D0_i(SDLEN-1 downto 0);
105
  D0_HI <= D0_i(SDLEN*2-1 downto SDLEN);
106
 
107
  D1_LO <= D1_i(SDLEN-1 downto 0);
108
  D1_HI <= D1_i(SDLEN*2-1 downto SDLEN);
109
 
110
  ---------------------------------------------
111
 
112
  IWA0 <= WA0_i/2;
113
  IWA1 <= WA1_i/2;
114
 
115
  WA0_LSB <= GET_LSB(WA0_i);
116
  WA1_LSB <= GET_LSB(WA1_i);
117
 
118 3 madsilicon
  ---------------------------------------------
119
 
120
  G0 : for k in 0 to REGNUM/2-1 generate
121
 
122
    WE_EVEN(k) <= '1' when (
123
      (WE0_i = '1' and (IWA0 = k) and (WA0_LSB = '0') and (LW0_i = '0')) or
124
      (WE1_i = '1' and (IWA1 = k) and (WA1_LSB = '0') and (LW1_i = '0')) or
125
      (WE0_i = '1' and (IWA0 = k) and (LW0_i = '1')) or
126
      (WE1_i = '1' and (IWA1 = k) and (LW1_i = '1'))
127
    ) else '0';
128
 
129
    WE_ODD(k) <= '1' when (
130
      (WE0_i = '1' and (IWA0 = k) and (WA0_LSB = '1') and (LW0_i = '0')) or
131
      (WE1_i = '1' and (IWA1 = k) and (WA1_LSB = '1') and (LW1_i = '0')) or
132
      (WE0_i = '1' and (IWA0 = k) and (LW0_i = '1')) or
133
      (WE1_i = '1' and (IWA1 = k) and (LW1_i = '1'))
134
    ) else '0';
135
 
136
    process(WE0_i,WE1_i,IWA0,IWA1,WA0_LSB,WA1_LSB,LW0_i,LW1_i,
137
      D0_LO,D0_HI,D1_LO,D1_HI)
138
      variable S : natural range 0 to 4-1;
139
    begin
140
 
141
      -- Write from port #1 must get higher priority because
142
      -- instruction #1 is newer than instruction #0.
143
 
144
      if(
145
        (WE1_i = '1') and (IWA1 = k) and
146
        ((WA1_LSB = '0') or (LW1_i = '1'))
147
      ) then
148
        -- write from port #1
149
        D_EVEN(k) <= D1_LO;
150
      else
151
        -- write from port #0
152
        D_EVEN(k) <= D0_LO;
153 2 madsilicon
      end if;
154 3 madsilicon
 
155
      if(
156
       (WE1_i = '1') and (IWA1 = k) and
157
       (WA1_LSB = '1') and (LW1_i = '0')
158
      ) then
159
        -- word write from port #1
160
        S := 0;
161
      elsif(
162
       (WE1_i = '1') and (IWA1 = k) and
163
       (LW1_i = '1')
164
      ) then
165
        -- long-word write from port #1
166
        S := 1;
167
      elsif(
168
       (WE0_i = '1') and (IWA0 = k) and
169
       (WA0_LSB = '1') and (LW0_i = '0')
170
      ) then
171
        -- word write from port #0
172
        S := 2;
173
      else
174
        -- long-word write from port #0
175
        S := 3;
176 2 madsilicon
      end if;
177
 
178 3 madsilicon
      case S is
179
        when 0 => D_ODD(k) <= D1_LO;
180
        when 1 => D_ODD(k) <= D1_HI;
181
        when 2 => D_ODD(k) <= D0_LO;
182
        when 3 => D_ODD(k) <= D0_HI;
183
      end case;
184
 
185
    end process;
186
 
187
    process(CLK_i)
188
    begin
189
      if(CLK_i = '1' and CLK_i'event) then
190
        if(WE_EVEN(k) = '1') then
191
          REG_EVEN(k) <= D_EVEN(k);
192
        end if;
193
        if(WE_ODD(k) = '1') then
194
          REG_ODD(k) <= D_ODD(k);
195
        end if;
196 2 madsilicon
      end if;
197 3 madsilicon
    end process;
198 2 madsilicon
 
199 3 madsilicon
  end generate;
200
 
201 2 madsilicon
  ---------------------------------------------
202
 
203
  IRA0 <= RA0_i/2;
204
  IRA1 <= RA1_i/2;
205
  IRA2 <= RA2_i/2;
206
  IRA3 <= RA3_i/2;
207
 
208
  RA0_LSB <= GET_LSB(RA0_i);
209
  RA1_LSB <= GET_LSB(RA1_i);
210
  RA2_LSB <= GET_LSB(RA2_i);
211
  RA3_LSB <= GET_LSB(RA3_i);
212
 
213
  Q0_EVEN <= REG_EVEN(IRA0);
214
  Q1_EVEN <= REG_EVEN(IRA1);
215
  Q2_EVEN <= REG_EVEN(IRA2);
216
  Q3_EVEN <= REG_EVEN(IRA3);
217
 
218
  Q0_ODD <= REG_ODD(IRA0);
219
  Q1_ODD <= REG_ODD(IRA1);
220
  Q2_ODD <= REG_ODD(IRA2);
221
  Q3_ODD <= REG_ODD(IRA3);
222
 
223
  process(RA0_LSB,LR0_i,Q0_EVEN,Q0_ODD)
224
  begin
225
    if(LR0_i = '0' and RA0_LSB = '1') then
226
      Q0_o(SDLEN-1 downto 0) <= Q0_ODD;
227
    else
228
      Q0_o(SDLEN-1 downto 0) <= Q0_EVEN;
229
    end if;
230
    if(LR0_i = '0') then
231
      Q0_o(SDLEN*2-1 downto SDLEN) <= (others => '0');
232
    else
233
      Q0_o(SDLEN*2-1 downto SDLEN) <= Q0_ODD;
234
    end if;
235
  end process;
236
 
237
  process(RA1_LSB,LR1_i,Q1_EVEN,Q1_ODD)
238
  begin
239
    if(LR1_i = '0' and RA1_LSB = '1') then
240
      Q1_o(SDLEN-1 downto 0) <= Q1_ODD;
241
    else
242
      Q1_o(SDLEN-1 downto 0) <= Q1_EVEN;
243
    end if;
244
    if(LR1_i = '0') then
245
      Q1_o(SDLEN*2-1 downto SDLEN) <= (others => '0');
246
    else
247
      Q1_o(SDLEN*2-1 downto SDLEN) <= Q1_ODD;
248
    end if;
249
  end process;
250
 
251
  process(RA2_LSB,LR2_i,Q2_EVEN,Q2_ODD)
252
  begin
253
    if(LR2_i = '0' and RA2_LSB = '1') then
254
      Q2_o(SDLEN-1 downto 0) <= Q2_ODD;
255
    else
256
      Q2_o(SDLEN-1 downto 0) <= Q2_EVEN;
257
    end if;
258
    if(LR2_i = '0') then
259
      Q2_o(SDLEN*2-1 downto SDLEN) <= (others => '0');
260
    else
261
      Q2_o(SDLEN*2-1 downto SDLEN) <= Q2_ODD;
262
    end if;
263
  end process;
264
 
265
  process(RA3_LSB,LR3_i,Q3_EVEN,Q3_ODD)
266
  begin
267
    if(LR3_i = '0' and RA3_LSB = '1') then
268
      Q3_o(SDLEN-1 downto 0) <= Q3_ODD;
269
    else
270
      Q3_o(SDLEN-1 downto 0) <= Q3_EVEN;
271
    end if;
272
    if(LR3_i = '0') then
273
      Q3_o(SDLEN*2-1 downto SDLEN) <= (others => '0');
274
    else
275
      Q3_o(SDLEN*2-1 downto SDLEN) <= Q3_ODD;
276
    end if;
277
  end process;
278
 
279 3 madsilicon
end ARC;

powered by: WebSVN 2.1.0

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