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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [vhdl/] [mlite_pack.vhd] - Blame information for rev 44

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 rhoads
---------------------------------------------------------------------
2 43 rhoads
-- TITLE: Plasma Misc. Package
3 39 rhoads
-- AUTHOR: Steve Rhoads (rhoadss@yahoo.com)
4
-- DATE CREATED: 2/15/01
5
-- FILENAME: mlite_pack.vhd
6 43 rhoads
-- PROJECT: Plasma CPU core
7 39 rhoads
-- COPYRIGHT: Software placed into the public domain by the author.
8
--    Software 'as is' without warranty.  Author liable for nothing.
9
-- DESCRIPTION:
10 43 rhoads
--    Data types, constants, and add functions needed for the Plasma CPU.
11 39 rhoads
---------------------------------------------------------------------
12
library ieee;
13
use ieee.std_logic_1164.all;
14
 
15
package mlite_pack is
16
   constant ZERO          : std_logic_vector(31 downto 0) :=
17
      "00000000000000000000000000000000";
18
   constant ONES          : std_logic_vector(31 downto 0) :=
19
      "11111111111111111111111111111111";
20
   --make HIGH_Z equal to ZERO if compiler complains
21
   constant HIGH_Z        : std_logic_vector(31 downto 0) :=
22
      "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
23
 
24
--   type alu_function_type is (alu_nothing, alu_add, alu_subtract, 
25
--      alu_less_than, alu_less_than_signed, alu_equal, alu_not_equal,
26
--      alu_ltz, alu_lez, alu_eqz, alu_nez, alu_gez, alu_gtz,
27
--      alu_or, alu_and, alu_xor, alu_nor);
28
   subtype alu_function_type is std_logic_vector(4 downto 0);
29
   constant alu_nothing   : alu_function_type := "00000";
30
   constant alu_add       : alu_function_type := "00010";
31
   constant alu_subtract  : alu_function_type := "00011";
32
   constant alu_less_than : alu_function_type := "00100";
33
   constant alu_less_than_signed : alu_function_type := "00101";
34
   constant alu_equal     : alu_function_type := "00110";
35
   constant alu_not_equal : alu_function_type := "00111";
36
   constant alu_ltz       : alu_function_type := "01000";
37
   constant alu_lez       : alu_function_type := "01001";
38
   constant alu_eqz       : alu_function_type := "01010";
39
   constant alu_nez       : alu_function_type := "01011";
40
   constant alu_gez       : alu_function_type := "01100";
41
   constant alu_gtz       : alu_function_type := "01101";
42
   constant alu_or        : alu_function_type := "01110";
43
   constant alu_and       : alu_function_type := "01111";
44
   constant alu_xor       : alu_function_type := "10001";
45
   constant alu_nor       : alu_function_type := "10010";
46
 
47
--   type shift_function_type is (
48
--      shift_nothing, shift_left_unsigned,
49
--      shift_right_signed, do_right_unsigned);
50
   subtype shift_function_type is std_logic_vector(1 downto 0);
51
   constant shift_nothing        : shift_function_type := "00";
52
   constant shift_left_unsigned  : shift_function_type := "01";
53
   constant shift_right_signed   : shift_function_type := "11";
54
   constant shift_right_unsigned : shift_function_type := "10";
55
 
56
--   type mult_function_type is (
57
--      mult_nothing, mult_read_lo, mult_read_hi, mult_write_lo, 
58
--      mult_write_hi, mult_mult, mult_divide, mult_signed_divide);
59 44 rhoads
   subtype mult_function_type is std_logic_vector(3 downto 0);
60
   constant mult_nothing       : mult_function_type := "0000";
61
   constant mult_read_lo       : mult_function_type := "0001";
62
   constant mult_read_hi       : mult_function_type := "0010";
63
   constant mult_write_lo      : mult_function_type := "0011";
64
   constant mult_write_hi      : mult_function_type := "0100";
65
   constant mult_mult          : mult_function_type := "0101";
66
   constant mult_signed_mult   : mult_function_type := "0110";
67
   constant mult_divide        : mult_function_type := "0111";
68
   constant mult_signed_divide : mult_function_type := "1000";
69 39 rhoads
 
70
--   type a_source_type is (from_reg_source, from_imm10_6);
71
   subtype a_source_type is std_logic_vector(1 downto 0);
72
   constant a_from_reg_source : a_source_type := "00";
73
   constant a_from_imm10_6    : a_source_type := "01";
