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

Subversion Repositories mlite

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

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
   component pc_next
210
      port(clk          : in std_logic;
211
           reset_in     : in std_logic;
212
           pc_new       : in std_logic_vector(31 downto 2);
213
           take_branch  : in std_logic;
214
           pause_in     : in std_logic;
215
           opcode25_0   : in std_logic_vector(25 downto 0);
216
           pc_source    : in pc_source_type;
217
           pc_out       : out std_logic_vector(31 downto 0);
218
           pc_out_plus4 : out std_logic_vector(31 downto 0));
219
   end component;
220
 
221
   component mem_ctrl
222 70 rhoads
      generic(ACCURATE_TIMING : boolean := false);
223 47 rhoads
      port(clk          : in std_logic;
224
           reset_in     : in std_logic;
225
           pause_in     : in std_logic;
226
           nullify_op   : in std_logic;
227
           address_pc   : in std_logic_vector(31 downto 0);
228
           opcode_out   : out std_logic_vector(31 downto 0);
229
 
230
           address_data : in std_logic_vector(31 downto 0);
231
           mem_source   : in mem_source_type;
232
           data_write   : in std_logic_vector(31 downto 0);
233
           data_read    : out std_logic_vector(31 downto 0);
234
           pause_out    : out std_logic;
235
 
236
           mem_address  : out std_logic_vector(31 downto 0);
237
           mem_data_w   : out std_logic_vector(31 downto 0);
238
           mem_data_r   : in std_logic_vector(31 downto 0);
239
           mem_byte_sel : out std_logic_vector(3 downto 0);
240 70 rhoads
           mem_write    : out std_logic);
241 47 rhoads
   end component;
242
 
243
   component control
244
      port(opcode       : in  std_logic_vector(31 downto 0);
245
           intr_signal  : in  std_logic;
246
           rs_index     : out std_logic_vector(5 downto 0);
247
           rt_index     : out std_logic_vector(5 downto 0);
248
           rd_index     : out std_logic_vector(5 downto 0);
249
           imm_out      : out std_logic_vector(15 downto 0);
250
           alu_func     : out alu_function_type;
251
           shift_func   : out shift_function_type;
252
           mult_func    : out mult_function_type;
253
           branch_func  : out branch_function_type;
254
           a_source_out : out a_source_type;
255
           b_source_out : out b_source_type;
256
           c_source_out : out c_source_type;
257
           pc_source_out: out pc_source_type;
258
           mem_source_out:out mem_source_type);
259
   end component;
260
 
261
   component reg_bank
262
      generic(memory_type : string := "TRI_PORT");
263
      port(clk            : in  std_logic;
264
           reset_in       : in  std_logic;
265 70 rhoads
           pause          : in  std_logic;
266 47 rhoads
           rs_index       : in  std_logic_vector(5 downto 0);
267
           rt_index       : in  std_logic_vector(5 downto 0);
268
           rd_index       : in  std_logic_vector(5 downto 0);
269
           reg_source_out : out std_logic_vector(31 downto 0);
270
           reg_target_out : out std_logic_vector(31 downto 0);
271
           reg_dest_new   : in  std_logic_vector(31 downto 0);
272
           intr_enable    : out std_logic);
273
   end component;
274
 
275
   component bus_mux
276
      port(imm_in       : in  std_logic_vector(15 downto 0);
277
           reg_source   : in  std_logic_vector(31 downto 0);
278
           a_mux        : in  a_source_type;
279
           a_out        : out std_logic_vector(31 downto 0);
280
 
281
           reg_target   : in  std_logic_vector(31 downto 0);
282
           b_mux        : in  b_source_type;
283
           b_out        : out std_logic_vector(31 downto 0);
284
 
285
           c_bus        : in  std_logic_vector(31 downto 0);
286
           c_memory     : in  std_logic_vector(31 downto 0);
287
           c_pc         : in  std_logic_vector(31 downto 0);
288
           c_pc_plus4   : in  std_logic_vector(31 downto 0);
289
           c_mux        : in  c_source_type;
290
           reg_dest_out : out std_logic_vector(31 downto 0);
291
 
292
           branch_func  : in  branch_function_type;
293
           take_branch  : out std_logic);
294
   end component;
295
 
296
   component alu
297
      generic(adder_type : string := "GENERIC");
298
      port(a_in         : in  std_logic_vector(31 downto 0);
299
           b_in         : in  std_logic_vector(31 downto 0);
300
           alu_function : in  alu_function_type;
301
           c_alu        : out std_logic_vector(31 downto 0));
302
   end component;
303
 
304
   component shifter
305
      port(value        : in  std_logic_vector(31 downto 0);
306
           shift_amount : in  std_logic_vector(4 downto 0);
307
           shift_func   : in  shift_function_type;
308
           c_shift      : out std_logic_vector(31 downto 0));
309
   end component;
310
 
311
   component mult
312
      generic(adder_type : string := "GENERIC");
313
      port(clk       : in std_logic;
314
           a, b      : in std_logic_vector(31 downto 0);
315
           mult_func : in mult_function_type;
316
           c_mult    : out std_logic_vector(31 downto 0);
317
           pause_out : out std_logic);
