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

Subversion Repositories raytrac

[/] [raytrac/] [branches/] [fp/] [arithpack.vhd] - Blame information for rev 186

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 151 jguarin200
library ieee;
2
use ieee.std_logic_1164.all;
3 153 jguarin200
use ieee.std_logic_arith.all;
4
use ieee.math_real.all;
5 151 jguarin200
 
6 153 jguarin200
library std;
7
use std.textio.all;
8
 
9 159 jguarin200
 
10
 
11 151 jguarin200
--! Memory Compiler Library
12 159 jguarin200
library altera_mf;
13
use altera_mf.all;
14 151 jguarin200
library lpm;
15
use lpm.all;
16
 
17
 
18
 
19
package arithpack is
20
        --! Estados para la maquina de estados.
21
        type macState is (LOAD_INSTRUCTION,FLUSH_ARITH_PIPELINE,EXECUTE_INSTRUCTION);
22
        --! Estados para el controlador de interrupciones.
23 181 jguarin200
        type iCtrlState is (WAITING_FOR_A_RFULL_EVENT,INHIBIT_RFULL_INT);
24 152 jguarin200
 
25
        --! Float data blocks
26
        constant floatwidth : integer := 32;
27
        constant widthadmemblock : integer := 9;
28
 
29 156 jguarin200
 
30
        subtype xfloat32 is std_logic_vector(31 downto 0);
31
        type    v3f     is array(02 downto 0) of xfloat32;
32
 
33
        --! Constantes para definir 
34
 
35
        --!type vectorblock12 is array (11 downto 0) of std_logic_vector(floatwidth-1 downto 0);
36
        type    vectorblock12 is array (11 downto 0) of xfloat32;
37
 
38
        type    vectorblock08 is array (07 downto 0) of xfloat32;
39 152 jguarin200
        type    vectorblock06 is array (05 downto 0) of std_logic_vector(floatwidth-1 downto 0);
40
        type    vectorblock04 is array (03 downto 0) of std_logic_vector(floatwidth-1 downto 0);
41
        type    vectorblock03 is array (02 downto 0) of std_logic_vector(floatwidth-1 downto 0);
42
        type    vectorblock02 is array (01 downto 0) of std_logic_vector(floatwidth-1 downto 0);
43
        type    vectorblockadd02 is array (01 downto 0) of std_logic_vector(widthadmemblock-1 downto 0);
44
 
45 151 jguarin200
        --! Constante de reseteo
46
        constant rstMasterValue : std_logic :='0';
47 168 jguarin200
 
48 151 jguarin200
        --! Constantes periodicas.
49
        constant tclk   : time := 20 ns;
50
        constant tclk_2 : time := tclk/2;
51
        constant tclk_4 : time := tclk/4;
52
 
53 152 jguarin200
 
54
        component raytrac
55
        port (
56
 
57
                clk : in std_logic;
58
                rst : in std_logic;
59
 
60
                --! Señal de lectura de alguna de las colas de resultados.
61
                rd      : in std_logic;
62
 
63
                --! Señal de escritura en alguno de los bloques de memoria de operandos o en la cola de instrucciones.
64
                wr      : in std_logic;
65
 
66
                --! Direccion de escritura o lectura
67
                add : in std_logic_vector (12 downto 0);
68
 
69
                --! datos de entrada
70
                d       : in std_logic_vector (31 downto 0);
71
 
72
                --! Interrupciones
73 181 jguarin200
                int     : out std_logic;
74 152 jguarin200
 
75
                --! Salidas
76
                q : out std_logic_vector (31 downto 0)
77
 
78
 
79
 
80
        );
81
        end component;
82
 
83
        --! Componentes Aritméticos
84
 
85
        component fadd32
86
        port (
87
                clk : in std_logic;
88
                dpc : in std_logic;
89 158 jguarin200
                a32 : in xfloat32;
90
                b32 : in xfloat32;
91
                c32 : out xfloat32
92 152 jguarin200
        );
93
        end component;
94
        component fmul32
95
        port (
96
                clk : in std_logic;
97 158 jguarin200
                a32 : in xfloat32;
98
                b32 : in xfloat32;
99
                p32 : out xfloat32
100 152 jguarin200
        );
