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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_idec.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
-- Instruction decoder (stage 2)
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_OP_PKG.all;
39
 
40
entity G729A_ASIP_IDEC2 is
41
  port(
42
    INSTR_i : in std_logic_vector(ILEN-1 downto 0);
43
    DRA_i : in std_logic_vector(LDLEN-1 downto 0);
44
    DRB_i : in std_logic_vector(LDLEN-1 downto 0);
45
    PCP1_i : in std_logic_vector(ALEN-1 downto 0);
46
    OPB_IMM_i : in std_logic;
47
    OPB_i : in LDWORD_T;
48
    ID_V_i : in std_logic;
49
 
50
    OPA_o : out LDWORD_T;
51
    OPB_o : out LDWORD_T;
52
    OPC_o : out SDWORD_T;
53
    IMM_o : out SDWORD_T;
54
    JL_o : out std_logic;
55
    HALT_o : out std_logic
56
  );
57
end G729A_ASIP_IDEC2;
58
 
59
architecture ARC of G729A_ASIP_IDEC2 is
60
 
61
  signal OP1 : integer range 0 to 16-1;
62
  signal OP2 : integer range 0 to 16-1;
63
  signal OP2_RRR : integer range 0 to 256-1;
64
  signal IMM8,IMM8_S : std_logic_vector(8-1 downto 0);
65
  signal IMM12,IMM12_S : std_logic_vector(12-1 downto 0);
66
  signal IMM16,IMM16_S : std_logic_vector(16-1 downto 0);
67
  signal IMM : signed(16-1 downto 0);
68
  signal JL : std_logic;
69
 
70
  function EXTS16(V : std_logic_vector) return signed is
71
    variable S : signed(SDLEN-1 downto 0);
72
  begin
73
    S(V'HIGH downto 0) := to_signed(V);
74
    S(SDLEN-1 downto V'HIGH+1) := (others => V(V'HIGH));
75
    return(S);
76
  end function;
77
 
78
  function EXTS32(V : std_logic_vector) return signed is
79
    variable S : signed(LDLEN-1 downto 0);
80
  begin
81
    S(V'HIGH downto 0) := to_signed(V);
82
    S(LDLEN-1 downto V'HIGH+1) := (others => V(V'HIGH));
83
    return(S);
84
  end function;
85
 
86
  function to_signed(U : unsigned) return signed is
87
    variable S : signed(U'HIGH downto U'LOW);
88
  begin
89
    for i in U'HIGH downto U'LOW loop
90
      S(i) := U(i);
91
    end loop;
92
    return(S);
93
  end function;
94
 
95
begin
96
 
97
  -- instruction subfields extraction
98
  process(INSTR_i)
99
    --variable B0,B1,B2,B3,B4,B5 : std_logic_vector(4-1 downto 0);
100
    variable B0,B1,B5 : std_logic_vector(4-1 downto 0);
101
    variable TMP : std_logic_vector(8-1 downto 0);
102
  begin
103
 
104
    B0 := INSTR_i(4*1-1 downto 4*0);
105
    B1 := INSTR_i(4*2-1 downto 4*1);
106
    --B2 := INSTR_i(4*3-1 downto 4*2);
107
    --B3 := INSTR_i(4*4-1 downto 4*3);
108
    --B4 := INSTR_i(4*5-1 downto 4*4);
109
    B5 := INSTR_i(4*6-1 downto 4*5);
110
 
111
    -- major opcode
112
    OP1 <= to_integer(to_unsigned(B5));
113
 
114
    -- minor opcode
115
    OP2 <= to_integer(to_unsigned(B0));
116
 
117
    -- minor opcode for RRR type instructions
118
 
119
    -- WARNING: this extra step is needed to
120
    -- insure correct ordering!
121
    TMP := (B1 & B0);
122
 
123
    OP2_RRR <= to_integer(to_unsigned(TMP));
124
 
125
    -- immediate operands
126
    IMM8 <= INSTR_i(12-1 downto 4);
127
    IMM8_S <= INSTR_i(20-1 downto 16) & INSTR_i(8-1 downto 4);
128
    IMM12 <= INSTR_i(12-1 downto 0);
129
    IMM12_S <= INSTR_i(20-1 downto 16) & INSTR_i(12-1 downto 4);
130
    IMM16 <= INSTR_i(16-1 downto 0);
131
    IMM16_S <= INSTR_i(20-1 downto 4);
132
 
133
  end process;
134
 
135
  -- jump & link instruction flag
136
  JL <= '1' when ((OP1 = 0 and OP2_RRR = 27) or (OP1 = 11)) else '0';
137
 
138
  JL_o <= JL;
139
 
140
  -- operand A is supplied by register file, unless
141
  -- instruction is a jump & link one (operand value
142
  -- is return address).
143
 
144
  OPA_o <= EXTS32(PCP1_i) when (JL = '1') else to_signed(DRA_i);
145
 
146
  -- operand B is supplied by register file, unless
147
  -- instruction takes an immediate operand.
148
 
149
  OPB_o <= OPB_i when OPB_IMM_i = '1' else to_signed(DRB_i);
150
 
151
  -- Operand C (actually used only by beq, bne, st and stpp instructions)
152
  OPC_o <= EXTS16(IMM8_S);
153
 
154
  -- immediate value selector
155
  process(OP1,OP2,IMM8,IMM8_S,IMM12,IMM12_S,IMM16,IMM16_S)
156
  begin
157
    case OP1 is
158
      when 8 =>
159
        if(OP2 = 8 or OP2 = 9 or OP2 = 11 or OP2 = 13) then
160
          IMM <= EXTS16(IMM8_S);
161
        else
162
          IMM <= EXTS16(IMM8);
163
        end if;
164
      when 12 =>
165
        if(OP2 = 8 or OP2 = 9 or OP2 = 10 or OP2 = 11) then
166
          IMM <= to_signed(IMM16_S);
167
        else
168
          IMM <= EXTS16(IMM12_S);
169
        end if;
170
      when 11|13 =>
171
        IMM <= to_signed(IMM16);
172
      when others =>
173
        IMM <= EXTS16(IMM12);
174
    end case;
175
  end process;
176
 
177
  IMM_o <= IMM;
178
 
179
  -- increment-rA flag generation
180
  HALT_o <= ID_V_i when (OP1 = 0 and OP2_RRR = 29) else '0';
181
 
182
end ARC;

powered by: WebSVN 2.1.0

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