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 loop control stack management logic
|
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_LCSTKLOG_2W is
|
40 |
|
|
generic(
|
41 |
|
|
DEPTH : natural
|
42 |
|
|
);
|
43 |
|
|
port(
|
44 |
|
|
CLK_i : in std_logic;
|
45 |
|
|
RST_i : in std_logic;
|
46 |
|
|
SRST_i : in std_logic;
|
47 |
|
|
LLBRX_i : in std_logic; -- llbri eXecute flag
|
48 |
|
|
LLERX_i : in std_logic; -- lleri eXecute flag
|
49 |
|
|
LLCRX_i : in std_logic; -- llcnt/llcnti eXecute flag
|
50 |
|
|
IMM_i : in unsigned(ALEN-1 downto 0); -- loop begin address
|
51 |
|
|
PCF0_i : in unsigned(ALEN-1 downto 0); -- IF program counter
|
52 |
|
|
PCF1_i : in unsigned(ALEN-1 downto 0); -- IF program counter
|
53 |
|
|
PCX0_i : in unsigned(ALEN-1 downto 0); -- IX program counter
|
54 |
|
|
PCX1_i : in unsigned(ALEN-1 downto 0); -- IX program counter
|
55 |
|
|
IXV_i : in std_logic_vector(2-1 downto 0);
|
56 |
|
|
|
57 |
|
|
KLL1_o : out std_logic;
|
58 |
|
|
LEND_o : out std_logic;
|
59 |
|
|
LEIS_o : out std_logic;
|
60 |
|
|
LBX_o : out std_logic; -- loop-back jump eXecute flag
|
61 |
|
|
LBTA_o : out unsigned(16-1 downto 0) -- loop-back target address
|
62 |
|
|
);
|
63 |
|
|
end G729A_ASIP_LCSTKLOG_2W;
|
64 |
|
|
|
65 |
|
|
architecture ARC of G729A_ASIP_LCSTKLOG_2W is
|
66 |
|
|
|
67 |
|
|
component G729A_ASIP_LCSTK is
|
68 |
|
|
generic(
|
69 |
|
|
DEPTH : natural
|
70 |
|
|
);
|
71 |
|
|
port(
|
72 |
|
|
CLK_i : in std_logic;
|
73 |
|
|
RST_i : in std_logic;
|
74 |
|
|
SRST_i : in std_logic;
|
75 |
|
|
PUSH_i : in std_logic;
|
76 |
|
|
POP_i : in std_logic;
|
77 |
|
|
DECR_i : in std_logic;
|
78 |
|
|
LBADR_i : in unsigned(ALEN-1 downto 0); -- loop begin address
|
79 |
|
|
LEADR_i : in unsigned(ALEN-1 downto 0); -- loop end address
|
80 |
|
|
LCNT_i : in unsigned(16-1 downto 0); -- loop count
|
81 |
|
|
|
82 |
|
|
SE_o : out std_logic;
|
83 |
|
|
SF_o : out std_logic;
|
84 |
|
|
LBADR_o : out unsigned(ALEN-1 downto 0); -- loop begin address
|
85 |
|
|
LEADR_o : out unsigned(ALEN-1 downto 0); -- loop end address
|
86 |
|
|
LCNT_o : out unsigned(16-1 downto 0) -- loop count
|
87 |
|
|
);
|
88 |
|
|
end component;
|
89 |
|
|
|
90 |
|
|
type STK_ENTRY_T is record
|
91 |
|
|
LBADR : unsigned(ALEN-1 downto 0);
|
92 |
|
|
LEADR : unsigned(ALEN-1 downto 0);
|
93 |
|
|
LCNT : unsigned(16-1 downto 0);
|
94 |
|
|
end record;
|
95 |
|
|
|
96 |
|
|
signal PUSH,POP,DECR,SE,SF : std_logic;
|
97 |
|
|
signal LLBRX,LLERX : std_logic;
|
98 |
|
|
signal STK_LBADR : unsigned(ALEN-1 downto 0);
|
99 |
|
|
signal STK_LEADR : unsigned(ALEN-1 downto 0);
|
100 |
|
|
signal STK_LCNT : unsigned(16-1 downto 0);
|
101 |
|
|
signal LBADR_q : unsigned(ALEN-1 downto 0);
|
102 |
|
|
signal LEADR_q : unsigned(ALEN-1 downto 0);
|
103 |
|
|
signal LCNT : unsigned(16-1 downto 0);
|
104 |
|
|
signal PCF_MTCH,PCX_MTCH : std_logic;
|
105 |
|
|
|
106 |
|
|
begin
|
107 |
|
|
|
108 |
|
|
-- The loop control stack is composed of DEPTH entries, each
|
109 |
|
|
-- one consisting of 3 fields:
|
110 |
|
|
-- 1) loop begin address (specified by llbri instruction)
|
111 |
|
|
-- 2) loop end address (specified by lleri instruction)
|
112 |
|
|
-- 3) loop iterations count (specified by llcnt/llcnti instruction)
|
113 |
|
|
|
114 |
|
|
-- When a llbri/lleri instruction is executed, the related operand
|
115 |
|
|
-- is saved into a temporary register.
|
116 |
|
|
-- When a llcnt/llcnti instruction is executed, the related operand
|
117 |
|
|
-- plus the saved operands of most recent llbri and lleri instructions
|
118 |
|
|
-- are pushed on the stack.
|
119 |
|
|
-- Note: instruction execution is used to trigger saving/pushing,
|
120 |
|
|
-- rather than fetching, to avoid issues with instructions laying
|
121 |
|
|
-- in the 'shadow' of a branch/jump.
|
122 |
|
|
|
123 |
|
|
U_STK : G729A_ASIP_LCSTK
|
124 |
|
|
generic map(
|
125 |
|
|
DEPTH => 2 --DEPTH
|
126 |
|
|
)
|
127 |
|
|
port map(
|
128 |
|
|
CLK_i => CLK_i,
|
129 |
|
|
RST_i => RST_i,
|
130 |
|
|
SRST_i => SRST_i,
|
131 |
|
|
PUSH_i => PUSH,
|
132 |
|
|
POP_i => POP,
|
133 |
|
|
DECR_i => DECR,
|
134 |
|
|
LBADR_i => LBADR_q,
|
135 |
|
|
LEADR_i => LEADR_q,
|
136 |
|
|
LCNT_i => LCNT,
|
137 |
|
|
|
138 |
|
|
SE_o => SE,
|
139 |
|
|
SF_o => SF,
|
140 |
|
|
LBADR_o => STK_LBADR,
|
141 |
|
|
LEADR_o => STK_LEADR,
|
142 |
|
|
LCNT_o => STK_LCNT
|
143 |
|
|
);
|
144 |
|
|
|
145 |
|
|
LCNT <= (IMM_i - 1);
|
146 |
|
|
|
147 |
|
|
-- llbri, lleri and llcr* instructions can issued only to pipe #0.
|
148 |
|
|
LLBRX <= (LLBRX_i and IXV_i(0));
|
149 |
|
|
LLERX <= (LLERX_i and IXV_i(0));
|
150 |
|
|
|
151 |
|
|
-- IX PC match flag
|
152 |
|
|
PCX_MTCH <= '1' when (
|
153 |
|
|
((IXV_i(0) = '1') and (PCX0_i = STK_LEADR)) or
|
154 |
|
|
((IXV_i(1) = '1') and (PCX1_i = STK_LEADR))
|
155 |
|
|
) else '0';
|
156 |
|
|
|
157 |
|
|
-- Stack push flag (stack is pushed whenever a llcnt/llcnti
|
158 |
|
|
-- instruction is executed).
|
159 |
|
|
|
160 |
|
|
PUSH <= LLCRX_i;
|
161 |
|
|
|
162 |
|
|
-- Stack pop flag (stack is popped whenever loop closing
|
163 |
|
|
-- instruction is executed and loop count is zero).
|
164 |
|
|
|
165 |
|
|
POP <= ((not SE) and PCX_MTCH) when (STK_LCNT = 0) else '0';
|
166 |
|
|
|
167 |
|
|
-- loop end
|
168 |
|
|
|
169 |
|
|
LEND_o <= POP;
|
170 |
|
|
|
171 |
|
|
LEIS_o <= '1' when ((IXV_i(1) = '1') and (PCX1_i = STK_LEADR) and (STK_LCNT = 0)) else '0';
|
172 |
|
|
|
173 |
|
|
-- Loop count is decremented when loop closing instruction is executed
|
174 |
|
|
|
175 |
|
|
DECR <= PCX_MTCH when (STK_LCNT > 0) else '0';
|
176 |
|
|
|
177 |
|
|
-- loop begin/end address temporary registers
|
178 |
|
|
process(CLK_i)
|
179 |
|
|
begin
|
180 |
|
|
if(CLK_i = '1' and CLK_i'event) then
|
181 |
|
|
if(LLBRX = '1') then
|
182 |
|
|
LBADR_q <= IMM_i;
|
183 |
|
|
end if;
|
184 |
|
|
if(LLERX = '1') then
|
185 |
|
|
LEADR_q <= IMM_i;
|
186 |
|
|
end if;
|
187 |
|
|
end if;
|
188 |
|
|
end process;
|
189 |
|
|
|
190 |
|
|
-- IF PC match flag
|
191 |
|
|
PCF_MTCH <= '1' when ((PCF0_i = STK_LEADR) or (PCF1_i = STK_LEADR)) else '0';
|
192 |
|
|
|
193 |
|
|
-- loop-back flag
|
194 |
|
|
LBX_o <= not(SE) when ((PCF_MTCH = '1') and (STK_LCNT > 0)) else '0';
|
195 |
|
|
|
196 |
|
|
-- loop-back target address
|
197 |
|
|
LBTA_o <= STK_LBADR;
|
198 |
|
|
|
199 |
|
|
-- Kill-instruction-in-slot-#1 flag
|
200 |
|
|
KLL1_o <= '1' when (PCF0_i = STK_LEADR) else '0';
|
201 |
|
|
|
202 |
|
|
end ARC;
|