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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V2_1/] [vhdl/] [mlite_pack.vhd] - Blame information for rev 402

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 91 rhoads
--      alu_less_than, alu_less_than_signed, 
26 39 rhoads
--      alu_or, alu_and, alu_xor, alu_nor);
27 91 rhoads
   subtype alu_function_type is std_logic_vector(3 downto 0);
28
   constant alu_nothing   : alu_function_type := "0000";
29
   constant alu_add       : alu_function_type := "0001";
30
   constant alu_subtract  : alu_function_type := "0010";
31
   constant alu_less_than : alu_function_type := "0011";
32
   constant alu_less_than_signed : alu_function_type := "0100";
33
   constant alu_or        : alu_function_type := "0101";
34
   constant alu_and       : alu_function_type := "0110";
35
   constant alu_xor       : alu_function_type := "0111";
36
   constant alu_nor       : alu_function_type := "1000";
37 39 rhoads
 
38
--   type shift_function_type is (
39
--      shift_nothing, shift_left_unsigned,
40
--      shift_right_signed, do_right_unsigned);
41
   subtype shift_function_type is std_logic_vector(1 downto 0);
42
   constant shift_nothing        : shift_function_type := "00";
43
   constant shift_left_unsigned  : shift_function_type := "01";
44
   constant shift_right_signed   : shift_function_type := "11";
45
   constant shift_right_unsigned : shift_function_type := "10";
46
 
47
--   type mult_function_type is (
48
--      mult_nothing, mult_read_lo, mult_read_hi, mult_write_lo, 
49
--      mult_write_hi, mult_mult, mult_divide, mult_signed_divide);
50 44 rhoads
   subtype mult_function_type is std_logic_vector(3 downto 0);
51
   constant mult_nothing       : mult_function_type := "0000";
52
   constant mult_read_lo       : mult_function_type := "0001";
53
   constant mult_read_hi       : mult_function_type := "0010";
54
   constant mult_write_lo      : mult_function_type := "0011";
55
   constant mult_write_hi      : mult_function_type := "0100";
56
   constant mult_mult          : mult_function_type := "0101";
57
   constant mult_signed_mult   : mult_function_type := "0110";
58
   constant mult_divide        : mult_function_type := "0111";
59
   constant mult_signed_divide : mult_function_type := "1000";
60 39 rhoads
 
61
--   type a_source_type is (from_reg_source, from_imm10_6);
62
   subtype a_source_type is std_logic_vector(1 downto 0);
63
   constant a_from_reg_source : a_source_type := "00";
64
   constant a_from_imm10_6    : a_source_type := "01";
65
   constant a_from_pc         : a_source_type := "10";
66
 
67
--   type b_source_type is (from_reg_target, from_imm, from_signed_imm);
68
   subtype b_source_type is std_logic_vector(1 downto 0);
69
   constant b_from_reg_target : b_source_type := "00";
70
   constant b_from_imm        : b_source_type := "01";
71
   constant b_from_signed_imm : b_source_type := "10";
72
   constant b_from_immX4      : b_source_type := "11";
73
 
74
--   type c_source_type is (from_null, from_alu, from_shift, 
75
--      from_mult, from_memory, from_pc, from_imm_shift16,
76
--      from_reg_source_nez, from_reg_source_eqz);
77
   subtype c_source_type is std_logic_vector(2 downto 0);
78
   constant c_from_null       : c_source_type := "000";
79
   constant c_from_alu        : c_source_type := "001";
80
   constant c_from_shift      : c_source_type := "001"; --same as alu
81
   constant c_from_mult       : c_source_type := "001"; --same as alu
82
   constant c_from_memory     : c_source_type := "010";
83
   constant c_from_pc         : c_source_type := "011";
84
   constant c_from_pc_plus4   : c_source_type := "100";
85
   constant c_from_imm_shift16: c_source_type := "101";
