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

Subversion Repositories raytrac

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

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

powered by: WebSVN 2.1.0

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