101
        end component;
102
 
103
 
104
        --! Contadores para la máquina de estados.
105
 
106 151 jguarin200
        component customCounter
107
        generic (
108
                EOBFLAG         : string ;
109
                ZEROFLAG        : string ;
110
                BACKWARDS       : string ;
111
                EQUALFLAG       : string ;
112
                subwidth        : integer;
113
                width           : integer
114
 
115
        );
116
        port (
117
                clk,rst,go,set  : in std_logic;
118
                setValue,cmpBlockValue          : in std_Logic_vector(width-1 downto subwidth);
119
                zero_flag,eob_flag,eq_flag      : out std_logic;
120
                count                   : out std_logic_vector(width-1 downto 0)
121
        );
122
        end component;
123
 
124 155 jguarin200
        --! LPM_MULTIPLIER
125
        component lpm_mult
126
        generic (
127
                lpm_hint                        : string;
128
                lpm_pipeline            : natural;
129
                lpm_representation      : string;
130
                lpm_type                        : string;
131
                lpm_widtha                      : natural;
132
                lpm_widthb                      : natural;
133
                lpm_widthp                      : natural
134
        );
135
        port (
136
                dataa   : in std_logic_vector ( lpm_widtha-1 downto 0 );
137
                datab   : in std_logic_vector ( lpm_widthb-1 downto 0 );
138
                result  : out std_logic_vector( lpm_widthp-1 downto 0 )
139
        );
140
        end component;
141 151 jguarin200
        --! LPM Memory Compiler.
142
        component scfifo
143
        generic (
144
                add_ram_output_register :string;
145
                almost_full_value               :natural;
146 159 jguarin200
                allow_rwcycle_when_full :string;
147 151 jguarin200
                intended_device_family  :string;
148
                lpm_hint                                :string;
149
                lpm_numwords                    :natural;
150
                lpm_showahead                   :string;
151
                lpm_type                                :string;
152
                lpm_width                               :natural;
153
                lpm_widthu                              :natural;
154
                overflow_checking               :string;
155
                underflow_checking              :string;
156
                use_eab                                 :string
157
        );
158
        port(
159
                rdreq           : in std_logic;
160
                aclr            : in std_logic;
161
                empty           : out std_logic;
162
                clock           : in std_logic;
163
                q                       : out std_logic_vector(lpm_width-1 downto 0);
164
                wrreq           : in std_logic;
165
                data            : in std_logic_vector(lpm_width-1 downto 0);
166
                almost_full : out std_logic;
167
                full            : out std_logic
168
        );
169
        end component;
170
 
171
 
172
        component altsyncram
173
        generic (
174
                address_aclr_b                  : string;
175
                address_reg_b                   : string;
176
                clock_enable_input_a    : string;
177
                clock_enable_input_b    : string;
178
                clock_enable_output_b   : string;
179
                intended_device_family  : string;
180
                lpm_type                                : string;
181
                numwords_a                              : natural;
182
                numwords_b                              : natural;
183
                operation_mode                  : string;
184
                outdata_aclr_b                  : string;
185
                outdata_reg_b                   : string;
186
                power_up_uninitialized  : string;
187
                ram_block_type                  : string;
188
                rdcontrol_reg_b                 : string;
189
                read_during_write_mode_mixed_ports      : string;
190
                widthad_a                               : natural;
191
                widthad_b                               : natural;
192
                width_a                                 : natural;
193
                width_b                                 : natural;
194
                width_byteena_a                 : natural
195
        );
196
        port (
197
                wren_a          : in std_logic;
198
                clock0          : in std_logic;
199
                address_a       : in std_logic_vector(8 downto 0);
200
                address_b       : in std_logic_vector(8 downto 0);
201
                rden_b          : in std_logic;
202
                q_b                     : out std_logic_vector(31 downto 0);
203
                data_a          : in std_logic_vector(31 downto 0)
204
 
205
        );
206
        end component;
207
 
208
        --! Maquina de Estados.
209
        component sm
210 152 jguarin200
 
