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

Subversion Repositories risc5x

[/] [risc5x/] [trunk/] [mux2_add_reg.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mikej
--
2
-- Risc5x
3
-- www.OpenCores.Org - November 2001
4
--
5
--
6
-- This library is free software; you can distribute it and/or modify it
7
-- under the terms of the GNU Lesser General Public License as published
8
-- by the Free Software Foundation; either version 2.1 of the License, or
9
-- (at your option) any later version.
10
--
11
-- This library is distributed in the hope that it will be useful, but
12
-- WITHOUT ANY WARRANTY; without even the implied warranty of
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
-- See the GNU Lesser General Public License for more details.
15
--
16
-- A RISC CPU core.
17
--
18
-- (c) Mike Johnson 2001. All Rights Reserved.
19
-- mikej@opencores.org for support or any other issues.
20
--
21
-- Revision list
22
--
23
-- version 1.0 initial opencores release
24
--
25
 
26
-- MUX2_ADD_REG
27
--
28
-- DOUT <= REG_DOUT + ADD_VAL when ADD = '1'
29
--      <= LOAD_VAL           when ADD = '0'
30
 
31
-- REG_DOUT <= DOUT            when ENA = '1' and rising_edge(CLK)
32
--          <= (others => '1') when PRESET = '1'
33
library ieee;
34
  use ieee.std_logic_1164.all;
35
  use ieee.std_logic_arith.all;
36
  use ieee.std_logic_unsigned.all;
37
 
38
entity MUX2_ADD_REG is
39
  generic (
40
    WIDTH         : in  natural := 11
41
    );
42
  port (
43
    ADD_VAL       : in  std_logic_vector(WIDTH-1 downto 0);
44
    LOAD_VAL      : in  std_logic_vector(WIDTH-1 downto 0);
45
 
46
    ADD           : in  std_logic;
47
 
48
    PRESET        : in  std_logic; -- async
49
    ENA           : in  std_logic;
50
    CLK           : in  std_logic;
51
 
52
    DOUT          : out std_logic_vector(WIDTH-1 downto 0);
53
    REG_DOUT      : out std_logic_vector(WIDTH-1 downto 0)
54
    );
55
end;
56
--
57
-- USE THIS ARCHITECTURE FOR XILINX
58
--
59
use work.pkg_xilinx_prims.all;
60
library ieee;
61
  use ieee.std_logic_1164.all;
62
  use ieee.std_logic_arith.all;
63
  use ieee.std_logic_unsigned.all;
64
 
65
architecture VIRTEX of MUX2_ADD_REG is
66
 
67
    signal lut_op       : std_logic_vector(WIDTH-1 downto 0);
68
    signal mult_and_op  : std_logic_vector(WIDTH-1 downto 0);
69
    signal carry        : std_logic_vector(WIDTH   downto 0);
70
    signal op_int       : std_logic_vector(WIDTH-1 downto 0);
71
    signal reg_op_int   : std_logic_vector(WIDTH-1 downto 0);
72
 
73
    function loc(i : integer) return integer is
74
    begin
75
      return (((WIDTH+1)/2)-1) - i/2;
76
    end loc;
77
 
78
begin
79
  carry(0) <= '0';
80
  INST : for i in 0 to WIDTH-1 generate
81
    attribute RLOC of u_lut  : label is "R" & integer'image(loc(i)) & "C0.S1";
82
    attribute RLOC of u_1    : label is "R" & integer'image(loc(i)) & "C0.S1";
83
    attribute RLOC of u_2    : label is "R" & integer'image(loc(i)) & "C0.S1";
84
    attribute RLOC of u_3    : label is "R" & integer'image(loc(i)) & "C0.S1";
85
    attribute RLOC of u_reg  : label is "R" & integer'image(loc(i)) & "C0.S1";
86
    attribute INIT of u_lut  : label is "7D28";
87
    begin
88
      u_lut :  LUT4
89
      --pragma translate_off
90
      generic map (
91
        INIT => str2slv(u_lut'INIT)
92
        )
93
      --pragma translate_on
94
      port map (
95
        I0 => ADD,
96
        I1 => ADD_VAL(i),
97
        I2 => reg_op_int(i),
98
        I3 => LOAD_VAL(i),
99
        O  => lut_op(i)
100
        );
101
 
102
      u_1 : MULT_AND
103
      port map (
104
        I0 => ADD,
105
        I1 => ADD_VAL(i),
106
        LO => mult_and_op(i)
107
        );
108
 
109
      u_2 : MUXCY
110
      port map (
111
        DI => mult_and_op(i),
112
        CI => carry(i),
113
        S  => lut_op(i),
114
        O  => carry(i+1)
115
        );
116
 
117
      u_3 : XORCY
118
      port map (
119
        LI => lut_op(i),
120
        CI => carry(i),
121
        O  => op_int(i)
122
        );
123
 
124
      u_reg : FDPE
125
      port map (
126
        Q  => reg_op_int(i),
127
        D  => op_int(i),
128
        C  => CLK,
129
        CE => ENA,
130
        PRE=> PRESET
131
        );
132
  end generate;
133
  DOUT <= op_int;
134
  REG_DOUT <= reg_op_int;
135
end Virtex;
136
 
137
--pragma translate_off
138
 
139
library ieee;
140
use ieee.std_logic_1164.all;
141
use ieee.std_logic_arith.all;
142
use ieee.std_logic_unsigned.all;
143
 
144
architecture RTL of MUX2_ADD_REG is
145
signal op_int       : std_logic_vector(WIDTH-1 downto 0);
146
signal reg_op_int   : std_logic_vector(WIDTH-1 downto 0);
147
begin -- architecture
148
 
149
p_comb : process(ADD,reg_op_int,ADD_VAL,LOAD_VAL)
150
begin
151
if (ADD = '1') then
152
 op_int <= reg_op_int + ADD_VAL;
153
else
154
 op_int <= LOAD_VAL;
155
end if;
156
end process;
157
 
158
p_opreg : process(PRESET,CLK)
159
begin
160
if (PRESET = '1') then
161
 reg_op_int <= (others => '1');
162
elsif CLK'event and (CLK = '1') then
163
 if (ENA = '1') then
164
   reg_op_int <= op_int;
165
 end if;
166
end if;
167
end process;
168
DOUT <= op_int;
169
REG_DOUT <= reg_op_int;
170
end RTL;
171
 
172
--pragma translate_on
173
 

powered by: WebSVN 2.1.0

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