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

Subversion Repositories plasma

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

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

powered by: WebSVN 2.1.0

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