211 151 jguarin200
        port (
212
 
213
                --! Señales normales de secuencia.
214
                clk,rst:                        in std_logic;
215 152 jguarin200
                --! Vector con las instrucción codficada
216 151 jguarin200
                instrQq:in std_logic_vector(31 downto 0);
217 152 jguarin200
                --! Señal de cola vacia.
218 151 jguarin200
                instrQ_empty:in std_logic;
219
                adda,addb:out std_logic_vector (8 downto 0);
220
                sync_chain_0,instrRdAckd:out std_logic;
221
                full_r:         in std_logic;   --! Indica que la cola de resultados no puede aceptar mas de 32 elementos.
222
                --! End Of Instruction Event
223
                eoi     : out std_logic;
224
 
225
                --! DataPath Control uca code.
226
                dpc_uca : out std_logic_vector (2 downto 0);
227
                state   : out macState
228
        );
229
        end component;
230
        --! Maquina de Interrupciones
231
        component im
232
        generic (
233
                num_events : integer ;
234
                cycles_to_wait : integer
235
        );
236
        port (
237
                clk,rst:                in std_logic;
238 181 jguarin200
                rfull_event:    in std_logic;   --! full results queue events
239
                eoi_event:              in std_logic;   --! end of instruction related events
240
                int:                    out std_logic;
241 151 jguarin200
                state:                  out iCtrlState
242
        );
243
        end component;
244
        --! Bloque de memorias
245
        component memblock
246
        port (
247
 
248
 
249
                clk,rst,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
250
                instrfifo_rd : in std_logic;
251 158 jguarin200
                resultfifo_wr: in std_logic_vector(8-1 downto 0);
252 151 jguarin200
                instrfifo_empty: out std_logic; ext_rd,ext_wr: in std_logic;
253 181 jguarin200
                ext_wr_add : in std_logic_vector(4+widthadmemblock-1 downto 0);
254
                ext_rd_add : in std_logic_vector(3 downto 0);
255 152 jguarin200
                ext_d: in std_logic_vector(floatwidth-1 downto 0);
256 158 jguarin200
                int_d : in vectorblock08;
257 181 jguarin200
 
258
                status_register : in std_logic_vector(3 downto 0);
259
 
260 151 jguarin200
                resultfifo_full  : out std_logic_vector(3 downto 0);
261 152 jguarin200
                ext_q,instrfifo_q : out std_logic_vector(floatwidth-1 downto 0);
262 158 jguarin200
                int_q : out vectorblock12;
263 151 jguarin200
                int_rd_add : in std_logic_vector(2*widthadmemblock-1 downto 0);
264 152 jguarin200
                dpfifo_d : in std_logic_vector(floatwidth*2-1 downto 0);
265
                normfifo_d : in std_logic_vector(floatwidth*3-1 downto 0);
266
                dpfifo_q : out std_logic_vector(floatwidth*2-1 downto 0);
267
                normfifo_q : out std_logic_vector(floatwidth*3-1 downto 0)
268 151 jguarin200
        );
269
        end component;
270
        --! Bloque decodificacion DataPath Control.
271
        component dpc
