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

Subversion Repositories mlite

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

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

powered by: WebSVN 2.1.0

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