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

Subversion Repositories raytrac

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

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

powered by: WebSVN 2.1.0

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