86
   constant c_from_reg_sourcen: c_source_type := "110";
87
 
88 125 rhoads
--   type pc_source_type is (from_inc4, from_opcode25_0, from_branch, from_lbranch);
89 39 rhoads
   subtype pc_source_type is std_logic_vector(1 downto 0);
90
   constant from_inc4       : pc_source_type := "00";
91
   constant from_opcode25_0 : pc_source_type := "01";
92
   constant from_branch     : pc_source_type := "10";
93
   constant from_lbranch    : pc_source_type := "11";
94
 
95
   subtype branch_function_type is std_logic_vector(2 downto 0);
96
   constant branch_ltz : branch_function_type := "000";
97
   constant branch_lez : branch_function_type := "001";
98
   constant branch_eq  : branch_function_type := "010";
99
   constant branch_ne  : branch_function_type := "011";
100
   constant branch_gez : branch_function_type := "100";
101
   constant branch_gtz : branch_function_type := "101";
102
   constant branch_yes : branch_function_type := "110";
103
 
104
   -- mode(32=1,16=2,8=3), signed, write
105
   subtype mem_source_type is std_logic_vector(3 downto 0);
106 62 rhoads
   constant mem_fetch   : mem_source_type := "0000";
107 39 rhoads
   constant mem_read32  : mem_source_type := "0100";
108
   constant mem_write32 : mem_source_type := "0101";
109
   constant mem_read16  : mem_source_type := "1000";
110
   constant mem_read16s : mem_source_type := "1010";
111
   constant mem_write16 : mem_source_type := "1001";
112
   constant mem_read8   : mem_source_type := "1100";
113
   constant mem_read8s  : mem_source_type := "1110";
114
   constant mem_write8  : mem_source_type := "1101";
115
 
116
   function bv_to_integer(bv: in std_logic_vector) return integer;
117
   function bv_adder(a     : in std_logic_vector(32 downto 0);
118
                     b     : in std_logic_vector(32 downto 0);
119 47 rhoads
                     do_add: in std_logic) return std_logic_vector;
120 39 rhoads
   function bv_adder_lookahead(
121
                     a     : in std_logic_vector(32 downto 0);
122
                     b     : in std_logic_vector(32 downto 0);
123 47 rhoads
                     do_add: in std_logic) return std_logic_vector;
124 39 rhoads
   function bv_negate(a : in std_logic_vector) return std_logic_vector;
125
   function bv_increment(a : in std_logic_vector(31 downto 2)
126
                     ) return std_logic_vector;
127
   function bv_inc6(a : in std_logic_vector
128
                     ) return std_logic_vector;
129 47 rhoads
 
130
   -- For Altera
131
   COMPONENT lpm_add_sub
132
      GENERIC (
133 91 rhoads
         lpm_width     : NATURAL;
134
         lpm_direction : STRING := "UNUSED";
135
         lpm_type      : STRING;
136
         lpm_hint      : STRING);
137 47 rhoads
      PORT (
138 91 rhoads
         dataa   : IN STD_LOGIC_VECTOR (lpm_width-1 DOWNTO 0);
139
         add_sub : IN STD_LOGIC ;
140
         datab   : IN STD_LOGIC_VECTOR (lpm_width-1 DOWNTO 0);
141
         result  : OUT STD_LOGIC_VECTOR (lpm_width-1 DOWNTO 0));
142 47 rhoads
   END COMPONENT;
143
 
144
   -- For Altera
145
   COMPONENT lpm_ram_dp
146
      GENERIC (
147
         lpm_width        : NATURAL;
148
         lpm_widthad      : NATURAL;
149
         rden_used        : STRING;
150
         intended_device_family : STRING;
151
         lpm_indata       : STRING;
152
         lpm_wraddress_control          : STRING;
153
         lpm_rdaddress_control          : STRING;
154
         lpm_outdata      : STRING;
155
         use_eab          : STRING;
156
         lpm_type         : STRING);