272
        port (
273
                clk,rst                                 : in    std_logic;
274 158 jguarin200
                paraminput                              : in    vectorblock12;  --! Vectores A,B,C,D
275
                prd32blko                               : in    vectorblock06;  --! Salidas de los 6 multiplicadores.
276
                add32blko                               : in    vectorblock04;  --! Salidas de los 4 sumadores.
277 152 jguarin200
                sqr32blko,inv32blko             : in    std_logic_vector (floatwidth-1 downto 0);                --! Salidas de la raiz cuadradas y el inversor.
278
                fifo32x23_q                             : in    std_logic_vector (03*floatwidth-1 downto 0);             --! Salida de la cola intermedia.
279
                fifo32x09_q                             : in    std_logic_vector (02*floatwidth-1 downto 0);     --! Salida de las colas de producto punto. 
280 151 jguarin200
                unary,crossprod,addsub  : in    std_logic;                                                                      --! Bit con el identificador del bloque AB vs CD e identificador del sub bloque (A/B) o (C/D). 
281 152 jguarin200
                sync_chain_0                    : in    std_logic;                                                                      --! Señal de dato valido que se va por toda la cadena de sincronizacion.
282
                eoi_int                                 : in    std_logic;                                                                      --! Señal de interrupción de final de instrucci&ocaute;n.
283
                eoi_demuxed_int                 : out   std_logic_vector (3 downto 0);                           --! Señal de interrup&ocaute;n de final de instrucción pero esta vez va asociada a la instruccón UCA.
284
                sqr32blki,inv32blki             : out   std_logic_vector (floatwidth-1 downto 0);                --! Salidas de las 2 raices cuadradas y los 2 inversores.
285
                fifo32x26_d                             : out   std_logic_vector (03*floatwidth-1 downto 0);             --! Entrada a la cola intermedia para la normalización.
286
                fifo32x09_d                             : out   std_logic_vector (02*floatwidth-1 downto 0);             --! Entrada a las colas intermedias del producto punto.         
287 158 jguarin200
                prd32blki                               : out   vectorblock12;  --! Entrada de los 12 factores en el bloque de multiplicación respectivamente.
288
                add32blki                               : out   vectorblock08;  --! Entrada de los 8 sumandos del bloque de 4 sumadores.  
289 151 jguarin200
                resw                                    : out   std_logic_vector (4 downto 0);                           --! Salidas de escritura y lectura en las colas de resultados.
290
                fifo32x09_w                             : out   std_logic;
291
                fifo32x23_w,fifo32x09_r : out   std_logic;
292
                fifo32x23_r                             : out   std_logic;
293
                resf_vector                             : in    std_logic_vector(3 downto 0);                            --! Entradas de la señal de full de las colas de resultados. 
294
                resf_event                              : out   std_logic;                                                                      --! Salida decodificada que indica que la cola de resultados de la operación que está en curso.
295 158 jguarin200
                resultoutput                    : out   vectorblock08   --! 8 salidas de resultados, pues lo máximo que podrá calcularse por cada clock son 2 vectores.
296 151 jguarin200
        );
297
        end component;
298
        --! Bloque Aritmetico de Sumadores y Multiplicadores (madd)
299
        component arithblock
300
        port (
301
 
302
                clk     : in std_logic;
303
                rst : in std_logic;
304
 
305
                dpc : in std_logic;
306
 
307 158 jguarin200
                f       : in vectorblock12;
308
                a       : in vectorblock08;
309 151 jguarin200
 
310 158 jguarin200
                s       : out vectorblock04;
311
                p       : out vectorblock06
312 151 jguarin200
 
313
        );
314
        end component;
315
        --! Bloque de Raiz Cuadrada
316
        component sqrt32
317
        port (
318
 
319
                clk     : in std_logic;
320 158 jguarin200
                rd32: in xfloat32;
321
                sq32: out xfloat32
322 151 jguarin200
        );
323
        end component;
324
        --! Bloque de Inversores.
325
        component invr32
326
        port (
327
 
328
                clk             : in std_logic;
329 158 jguarin200
                dvd32   : in xfloat32;
330
                qout32  : out xfloat32
331 151 jguarin200
        );
332
        end component;
333 153 jguarin200
 
334
 
335
 
336
 
337
        type apCamera is record
338
                resx,resy : integer;
339
                width,height : real;
340
                dist : real;
341
        end record;
342
 
343
        --! Función que convierte un std_logic_vector en un numero entero
344
        function ap_slv2int(sl:std_logic_vector) return integer;
345
 
346
        --! Función que convierte un número flotante IEE754 single float, en un número std_logic_vector.
347
        function ap_fp2slv (f:real) return std_logic_vector;
348
 
349
        --! Función que convierte un número std_logic_vector en un ieee754 single float.
350
        function ap_slv2fp (sl:std_logic_vector) return real;
351
 
352
        --! Función que devuelve un vector en punto flotante IEEE754 a través de un   
353
        function ap_slv_calc_xyvec (x,y:integer; cam:apCamera) return v3f;
354
 
355 156 jguarin200
        --! Función que devuelve una cadena con el número flotante IEEE 754 ó a una cadena de cifras hexadecimales.
356 160 jguarin200
        procedure ap_slvf2string(l:inout line;sl:std_logic_vector);
357
        procedure ap_slv2hex (l:inout line;h:in std_logic_vector) ;
358 156 jguarin200
        --! Función que devuelve una cadena con el estado de macState.
