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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [mlite_pack.vhd] - Blame information for rev 43

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
   subtype mult_function_type is std_logic_vector(2 downto 0);
60
   constant mult_nothing       : mult_function_type := "000";
61
   constant mult_read_lo       : mult_function_type := "001";
62
   constant mult_read_hi       : mult_function_type := "010";
63
   constant mult_write_lo      : mult_function_type := "011";
64
   constant mult_write_hi      : mult_function_type := "100";
65
   constant mult_mult          : mult_function_type := "101";
66
   constant mult_divide        : mult_function_type := "110";
67
   constant mult_signed_divide : mult_function_type := "111";
68
 
69
--   type a_source_type is (from_reg_source, from_imm10_6);
70
   subtype a_source_type is std_logic_vector(1 downto 0);
71
   constant a_from_reg_source : a_source_type := "00";
72
   constant a_from_imm10_6    : a_source_type := "01";
73
   constant a_from_pc         : a_source_type := "10";
74
 
75
--   type b_source_type is (from_reg_target, from_imm, from_signed_imm);
76
   subtype b_source_type is std_logic_vector(1 downto 0);
77
   constant b_from_reg_target : b_source_type := "00";
78
   constant b_from_imm        : b_source_type := "01";
79
   constant b_from_signed_imm : b_source_type := "10";
80
   constant b_from_immX4      : b_source_type := "11";
81
 
82
--   type c_source_type is (from_null, from_alu, from_shift, 
83
--      from_mult, from_memory, from_pc, from_imm_shift16,
84
--      from_reg_source_nez, from_reg_source_eqz);
85
   subtype c_source_type is std_logic_vector(2 downto 0);
86
   constant c_from_null       : c_source_type := "000";
87
   constant c_from_alu        : c_source_type := "001";
88
   constant c_from_shift      : c_source_type := "001"; --same as alu
89
   constant c_from_mult       : c_source_type := "001"; --same as alu
90
   constant c_from_memory     : c_source_type := "010";
91
   constant c_from_pc         : c_source_type := "011";
92
   constant c_from_pc_plus4   : c_source_type := "100";
93
   constant c_from_imm_shift16: c_source_type := "101";
94
   constant c_from_reg_sourcen: c_source_type := "110";
95
 
96
--   type pc_source_type is (from_inc4, from_inc8, from_reg_source, 
97
--      from_opcode25_0, from_branch, from_lbranch);
98
   subtype pc_source_type is std_logic_vector(1 downto 0);
99
   constant from_inc4       : pc_source_type := "00";
100
   constant from_opcode25_0 : pc_source_type := "01";
101
   constant from_branch     : pc_source_type := "10";
102
   constant from_lbranch    : pc_source_type := "11";
103
 
104
   subtype branch_function_type is std_logic_vector(2 downto 0);
105
   constant branch_ltz : branch_function_type := "000";
106
   constant branch_lez : branch_function_type := "001";
107
   constant branch_eq  : branch_function_type := "010";
108
   constant branch_ne  : branch_function_type := "011";
109
   constant branch_gez : branch_function_type := "100";
110
   constant branch_gtz : branch_function_type := "101";
111
   constant branch_yes : branch_function_type := "110";
112
 
113
   -- mode(32=1,16=2,8=3), signed, write
114
   subtype mem_source_type is std_logic_vector(3 downto 0);
115
   constant mem_none    : mem_source_type := "0000";
116
   constant mem_read32  : mem_source_type := "0100";
117
   constant mem_write32 : mem_source_type := "0101";
118
   constant mem_read16  : mem_source_type := "1000";
119
   constant mem_read16s : mem_source_type := "1010";
120
   constant mem_write16 : mem_source_type := "1001";
121
   constant mem_read8   : mem_source_type := "1100";
122
   constant mem_read8s  : mem_source_type := "1110";
123
   constant mem_write8  : mem_source_type := "1101";
124
 
125
   function bv_to_integer(bv: in std_logic_vector) return integer;
126
   function bv_adder(a     : in std_logic_vector(32 downto 0);
127
                     b     : in std_logic_vector(32 downto 0);
128
                     do_sub: in std_logic) return std_logic_vector;
129
   function bv_adder_lookahead(
130
                     a     : in std_logic_vector(32 downto 0);
131
                     b     : in std_logic_vector(32 downto 0);
132
                     do_sub: in std_logic) return std_logic_vector;
133
   function bv_negate(a : in std_logic_vector) return std_logic_vector;
134
   function bv_increment(a : in std_logic_vector(31 downto 2)
135
                     ) return std_logic_vector;
136
   function bv_inc6(a : in std_logic_vector
137
                     ) return std_logic_vector;
138
end; --package mlite_pack
139
 
140
package body mlite_pack is
141
 
142
function add_1(a:integer) return integer is
143
begin
144
   return a+1;
145
end; --function
146
 