157
      PORT (
158 91 rhoads
         wren      : IN STD_LOGIC ;
159 47 rhoads
         wrclock   : IN STD_LOGIC ;
160 91 rhoads
         q         : OUT STD_LOGIC_VECTOR (lpm_width-1 DOWNTO 0);
161
         data      : IN STD_LOGIC_VECTOR (lpm_width-1 DOWNTO 0);
162
         rdaddress : IN STD_LOGIC_VECTOR (lpm_widthad-1 DOWNTO 0);
163
         wraddress : IN STD_LOGIC_VECTOR (lpm_widthad-1 DOWNTO 0));
164 47 rhoads
   END COMPONENT;
165
 
166
   -- For Altera
167 62 rhoads
   component LPM_RAM_DQ
168
      generic (
169 91 rhoads
         LPM_WIDTH    : natural;    -- MUST be greater than 0
170
         LPM_WIDTHAD  : natural;    -- MUST be greater than 0
171 62 rhoads
         LPM_NUMWORDS : natural := 0;
172 91 rhoads
         LPM_INDATA   : string := "REGISTERED";
173 62 rhoads
         LPM_ADDRESS_CONTROL: string := "REGISTERED";
174 91 rhoads
         LPM_OUTDATA  : string := "REGISTERED";
175
         LPM_FILE     : string := "UNUSED";
176
         LPM_TYPE     : string := "LPM_RAM_DQ";
177
         USE_EAB      : string := "OFF";
178 62 rhoads
         INTENDED_DEVICE_FAMILY  : string := "UNUSED";
179 91 rhoads
         LPM_HINT     : string := "UNUSED");
180 62 rhoads
                port (
181
         DATA     : in std_logic_vector(LPM_WIDTH-1 downto 0);
182
         ADDRESS  : in std_logic_vector(LPM_WIDTHAD-1 downto 0);
183
         INCLOCK  : in std_logic := '0';
184
         OUTCLOCK : in std_logic := '0';
185
         WE       : in std_logic;
186
         Q        : out std_logic_vector(LPM_WIDTH-1 downto 0));
187
   end component;
188 47 rhoads
 
189
   -- For Xilinx
190
   component ramb4_s16_s16
191
      port (
192
         clka  : in std_logic;
193
         rsta  : in std_logic;
194
         addra : in std_logic_vector;
195
         dia   : in std_logic_vector;
196
         ena   : in std_logic;
197
         wea   : in std_logic;
198
         doa   : out std_logic_vector;
199
 
200
         clkb  : in std_logic;
201
         rstb  : in std_logic;
202
         addrb : in std_logic_vector;
203
         dib   : in std_logic_vector;
204
         enb   : in std_logic;
205
         web   : in std_logic);
206
   end component;
207
 
208 116 rhoads
   -- For Xilinx
209
   component reg_file_dp_ram
210
     port (
211
       addra : IN  std_logic_VECTOR(4 downto 0);
212
       addrb : IN  std_logic_VECTOR(4 downto 0);
213
       clka  : IN  std_logic;
214
       clkb  : IN  std_logic;
215
       dinb  : IN  std_logic_VECTOR(31 downto 0);
216
       douta : OUT std_logic_VECTOR(31 downto 0);
217
       web   : IN  std_logic);
218
   end component;
219
 
220
   -- For Xilinx
221
   component reg_file_dp_ram_xc4000xla
222
     port (
223
       A      : IN  std_logic_vector(4 DOWNTO 0);
224
       DI     : IN  std_logic_vector(31 DOWNTO 0);
225
       WR_EN  : IN  std_logic;
226
       WR_CLK : IN  std_logic;
227
       DPRA   : IN  std_logic_vector(4 DOWNTO 0);
228
       SPO    : OUT std_logic_vector(31 DOWNTO 0);
229
       DPO    : OUT std_logic_vector(31 DOWNTO 0));