359 160 jguarin200
        procedure ap_macState2string(l:inout line;s:in macState);
360 153 jguarin200
 
361 156 jguarin200
        --! Función que convierte un array de 2 std_logic_vectors que contienen un par de direcciones en string
362 160 jguarin200
        procedure ap_vnadd022string(l:inout line; va2:in vectorblockadd02);
363 153 jguarin200
 
364 156 jguarin200
        --! Función que devuelve una cadena de caracteres con el estado de la maquina de estados que controla las interrupciones
365 160 jguarin200
        procedure ap_iCtrlState2string(l:inout line;i:in iCtrlState) ;
366 156 jguarin200
 
367
        --! Función que devuelve una cadena con los componentes de un vector R3 en punto flotante IEEE754        
368 160 jguarin200
        procedure ap_v3f2string(l:inout line;v:in v3f);
369 173 jguarin200
        procedure ap_xfp032string(l:inout line;vb03:in vectorblock03);
370 157 jguarin200
 
371
        --! Función que formatea una instrucción
372 161 jguarin200
        function ap_format_instruction(i:string;ac_o,ac_f,bd_o,bd_f:std_logic_vector;comb:std_logic) return std_logic_vector;
373 157 jguarin200
 
374
        --! Función que devuelve una cadena de caracteres de un solo caracter con el valor de un bit std_logic
375 160 jguarin200
        procedure ap_sl2string(l:inout line;s:std_logic);
376
 
377 168 jguarin200
        --! Procedimiento para mostrar vectores en forma de arreglos de flotantes
378 160 jguarin200
        procedure ap_xfp122string(l:inout line;vb12:in vectorblock12);
379
        procedure ap_xfp082string(l:inout line;vb08:in vectorblock08);
380
        procedure ap_xfp062string(l:inout line;vb06:in vectorblock06);
381
        procedure ap_xfp042string(l:inout line;vb04:in vectorblock04);
382 168 jguarin200
        procedure ap_xfp022string(l:inout line;vb02:in vectorblock02);
383
 
384 156 jguarin200
 
385 151 jguarin200
end package;
386 153 jguarin200
 
387
 
388
package body arithpack is
389 160 jguarin200
 
390 168 jguarin200
        procedure ap_xfp022string(l:inout line; vb02:in vectorblock02) is
391
        begin
392
                for i in 01 downto 0 loop
393
                        write(l,string'(" ["&integer'image(i)&"]"));
