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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V3_0/] [vhdl/] [mlite_pack.vhd] - Blame information for rev 132

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

powered by: WebSVN 2.1.0

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