230
   end component;
231
 
232 47 rhoads
   component pc_next
233
      port(clk          : in std_logic;
234
           reset_in     : in std_logic;
235
           pc_new       : in std_logic_vector(31 downto 2);
236
           take_branch  : in std_logic;
237
           pause_in     : in std_logic;
238
           opcode25_0   : in std_logic_vector(25 downto 0);
239
           pc_source    : in pc_source_type;
240
           pc_out       : out std_logic_vector(31 downto 0);
241
           pc_out_plus4 : out std_logic_vector(31 downto 0));
242
   end component;
243
 
244
   component mem_ctrl
245 70 rhoads
      generic(ACCURATE_TIMING : boolean := false);
246 47 rhoads
      port(clk          : in std_logic;
247
           reset_in     : in std_logic;
248
           pause_in     : in std_logic;
249
           nullify_op   : in std_logic;
250
           address_pc   : in std_logic_vector(31 downto 0);
251
           opcode_out   : out std_logic_vector(31 downto 0);
252
 
253
           address_data : in std_logic_vector(31 downto 0);
254
           mem_source   : in mem_source_type;
255
           data_write   : in std_logic_vector(31 downto 0);
256
           data_read    : out std_logic_vector(31 downto 0);
257
           pause_out    : out std_logic;
258
 
259
           mem_address  : out std_logic_vector(31 downto 0);
260
           mem_data_w   : out std_logic_vector(31 downto 0);
261
           mem_data_r   : in std_logic_vector(31 downto 0);
262
           mem_byte_sel : out std_logic_vector(3 downto 0);
263 70 rhoads
           mem_write    : out std_logic);
264 47 rhoads
   end component;
265
 
266
   component control
267
      port(opcode       : in  std_logic_vector(31 downto 0);
268
           intr_signal  : in  std_logic;
269
           rs_index     : out std_logic_vector(5 downto 0);
270
           rt_index     : out std_logic_vector(5 downto 0);
271
           rd_index     : out std_logic_vector(5 downto 0);
272
           imm_out      : out std_logic_vector(15 downto 0);
273
           alu_func     : out alu_function_type;
274
           shift_func   : out shift_function_type;
275
           mult_func    : out mult_function_type;
276
           branch_func  : out branch_function_type;
277
           a_source_out : out a_source_type;
278
           b_source_out : out b_source_type;
279
           c_source_out : out c_source_type;
280
           pc_source_out: out pc_source_type;
281
           mem_source_out:out mem_source_type);
282
   end component;
283
 
284
   component reg_bank
285
      generic(memory_type : string := "TRI_PORT");
286
      port(clk            : in  std_logic;
287
           reset_in       : in  std_logic;
288 70 rhoads
           pause          : in  std_logic;
289 47 rhoads
           rs_index       : in  std_logic_vector(5 downto 0);
290
           rt_index       : in  std_logic_vector(5 downto 0);
291
           rd_index       : in  std_logic_vector(5 downto 0);
292
           reg_source_out : out std_logic_vector(31 downto 0);
293
           reg_target_out : out std_logic_vector(31 downto 0);
294
           reg_dest_new   : in  std_logic_vector(31 downto 0);
295
           intr_enable    : out std_logic);
296
   end component;
297
 
298
   component bus_mux
299
      port(imm_in       : in  std_logic_vector(15 downto 0);
300
           reg_source   : in  std_logic_vector(31 downto 0);
301
           a_mux        : in  a_source_type;
302
           a_out        : out std_logic_vector(31 downto 0);
303
 
304
           reg_target   : in  std_logic_vector(31 downto 0);
305
           b_mux        : in  b_source_type;
306
           b_out        : out std_logic_vector(31 downto 0);
307
 
308
           c_bus        : in  std_logic_vector(31 downto 0);
309
           c_memory     : in  std_logic_vector(31 downto 0);
310
           c_pc         : in  std_logic_vector(31 downto 0);
311
           c_pc_plus4   : in  std_logic_vector(31 downto 0);
312
           c_mux        : in  c_source_type;
313
           reg_dest_out : out std_logic_vector(31 downto 0);
314
 
315
           branch_func  : in  branch_function_type;
316
           take_branch  : out std_logic);