394
                        write(l,string'(" "));
395
                        ap_slvf2string(l,vb02(i));
396
                end loop;
397
 
398
        end procedure;
399 160 jguarin200
        procedure ap_xfp122string(l:inout line; vb12:in vectorblock12) is
400 153 jguarin200
 
401 160 jguarin200
        begin
402
                for i in 11 downto 0 loop
403 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
404 160 jguarin200
                        write(l,string'(" "));
405
                        ap_slvf2string(l,vb12(i));
406
                end loop;
407
        end procedure;
408
 
409
        procedure ap_xfp082string(l:inout line; vb08:in vectorblock08) is
410
 
411
        begin
412
                for i in 07 downto 0 loop
413
                        write(l,string'(" ["&integer'image(i)&"]"));
414
                        write(l,string'(" "));
415
                        ap_slvf2string(l,vb08(i));
416
                end loop;
417
        end procedure;
418
 
419
        procedure ap_xfp062string(l:inout line; vb06:in vectorblock06) is
420
 
421
        begin
422
                for i in 05 downto 0 loop
423 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
424 160 jguarin200
                        write(l,string'(" "));
425
                        ap_slvf2string(l,vb06(i));
426
                end loop;
427
        end procedure;
428
 
429
        procedure ap_xfp042string(l:inout line; vb04:in vectorblock04) is
430
 
431
        begin
432
                for i in 03 downto 0 loop
433 168 jguarin200
                        write(l,string'(" ["&integer'image(i)&"]"));
434 160 jguarin200
                        write(l,string'(" "));
435
                        ap_slvf2string(l,vb04(i));
436
                end loop;
437
        end procedure;
438
 
439
 
440
        procedure ap_sl2string(l:inout line; s:in std_logic)is
441 157 jguarin200
                variable tmp:string(1 to 1);
442
        begin
443
 
444
                case s is
445
                        when '1' =>
446
                                tmp:="1";
447
                        when '0' =>
448
                                tmp:="0";
449
                        when 'U' =>
450
                                tmp:="U";
451
                        when 'X' =>
452
                                tmp:="X";
453
                        when 'Z' =>
454
                                tmp:="Z";
455
                        when 'W' =>
456
                                tmp:="W";
457
                        when 'L' =>
458
                                tmp:="L";
459
                        when 'H' =>
460
                                tmp:="H";
461
                        when others =>
462
                                tmp:="-"; -- Don't care
463
                end case;
464 168 jguarin200
                write(l,string'(" "));
465 160 jguarin200
                write(l,string'(tmp));
466 168 jguarin200
                write(l,string'(" "));
467 157 jguarin200
 
468 160 jguarin200
 
469
 
470
        end procedure;
471 157 jguarin200
 
472 161 jguarin200
        function ap_format_instruction(i:string;ac_o,ac_f,bd_o,bd_f:std_logic_vector;comb:std_logic) return std_logic_vector is
473 157 jguarin200
 
474
                alias aco : std_logic_vector (4 downto 0) is ac_o;
475
                alias acf : std_logic_vector (4 downto 0) is ac_f;
476
                alias bdo : std_logic_vector (4 downto 0) is bd_o;
477
                alias bdf : std_logic_vector (4 downto 0) is bd_f;
478
                variable ins : std_logic_vector (31 downto 0);
479
                alias it : string (1 to 3) is i;
480
        begin
481
 
482
                case it is
483
                        when "mag" =>
484
                                ins(31 downto 29) := "100";
485 160 jguarin200
                                ins(04 downto 00) := '1'&x"8";
486 157 jguarin200
                        when "nrm" =>
487 163 jguarin200
                                ins(31 downto 29) := "110";
488 160 jguarin200
                                ins(04 downto 00) := '1'&x"d";
489 157 jguarin200
                        when "add" =>
490
                                ins(31 downto 29) := "001";
491 160 jguarin200
                                ins(04 downto 00) := '0'&x"a";
492 157 jguarin200
                        when "sub" =>
493
                                ins(31 downto 29) := "011";
494 160 jguarin200
                                ins(04 downto 00) := '0'&x"a";
495 157 jguarin200
                        when "dot" =>
496
                                ins(31 downto 29) := "000";
497 160 jguarin200
                                ins(04 downto 00) := '1'&x"7";
498 157 jguarin200
                        when "crs" =>
499
                                ins(31 downto 29) := "010";
500 160 jguarin200
                                ins(04 downto 00) := '0'&x"e";
501 157 jguarin200
                        when others =>
502
                                ins(31 downto 29) := "111";
503 160 jguarin200
                                ins(04 downto 00) := '0'&x"5";
504 157 jguarin200
                end case;
505
                ins(28 downto 24) := aco;
506
                ins(23 downto 19) := acf;
507
                ins(18 downto 14) := bdo;
508
                ins(13 downto 09) := bdf;
509
                ins(08) := comb;
510
                ins(07 downto 05) := "000";
511
                return ins;
512
 
513
 
514
        end function;
515
 
516
 
517
 
518 160 jguarin200
        procedure ap_v3f2string(l:inout line;v:in v3f) is
519 155 jguarin200
        begin
520 168 jguarin200
                write(l,string'("[X]"));
521
                write(l,string'(" "));
522
                ap_slvf2string(l,v(2));
523
                write(l,string'("[Y]"));
524
                write(l,string'(" "));
525
                ap_slvf2string(l,v(1));
526
                write(l,string'("[Z]"));
527
                write(l,string'(" "));
528
                ap_slvf2string(l,v(0));
529 160 jguarin200
        end procedure;
530 173 jguarin200
        procedure ap_xfp032string(l:inout line;vb03:in vectorblock03) is
531
        begin
532
                write(l,string'("[X]"));
533
                write(l,string'(" "));
534
                ap_slvf2string(l,vb03(2));
535
                write(l,string'("[Y]"));
536
                write(l,string'(" "));
537
                ap_slvf2string(l,vb03(1));
538
                write(l,string'("[Z]"));
539
                write(l,string'(" "));
540
                ap_slvf2string(l,vb03(0));
541
        end procedure;
542 160 jguarin200
 
543
        procedure ap_iCtrlState2string(l:inout line;i:in iCtrlState) is
544 158 jguarin200
                variable tmp:string (1 to 9);
545 156 jguarin200
        begin
546 160 jguarin200
 
547
                write(l,string'("<< "));
548 156 jguarin200
                case i is
549 181 jguarin200
                        when WAITING_FOR_A_RFULL_EVENT =>
550
                                tmp:="WAIT_RF_EVNT";
551
                        when INHIBIT_RFULL_INT =>
552
                                tmp:="INHB_RF_INT";
553 156 jguarin200
                        when others =>
554 158 jguarin200
                                tmp:="ILGL__VAL";
555 156 jguarin200
                end case;
556 160 jguarin200
                write(l,string'(tmp));
557
                write(l,string'(" >>"));
558 156 jguarin200
 
559 160 jguarin200
        end procedure;
560 156 jguarin200
 
561 160 jguarin200
        procedure ap_vnadd022string(l:inout line;va2:in vectorblockadd02) is
562 156 jguarin200
        begin
563 160 jguarin200
 
564
                write(l,string'("<<[1] "));
565
                ap_slv2hex(l,va2(1));
566
                write(l,string'(" [0] "));
567
                ap_slv2hex(l,va2(0));
568
                write(l,string'(" >>"));
569
 
570
        end procedure;
571 156 jguarin200
 
572 160 jguarin200
        procedure ap_macState2string(l:inout line;s:in macState) is
573 158 jguarin200
                variable tmp:string (1 to 6);
574 156 jguarin200
        begin
575 160 jguarin200
 
576
                write(l,string'("<< "));
577 156 jguarin200
                case s is
578
                        when LOAD_INSTRUCTION =>
579
                                tmp:="LD_INS";
580
                        when FLUSH_ARITH_PIPELINE =>
581
                                tmp:="FL_ARP";
582
                        when EXECUTE_INSTRUCTION =>
583
                                tmp:="EX_INS";
584
                        when others =>
585 158 jguarin200
                                tmp:="HEL_ON";
586 156 jguarin200
                end case;
587 160 jguarin200
                write(l,string'(tmp));
588
                write(l,string'(" >>"));
589
 
590
        end procedure;
591 156 jguarin200
 
592
        constant hexchars : string (1 to 16) := "0123456789ABCDEF";
593 160 jguarin200
        procedure ap_slv2hex (l:inout line;h:in std_logic_vector) is
594
                variable index_high,index_low,highone,nc : integer;
595
        begin
596
                highone := h'high-h'low;
597
                nc:=0;
598
                for i in h'high downto h'low loop
599
                        if h(i)/='0' and h(i)/='1' then
600
                                nc:=1;
601
                        end if;
602 156 jguarin200
                end loop;
603 160 jguarin200
 
604
                if nc=1 then
605
                        for i in h'high downto h'low loop
606
                                ap_sl2string(l,h(i));
607
                        end loop;
608
                else
609
                        for i in (highone)/4 downto 0 loop
610
                                index_low:=i*4;
611
                                if (index_low+3)>highone then
612
                                        index_high := highone;
613
                                else
614
                                        index_high := i*4+3;
615
                                end if;
616
                                write(l,hexchars(1+ieee.std_logic_unsigned.conv_integer(h(index_high+h'low downto index_low+h'low))));
617
                        end loop;
618
                end if;
619
        end procedure;
620
 
621 153 jguarin200
        function ap_slv2int (sl:std_logic_vector) return integer is
622
                alias s : std_logic_vector (sl'high downto sl'low) is sl;
623
                variable i : integer;
624
        begin
625
                i:=0;
626
                for index in s'high downto s'low loop
627
                        if s(index)='1' then
628
                                i:=i*2+1;
629
                        else
630
                                i:=i*2;
631
                        end if;
632
                end loop;
633
                return i;
634
 
635
        end function;
636
        function ap_fp2slv (f:real) return std_logic_vector is
637
                variable faux : real;
638
                variable sef : std_logic_vector (31 downto 0);
639
        begin
640
                --! Signo
641
                if (f<0.0) then
642
                        sef(31) := '1';
643 160 jguarin200
                        faux:=f*(-1.0);
644 153 jguarin200
                else
645
                        sef(31) := '0';
646 160 jguarin200
                        faux:=f;
647 153 jguarin200
                end if;
648
 
649
                --! Exponente
650 160 jguarin200
                sef(30 downto 23) := conv_std_logic_vector(127+integer(floor(log(faux,2.0))),8);
651 153 jguarin200
 
652
                --! Fraction
653 160 jguarin200
                faux :=faux/(2.0**real(floor(log(faux,2.0))));
654 153 jguarin200
                faux := faux - 1.0;
655
 
656 160 jguarin200
                sef(22 downto 0)  := conv_std_logic_vector(integer(faux*(2.0**23.0)),23);
657 153 jguarin200
 
658
                return sef;
659
 
660
        end function;
661
 
662
        function ap_slv2fp(sl:std_logic_vector) return real is
663 160 jguarin200
                variable frc:integer;
664 153 jguarin200
                alias s: std_logic_vector(31 downto 0) is sl;
665 160 jguarin200
                variable f,expo: real;
666 153 jguarin200
 
667
        begin
668
 
669
 
670 160 jguarin200
                expo:=real(ap_slv2int(s(30 downto 23)) - 127);
671
                expo:=(2.0)**(expo);
672 153 jguarin200
                frc:=ap_slv2int('1'&s(22 downto 0));
673
                f:=real(frc)*(2.0**(-23.0));
674
                f:=f*real(expo);
675
 
676
                if s(31)='1' then
677
                        return -f;
678
                else
679
                        return f;
680 160 jguarin200
                end if;
681 153 jguarin200
 
682 160 jguarin200
 
683 153 jguarin200
 
684 160 jguarin200
 
685 153 jguarin200
        end function;
686
 
687
        function ap_slv_calc_xyvec (x,y:integer; cam:apCamera) return v3f is
688
 
689
 
690
                variable dx,dy : real;
691
                variable v : v3f;
692
        begin
693
 
694
                dx := cam.width/real(cam.resx);
695
                dy := cam.height/real(cam.resy);
696
 
697 160 jguarin200
                --! Eje Z: Tomando el dedo &iacute;ndice de la mano derecha, este eje queda apuntando en la direcci&on en la que mira la c&aacute;mara u observador siempre.
698 153 jguarin200
                v(0):=ap_fp2slv(cam.dist);
699
 
700 160 jguarin200
                --! Eje X: Tomando el dedo coraz&oacute;n de la mano derecha, este eje queda apuntando a la izquierda del observador, desde el observador.
701
                v(2):=ap_fp2slv(dx*real(cam.resx)*0.5-real(x)*dx-dx*0.5);
702 153 jguarin200
 
703 160 jguarin200
                --! Eje Y: Tomando el dedo pulgar de la mano derecha, este eje queda apuntando hacia arriba del observador, desde el observador.
704
                v(1):=ap_fp2slv(dy*real(cam.resy)*0.5-real(y)*dy-dy*0.5);
705 153 jguarin200
 
706
                return v;
707
 
708
        end function;
709 155 jguarin200
 
710 160 jguarin200
        procedure ap_slvf2string(l:inout line;sl:std_logic_vector) is
711 155 jguarin200
                alias f: std_logic_vector(31 downto 0) is sl;
712
                variable r: real;
713
 
714
        begin
715
 
716
                r:=ap_slv2fp(f);
717 160 jguarin200
                write(l,string'(real'image(r)));
718
                write(l,string'(" [ s:"));
719
                ap_slv2hex(l,f(31 downto 31));
720
                write(l,string'(" f: "));
721
                ap_slv2hex(l,f(30 downto 23));
722
                write(l,string'(" m: "));
723
                ap_slv2hex(l,f(22 downto 00));
724
                write(l,string'(" ]"));
725 155 jguarin200
 
726 160 jguarin200
        end procedure;
727 155 jguarin200
 
728
 
729
 
730 153 jguarin200
 
731
end package body;

powered by: WebSVN 2.1.0

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