318
   end component;
319
 
320 70 rhoads
   component pipeline
321
      port(clk            : in  std_logic;
322
           reset          : in  std_logic;
323
           a_bus          : in  std_logic_vector(31 downto 0);
324
           a_busD         : out std_logic_vector(31 downto 0);
325
           b_bus          : in  std_logic_vector(31 downto 0);
326
           b_busD         : out std_logic_vector(31 downto 0);
327
           alu_func       : in  alu_function_type;
328
           alu_funcD      : out alu_function_type;
329
           shift_func     : in  shift_function_type;
330
           shift_funcD    : out shift_function_type;
331
           mult_func      : in  mult_function_type;
332
           mult_funcD     : out mult_function_type;
333
           reg_dest       : in  std_logic_vector(31 downto 0);
334
           reg_destD      : out std_logic_vector(31 downto 0);
335
           rd_index       : in  std_logic_vector(5 downto 0);
336
           rd_indexD      : out std_logic_vector(5 downto 0);
337
 
338
           rs_index       : in  std_logic_vector(5 downto 0);
339
           rt_index       : in  std_logic_vector(5 downto 0);
340
           pc_source      : in  pc_source_type;
341
           mem_source     : in  mem_source_type;
342
           a_source       : in  a_source_type;
343
           b_source       : in  b_source_type;
344
           c_source       : in  c_source_type;
345
           c_bus          : in  std_logic_vector(31 downto 0);
346
           take_branch    : in  std_logic;
347
           take_branchD   : out std_logic;
348
           pause_any      : in  std_logic;
349
           pause_pipeline : out std_logic);
350
   end component;
351
 
352 47 rhoads
   component mlite_cpu
353 91 rhoads
      generic(memory_type     : string := "ALTERA";
354 70 rhoads
              pipeline_stages : natural := 3);
355 47 rhoads
      port(clk         : in std_logic;
356
           reset_in    : in std_logic;
357
           intr_in     : in std_logic;
358
 
359
           mem_address : out std_logic_vector(31 downto 0);
360
           mem_data_w  : out std_logic_vector(31 downto 0);
361
           mem_data_r  : in std_logic_vector(31 downto 0);
362
           mem_byte_sel: out std_logic_vector(3 downto 0);
363
           mem_write   : out std_logic;
364
           mem_pause   : in std_logic);
365
   end component;
366
 
367 50 rhoads
   component ram
368
      generic(memory_type : string := "GENERIC");
369 47 rhoads
      port(clk          : in std_logic;
370
           mem_byte_sel : in std_logic_vector(3 downto 0);
371
           mem_write    : in std_logic;
372 50 rhoads
           mem_address  : in std_logic_vector(31 downto 0);
373 62 rhoads
           mem_data_w   : in std_logic_vector(31 downto 0);
374
           mem_data_r   : out std_logic_vector(31 downto 0));
375 47 rhoads
   end component; --ram
376
 
377
   component uart
378 50 rhoads
      generic(log_file : string := "UNUSED");
379
      port(clk        : in std_logic;
380
           reset      : in std_logic;
381
           uart_sel   : in std_logic;
382
           data       : in std_logic_vector(7 downto 0);
383
           uart_read  : in std_logic;
384
           uart_write : out std_logic;
385
           pause      : out std_logic);
386 47 rhoads
   end component; --uart
387
 
388 50 rhoads
   component plasma
389
      generic(memory_type : string := "GENERIC";
390
              log_file    : string := "UNUSED");
391
      port(clk_in           : in std_logic;
392
           reset_in         : in std_logic;
393
           intr_in          : in std_logic;
394
 
395
           uart_read        : in std_logic;
396
           uart_write       : out std_logic;
397
 
398
           mem_address_out  : out std_logic_vector(31 downto 0);
399 62 rhoads
           mem_data         : out std_logic_vector(31 downto 0);
400 50 rhoads
           mem_byte_sel_out : out std_logic_vector(3 downto 0);
401
           mem_write_out    : out std_logic;
402
           mem_pause_in     : in std_logic);
403
   end component; --plasma
404
 
405 62 rhoads
   component plasma_if
406
      generic(memory_type : string := "ALTERA";
407
              log_file    : string := "UNUSED");
408
      port(clk_in     : in std_logic;
409
           reset_n    : in std_logic;
410
           uart_read  : in std_logic;
411
           uart_write : out std_logic;
412
 
413
           address    : out std_logic_vector(31 downto 0);
414
           data       : out std_logic_vector(31 downto 0);
415
           we_n       : out std_logic;
416
           oe_n       : out std_logic;
417
           be_n       : out std_logic_vector(3 downto 0);
418
           sram0_cs_n : out std_logic;
419
           sram1_cs_n : out std_logic);
420
   end component; --plasma_if
421
 
422 39 rhoads
end; --package mlite_pack
423
 
424
package body mlite_pack is
425
 
426
function bv_to_integer(bv: in std_logic_vector) return integer is
427
   variable result : integer;