147
function bv_to_integer(bv: in std_logic_vector) return integer is
148
   variable result : integer;
149
   variable b      : integer;
150
begin
151
   result := 0;
152
   b := 0;
153
   for index in bv'range loop
154
      if bv(index) = '1' then
155
         b := 1;
156
      else
157
         b := 0;
158
      end if;
159
      result := result * 2 + b;
160
   end loop;
161
   return result;
162
end; --function bv_to_integer
163
 
164
function bv_adder(a     : in std_logic_vector(32 downto 0);
165
                  b     : in std_logic_vector(32 downto 0);
166
                  do_sub: in std_logic) return std_logic_vector is
167
   variable carry_in : std_logic;
168
   variable bb       : std_logic_vector(32 downto 0);
169
   variable result   : std_logic_vector(32 downto 0);
170
begin
171
   result := "000000000000000000000000000000000";
172
   if do_sub = '0' then
173
      bb := b;
174
      carry_in := '0';
175
   else
176
      bb := not b;
177
      carry_in := '1';
178
   end if;
179
   for index in 0 to 32 loop
180
      result(index) := a(index) xor bb(index) xor carry_in;
181
      carry_in := (carry_in and (a(index) or bb(index))) or
182
                  (a(index) and bb(index));
183
   end loop;
184
   return result;
185
end; --function
186
 
187
function bv_adder_lookahead(
188
                  a     : in std_logic_vector(32 downto 0);
189
                  b     : in std_logic_vector(32 downto 0);
190
                  do_sub: in std_logic) return std_logic_vector is
191
   variable carry    : std_logic_vector(32 downto 0);
192
   variable p, g     : std_logic_vector(32 downto 0);
193
   variable bb       : std_logic_vector(32 downto 0);
194
   variable result   : std_logic_vector(32 downto 0);
195
   variable i        : natural;
196
begin
197
   carry := "000000000000000000000000000000000";
198
   if do_sub = '0' then
199
      bb := b;
200
      carry(0) := '0';
201
   else
202
      bb := not b;
203
      carry(0) := '1';
204
   end if;
205
 
206
   p := a or bb;   --propogate
207
   g := a and bb;  --generate
208
   for index in 0 to 7 loop
209
      i := index*4;
210
      carry(i+1) := g(i) or
211
                    (p(i) and carry(i));
212
      i := index*4+1;
213
      carry(i+1) := g(i) or
214
                    (p(i) and g(i-1)) or
215
                    ((p(i) and p(i-1)) and carry(i-1));
216
      i := index*4+2;
217
      carry(i+1) := g(i) or
218
                    (p(i) and g(i-1)) or
219
                    (p(i) and p(i-1) and g(i-2)) or
220
                    ((p(i) and p(i-1) and p(i-2)) and carry(i-2));
221
      i := index*4+3;
222
      carry(i+1) := g(i) or
223
                    (p(i) and g(i-1)) or
224
                    (p(i) and p(i-1) and g(i-2)) or
225
                    (p(i) and p(i-1) and p(i-2) and g(i-3)) or
226
                    (((p(i) and p(i-1)) and (p(i-2) and p(i-3)))
227
                       and carry(i-3));
228
   end loop;
229
   result := (a xor bb) xor carry;
230
   return result;
231
end; --function
232
 
233
function bv_negate(a : in std_logic_vector) return std_logic_vector is
234
   variable carry_in : std_logic;
235
   variable not_a    : std_logic_vector(31 downto 0);
236
   variable result   : std_logic_vector(31 downto 0);
237
begin
238
   result := ZERO;
239
   not_a := not a;
240
   carry_in := '1';
241
   for index in a'reverse_range loop
242
      result(index) := not_a(index) xor carry_in;
243
      carry_in := carry_in and not_a(index);
244
   end loop;
245
   return result;
246
end; --function
247
 
248
function bv_increment(a : in std_logic_vector(31 downto 2)
249
                     ) return std_logic_vector is
250
   variable carry_in : std_logic;
251
   variable result   : std_logic_vector(31 downto 2);
252
begin
253
   result := "000000000000000000000000000000";
254
   carry_in := '1';
255
   for index in 2 to 31 loop
256
      result(index) := a(index) xor carry_in;
257
      carry_in := a(index) and carry_in;
258
   end loop;
259
   return result;
260
end; --function
261
 
262
function bv_inc6(a : in std_logic_vector
263
                     ) return std_logic_vector is
264
   variable carry_in : std_logic;
265
   variable result   : std_logic_vector(5 downto 0);
266
begin
267
   result := "000000";
268
   carry_in := '1';
269
   for index in 0 to 5 loop
270
      result(index) := a(index) xor carry_in;
271
      carry_in := a(index) and carry_in;
272
   end loop;
273
   return result;
274
end; --function
275
 
276
end; --package body
277
 
278
 

powered by: WebSVN 2.1.0

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