317
   end component;
318
 
319
   component alu
320 116 rhoads
      generic(adder_type : string := "GENERIC";
321
              alu_type   : string := "GENERIC");
322 47 rhoads
      port(a_in         : in  std_logic_vector(31 downto 0);
323
           b_in         : in  std_logic_vector(31 downto 0);
324
           alu_function : in  alu_function_type;
325
           c_alu        : out std_logic_vector(31 downto 0));
326
   end component;
327
 
328
   component shifter
329 116 rhoads
      generic( shifter_type : string := "GENERIC" );
330 47 rhoads
      port(value        : in  std_logic_vector(31 downto 0);
331
           shift_amount : in  std_logic_vector(4 downto 0);
332
           shift_func   : in  shift_function_type;
333
           c_shift      : out std_logic_vector(31 downto 0));
334
   end component;
335
 
336
   component mult
337 116 rhoads
     generic (
338
       adder_type : string := "GENERIC";
339
       mult_type  : string := "GENERIC");
340
     port (
341
       clk       : in  std_logic;
342
       a, b      : in  std_logic_vector(31 downto 0);
343
       mult_func : in  mult_function_type;
344
       c_mult    : out std_logic_vector(31 downto 0);
345
       pause_out : out std_logic);
346 47 rhoads
   end component;
347
 
348 70 rhoads
   component pipeline
349
      port(clk            : in  std_logic;
350
           reset          : in  std_logic;
351
           a_bus          : in  std_logic_vector(31 downto 0);
352
           a_busD         : out std_logic_vector(31 downto 0);
353
           b_bus          : in  std_logic_vector(31 downto 0);
354
           b_busD         : out std_logic_vector(31 downto 0);
355
           alu_func       : in  alu_function_type;
356
           alu_funcD      : out alu_function_type;
357
           shift_func     : in  shift_function_type;
358
           shift_funcD    : out shift_function_type;
359
           mult_func      : in  mult_function_type;
360
           mult_funcD     : out mult_function_type;
361
           reg_dest       : in  std_logic_vector(31 downto 0);
362
           reg_destD      : out std_logic_vector(31 downto 0);
363
           rd_index       : in  std_logic_vector(5 downto 0);
364
           rd_indexD      : out std_logic_vector(5 downto 0);
365
 
366
           rs_index       : in  std_logic_vector(5 downto 0);
367
           rt_index       : in  std_logic_vector(5 downto 0);
368
           pc_source      : in  pc_source_type;
369
           mem_source     : in  mem_source_type;
370
           a_source       : in  a_source_type;
371
           b_source       : in  b_source_type;
372
           c_source       : in  c_source_type;
373
           c_bus          : in  std_logic_vector(31 downto 0);
374
           pause_any      : in  std_logic;
375
           pause_pipeline : out std_logic);
376
   end component;
377
 
378 47 rhoads
   component mlite_cpu
379 91 rhoads
      generic(memory_type     : string := "ALTERA";
380 116 rhoads
              mult_type       : string := "GENERIC";
381
              shifter_type    : string := "GENERIC";
382 70 rhoads
              pipeline_stages : natural := 3);
383 47 rhoads
      port(clk         : in std_logic;
384
           reset_in    : in std_logic;
385
           intr_in     : in std_logic;
386
 
387
           mem_address : out std_logic_vector(31 downto 0);
388
           mem_data_w  : out std_logic_vector(31 downto 0);
389
           mem_data_r  : in std_logic_vector(31 downto 0);
390
           mem_byte_sel: out std_logic_vector(3 downto 0);
391
           mem_write   : out std_logic;
392
           mem_pause   : in std_logic);