428
   variable b      : integer;
429
begin
430
   result := 0;
431
   b := 0;
432
   for index in bv'range loop
433
      if bv(index) = '1' then
434
         b := 1;
435
      else
436
         b := 0;
437
      end if;
438
      result := result * 2 + b;
439
   end loop;
440
   return result;
441
end; --function bv_to_integer
442
 
443 91 rhoads
 
444 39 rhoads
function bv_adder(a     : in std_logic_vector(32 downto 0);
445
                  b     : in std_logic_vector(32 downto 0);
446 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
447 39 rhoads
   variable carry_in : std_logic;
448
   variable bb       : std_logic_vector(32 downto 0);
449
   variable result   : std_logic_vector(32 downto 0);
450
begin
451 47 rhoads
   result := '0' & ZERO;
452
   if do_add = '1' then
453 39 rhoads
      bb := b;
454
      carry_in := '0';
455
   else
456
      bb := not b;
457
      carry_in := '1';
458
   end if;
459
   for index in 0 to 32 loop
460
      result(index) := a(index) xor bb(index) xor carry_in;
461
      carry_in := (carry_in and (a(index) or bb(index))) or
462
                  (a(index) and bb(index));
463
   end loop;
464
   return result;
465
end; --function
466
 
467 91 rhoads
 
468 39 rhoads
function bv_adder_lookahead(
469
                  a     : in std_logic_vector(32 downto 0);
470
                  b     : in std_logic_vector(32 downto 0);
471 47 rhoads
                  do_add: in std_logic) return std_logic_vector is
472 39 rhoads
   variable carry    : std_logic_vector(32 downto 0);
473
   variable p, g     : std_logic_vector(32 downto 0);
474
   variable bb       : std_logic_vector(32 downto 0);
475
   variable result   : std_logic_vector(32 downto 0);
476
   variable i        : natural;
477
begin
478 47 rhoads
   carry := '0' & ZERO;
479
   if do_add = '1' then
480 39 rhoads
      bb := b;
481
      carry(0) := '0';
482
   else
483
      bb := not b;
484
      carry(0) := '1';
485
   end if;
486
 
487
   p := a or bb;   --propogate
488
   g := a and bb;  --generate
489
   for index in 0 to 7 loop
490
      i := index*4;
491
      carry(i+1) := g(i) or
492
                    (p(i) and carry(i));
493
      i := index*4+1;
494
      carry(i+1) := g(i) or
495
                    (p(i) and g(i-1)) or
496
                    ((p(i) and p(i-1)) and carry(i-1));
497
      i := index*4+2;
498
      carry(i+1) := g(i) or
499
                    (p(i) and g(i-1)) or
500
                    (p(i) and p(i-1) and g(i-2)) or
501
                    ((p(i) and p(i-1) and p(i-2)) and carry(i-2));
502
      i := index*4+3;
503
      carry(i+1) := g(i) or
504
                    (p(i) and g(i-1)) or
505
                    (p(i) and p(i-1) and g(i-2)) or
506
                    (p(i) and p(i-1) and p(i-2) and g(i-3)) or
507
                    (((p(i) and p(i-1)) and (p(i-2) and p(i-3)))
508
                       and carry(i-3));
509
   end loop;
510
   result := (a xor bb) xor carry;
511
   return result;
512
end; --function
513
 
514 91 rhoads
 
515 39 rhoads
function bv_negate(a : in std_logic_vector) return std_logic_vector is
516
   variable carry_in : std_logic;
517
   variable not_a    : std_logic_vector(31 downto 0);
518
   variable result   : std_logic_vector(31 downto 0);
519
begin
520
   result := ZERO;
521
   not_a := not a;
522
   carry_in := '1';
523
   for index in a'reverse_range loop
524
      result(index) := not_a(index) xor carry_in;
525
      carry_in := carry_in and not_a(index);
526
   end loop;
527
   return result;
528
end; --function
529
 
530 91 rhoads
 
531 39 rhoads
function bv_increment(a : in std_logic_vector(31 downto 2)
532
                     ) return std_logic_vector is
533
   variable carry_in : std_logic;
534
   variable result   : std_logic_vector(31 downto 2);
535
begin
536 47 rhoads
   result := ZERO(31 downto 2);
537 39 rhoads
   carry_in := '1';
538
   for index in 2 to 31 loop
539
      result(index) := a(index) xor carry_in;
540
      carry_in := a(index) and carry_in;
541
   end loop;
542
   return result;
543
end; --function
544
 
545 91 rhoads
 
546 39 rhoads
function bv_inc6(a : in std_logic_vector
547
                     ) return std_logic_vector is
548
   variable carry_in : std_logic;
549
   variable result   : std_logic_vector(5 downto 0);
550
begin
551
   result := "000000";
552
   carry_in := '1';
553
   for index in 0 to 5 loop
554
      result(index) := a(index) xor carry_in;
555
      carry_in := a(index) and carry_in;
556
   end loop;
557
   return result;
558
end; --function
559
 
560
end; --package body
561
 
562
 

powered by: WebSVN 2.1.0

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