74
   constant a_from_pc         : a_source_type := "10";
75
 
76
--   type b_source_type is (from_reg_target, from_imm, from_signed_imm);
77
   subtype b_source_type is std_logic_vector(1 downto 0);
78
   constant b_from_reg_target : b_source_type := "00";
79
   constant b_from_imm        : b_source_type := "01";
80
   constant b_from_signed_imm : b_source_type := "10";
81
   constant b_from_immX4      : b_source_type := "11";
82
 
83
--   type c_source_type is (from_null, from_alu, from_shift, 
84
--      from_mult, from_memory, from_pc, from_imm_shift16,
85
--      from_reg_source_nez, from_reg_source_eqz);
86
   subtype c_source_type is std_logic_vector(2 downto 0);
87
   constant c_from_null       : c_source_type := "000";
88
   constant c_from_alu        : c_source_type := "001";
89
   constant c_from_shift      : c_source_type := "001"; --same as alu
90
   constant c_from_mult       : c_source_type := "001"; --same as alu
91
   constant c_from_memory     : c_source_type := "010";
92
   constant c_from_pc         : c_source_type := "011";
93
   constant c_from_pc_plus4   : c_source_type := "100";
94
   constant c_from_imm_shift16: c_source_type := "101";
95
   constant c_from_reg_sourcen: c_source_type := "110";
96
 
97
--   type pc_source_type is (from_inc4, from_inc8, from_reg_source, 
98
--      from_opcode25_0, from_branch, from_lbranch);
99
   subtype pc_source_type is std_logic_vector(1 downto 0);
100
   constant from_inc4       : pc_source_type := "00";
101
   constant from_opcode25_0 : pc_source_type := "01";
102
   constant from_branch     : pc_source_type := "10";
103
   constant from_lbranch    : pc_source_type := "11";
104
 
105
   subtype branch_function_type is std_logic_vector(2 downto 0);
106
   constant branch_ltz : branch_function_type := "000";
107
   constant branch_lez : branch_function_type := "001";
108
   constant branch_eq  : branch_function_type := "010";
109
   constant branch_ne  : branch_function_type := "011";
110
   constant branch_gez : branch_function_type := "100";
111
   constant branch_gtz : branch_function_type := "101";
112
   constant branch_yes : branch_function_type := "110";
113
 
114
   -- mode(32=1,16=2,8=3), signed, write
115
   subtype mem_source_type is std_logic_vector(3 downto 0);
116
   constant mem_none    : mem_source_type := "0000";
117
   constant mem_read32  : mem_source_type := "0100";
118
   constant mem_write32 : mem_source_type := "0101";
119
   constant mem_read16  : mem_source_type := "1000";
120
   constant mem_read16s : mem_source_type := "1010";
121
   constant mem_write16 : mem_source_type := "1001";
122
   constant mem_read8   : mem_source_type := "1100";
123
   constant mem_read8s  : mem_source_type := "1110";
124
   constant mem_write8  : mem_source_type := "1101";
125
 
126
   function bv_to_integer(bv: in std_logic_vector) return integer;
127
   function bv_adder(a     : in std_logic_vector(32 downto 0);
128
                     b     : in std_logic_vector(32 downto 0);
129
                     do_sub: in std_logic) return std_logic_vector;
130
   function bv_adder_lookahead(
131
                     a     : in std_logic_vector(32 downto 0);
132
                     b     : in std_logic_vector(32 downto 0);
133
                     do_sub: in std_logic) return std_logic_vector;
134
   function bv_negate(a : in std_logic_vector) return std_logic_vector;
135
   function bv_increment(a : in std_logic_vector(31 downto 2)
136
                     ) return std_logic_vector;
137
   function bv_inc6(a : in std_logic_vector
138
                     ) return std_logic_vector;
139
end; --package mlite_pack
140
 
141
package body mlite_pack is
142
 
143
function add_1(a:integer) return integer is
144
begin
145
   return a+1;
146
end; --function
147
 
148
function bv_to_integer(bv: in std_logic_vector) return integer is
149
   variable result : integer;
150
   variable b      : integer;
151
begin
152
   result := 0;
153
   b := 0;
154
   for index in bv'range loop
155
      if bv(index) = '1' then
156
         b := 1;
157
      else
158
         b := 0;
159
      end if;
160
      result := result * 2 + b;
161
   end loop;
162
   return result;
163
end; --function bv_to_integer
164
 