393
   end component;
394
 
395 50 rhoads
   component ram
396
      generic(memory_type : string := "GENERIC");
397 47 rhoads
      port(clk          : in std_logic;
398
           mem_byte_sel : in std_logic_vector(3 downto 0);
399
           mem_write    : in std_logic;
400 50 rhoads
           mem_address  : in std_logic_vector(31 downto 0);
401 62 rhoads
           mem_data_w   : in std_logic_vector(31 downto 0);
402
           mem_data_r   : out std_logic_vector(31 downto 0));
403 47 rhoads
   end component; --ram
404
 
405
   component uart
406 50 rhoads
      generic(log_file : string := "UNUSED");
407
      port(clk        : in std_logic;
408
           reset      : in std_logic;
409
           uart_sel   : in std_logic;
410
           data       : in std_logic_vector(7 downto 0);
411
           uart_read  : in std_logic;
412
           uart_write : out std_logic;
413
           pause      : out std_logic);
414 47 rhoads
   end component; --uart
415
 
416 50 rhoads
   component plasma
417
      generic(memory_type : string := "GENERIC";
418
              log_file    : string := "UNUSED");
419
      port(clk_in           : in std_logic;
420
           reset_in         : in std_logic;
421
           intr_in          : in std_logic;
422
 
423
           uart_read        : in std_logic;
424
           uart_write       : out std_logic;
425
 
426
           mem_address_out  : out std_logic_vector(31 downto 0);
427 62 rhoads
           mem_data         : out std_logic_vector(31 downto 0);
428 50 rhoads
           mem_byte_sel_out : out std_logic_vector(3 downto 0);
429
           mem_write_out    : out std_logic;
430
           mem_pause_in     : in std_logic);
431
   end component; --plasma
432
 
433 62 rhoads
   component plasma_if
434
      generic(memory_type : string := "ALTERA";
435
              log_file    : string := "UNUSED");
436
      port(clk_in     : in std_logic;
437
           reset_n    : in std_logic;
438
           uart_read  : in std_logic;
439
           uart_write : out std_logic;
440
 
441
           address    : out std_logic_vector(31 downto 0);
442
           data       : out std_logic_vector(31 downto 0);
443
           we_n       : out std_logic;
444
           oe_n       : out std_logic;
445
           be_n       : out std_logic_vector(3 downto 0);
446
           sram0_cs_n : out std_logic;
447
           sram1_cs_n : out std_logic);
448
   end component; --plasma_if
449
 
450 39 rhoads
end; --package mlite_pack
451
 
452
package body mlite_pack is
453
 
454
function bv_to_integer(bv: in std_logic_vector) return integer is
455
   variable result : integer;
456
   variable b      : integer;
457
begin
458
   result := 0;
459
   b := 0;
460
   for index in bv'range loop
461
      if bv(index) = '1' then
462
         b := 1;
463
      else
464
         b := 0;
465
      end if;
466
      result := result * 2 + b;
467
   end loop;
468
   return result;
469
end; --function bv_to_integer
470
 
471 91 rhoads
 
472 39 rhoads
function bv_adder(a     : in std_logic_vector(32 downto 0);
473
                  b     : in std_logic_vector(32 downto 0);
474 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
475 39 rhoads
   variable carry_in : std_logic;
476
   variable bb       : std_logic_vector(32 downto 0);
477
   variable result   : std_logic_vector(32 downto 0);
478
begin
479 47 rhoads
   result := '0' & ZERO;
480
   if do_add = '1' then
481 39 rhoads
      bb := b;
482
      carry_in := '0';
483
   else
484
      bb := not b;
485
      carry_in := '1';
486
   end if;
487
   for index in 0 to 32 loop
488
      result(index) := a(index) xor bb(index) xor carry_in;
489
      carry_in := (carry_in and (a(index) or bb(index))) or
490
                  (a(index) and bb(index));
491
   end loop;
492
   return result;
493
end; --function
494
 
495 91 rhoads
 
496 39 rhoads
function bv_adder_lookahead(
497
                  a     : in std_logic_vector(32 downto 0);
498
                  b     : in std_logic_vector(32 downto 0);
499 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
500 39 rhoads
   variable carry    : std_logic_vector(32 downto 0);
501
   variable p, g     : std_logic_vector(32 downto 0);
502
   variable bb       : std_logic_vector(32 downto 0);
503
   variable result   : std_logic_vector(32 downto 0);
504
   variable i        : natural;
505
begin
506 47 rhoads
   carry := '0' & ZERO;
507
   if do_add = '1' then
508 39 rhoads
      bb := b;
509
      carry(0) := '0';
510
   else
511
      bb := not b;
512
      carry(0) := '1';
513
   end if;
514
 
515
   p := a or bb;   --propogate
516
   g := a and bb;  --generate
517
   for index in 0 to 7 loop
518
      i := index*4;
519
      carry(i+1) := g(i) or
520
                    (p(i) and carry(i));
521
      i := index*4+1;
522
      carry(i+1) := g(i) or
523
                    (p(i) and g(i-1)) or
524
                    ((p(i) and p(i-1)) and carry(i-1));
525
      i := index*4+2;
526
      carry(i+1) := g(i) or
527
                    (p(i) and g(i-1)) or
528
                    (p(i) and p(i-1) and g(i-2)) or
529
                    ((p(i) and p(i-1) and p(i-2)) and carry(i-2));
530
      i := index*4+3;
531
      carry(i+1) := g(i) or
532
                    (p(i) and g(i-1)) or
533
                    (p(i) and p(i-1) and g(i-2)) or
534
                    (p(i) and p(i-1) and p(i-2) and g(i-3)) or
535
                    (((p(i) and p(i-1)) and (p(i-2) and p(i-3)))
536
                       and carry(i-3));
537
   end loop;
538
   result := (a xor bb) xor carry;
539
   return result;
540
end; --function
541
 
542 91 rhoads
 
543 39 rhoads
function bv_negate(a : in std_logic_vector) return std_logic_vector is
544
   variable carry_in : std_logic;
545
   variable not_a    : std_logic_vector(31 downto 0);
546
   variable result   : std_logic_vector(31 downto 0);
547
begin
548
   result := ZERO;
549
   not_a := not a;
550
   carry_in := '1';
551
   for index in a'reverse_range loop
552
      result(index) := not_a(index) xor carry_in;
553
      carry_in := carry_in and not_a(index);
554
   end loop;
555
   return result;
556
end; --function
557
 
558 91 rhoads
 
559 39 rhoads
function bv_increment(a : in std_logic_vector(31 downto 2)
560
                     ) return std_logic_vector is
561
   variable carry_in : std_logic;
562
   variable result   : std_logic_vector(31 downto 2);
563
begin
564 47 rhoads
   result := ZERO(31 downto 2);
565 39 rhoads
   carry_in := '1';
566
   for index in 2 to 31 loop
567
      result(index) := a(index) xor carry_in;
568
      carry_in := a(index) and carry_in;
569
   end loop;
570
   return result;
571
end; --function
572
 
573 91 rhoads
 
574 39 rhoads
function bv_inc6(a : in std_logic_vector
575
                     ) return std_logic_vector is
576
   variable carry_in : std_logic;
577
   variable result   : std_logic_vector(5 downto 0);
578
begin
579
   result := "000000";
580
   carry_in := '1';
581
   for index in 0 to 5 loop
582
      result(index) := a(index) xor carry_in;
583
      carry_in := a(index) and carry_in;
584
   end loop;
585
   return result;
586
end; --function
587
 
588
end; --package body
589
 
590
 

powered by: WebSVN 2.1.0

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