165
function bv_adder(a     : in std_logic_vector(32 downto 0);
166
                  b     : in std_logic_vector(32 downto 0);
167
                  do_sub: in std_logic) return std_logic_vector is
168
   variable carry_in : std_logic;
169
   variable bb       : std_logic_vector(32 downto 0);
170
   variable result   : std_logic_vector(32 downto 0);
171
begin
172
   result := "000000000000000000000000000000000";
173
   if do_sub = '0' then
174
      bb := b;
175
      carry_in := '0';
176
   else
177
      bb := not b;
178
      carry_in := '1';
179
   end if;
180
   for index in 0 to 32 loop
181
      result(index) := a(index) xor bb(index) xor carry_in;
182
      carry_in := (carry_in and (a(index) or bb(index))) or
183
                  (a(index) and bb(index));
184
   end loop;
185
   return result;
186
end; --function
187
 
188
function bv_adder_lookahead(
189
                  a     : in std_logic_vector(32 downto 0);
190
                  b     : in std_logic_vector(32 downto 0);
191
                  do_sub: in std_logic) return std_logic_vector is
192
   variable carry    : std_logic_vector(32 downto 0);
193
   variable p, g     : std_logic_vector(32 downto 0);
194
   variable bb       : std_logic_vector(32 downto 0);
195
   variable result   : std_logic_vector(32 downto 0);
196
   variable i        : natural;
197
begin
198
   carry := "000000000000000000000000000000000";
199
   if do_sub = '0' then
200
      bb := b;
201
      carry(0) := '0';
202
   else
203
      bb := not b;
204
      carry(0) := '1';
205
   end if;
206
 
207
   p := a or bb;   --propogate
208
   g := a and bb;  --generate
209
   for index in 0 to 7 loop
210
      i := index*4;
211
      carry(i+1) := g(i) or
212
                    (p(i) and carry(i));
213
      i := index*4+1;
214
      carry(i+1) := g(i) or
215
                    (p(i) and g(i-1)) or
216
                    ((p(i) and p(i-1)) and carry(i-1));
217
      i := index*4+2;
218
      carry(i+1) := g(i) or
219
                    (p(i) and g(i-1)) or
220
                    (p(i) and p(i-1) and g(i-2)) or
221
                    ((p(i) and p(i-1) and p(i-2)) and carry(i-2));
222
      i := index*4+3;
223
      carry(i+1) := g(i) or
224
                    (p(i) and g(i-1)) or
225
                    (p(i) and p(i-1) and g(i-2)) or
226
                    (p(i) and p(i-1) and p(i-2) and g(i-3)) or
227
                    (((p(i) and p(i-1)) and (p(i-2) and p(i-3)))
228
                       and carry(i-3));
229
   end loop;
230
   result := (a xor bb) xor carry;
231
   return result;
232
end; --function
233
 
234
function bv_negate(a : in std_logic_vector) return std_logic_vector is
235
   variable carry_in : std_logic;
236
   variable not_a    : std_logic_vector(31 downto 0);
237
   variable result   : std_logic_vector(31 downto 0);
238
begin
239
   result := ZERO;
240
   not_a := not a;
241
   carry_in := '1';
242
   for index in a'reverse_range loop
243
      result(index) := not_a(index) xor carry_in;
244
      carry_in := carry_in and not_a(index);
245
   end loop;
246
   return result;
247
end; --function
248
 
249
function bv_increment(a : in std_logic_vector(31 downto 2)
250
                     ) return std_logic_vector is
251
   variable carry_in : std_logic;
252
   variable result   : std_logic_vector(31 downto 2);
253
begin
254
   result := "000000000000000000000000000000";
255
   carry_in := '1';
256
   for index in 2 to 31 loop
257
      result(index) := a(index) xor carry_in;
258
      carry_in := a(index) and carry_in;
259
   end loop;
260
   return result;
261
end; --function
262
 
263
function bv_inc6(a : in std_logic_vector
264
                     ) return std_logic_vector is
265
   variable carry_in : std_logic;
266
   variable result   : std_logic_vector(5 downto 0);
267
begin
268
   result := "000000";
269
   carry_in := '1';
270
   for index in 0 to 5 loop
271
      result(index) := a(index) xor carry_in;
272
      carry_in := a(index) and carry_in;
273
   end loop;
274
   return result;
275
end; --function
276
 
277
end; --package body
278
 
279
 

powered by: WebSVN 2.1.0

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