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 |
|
|
a32 : in std_logic_vector (31 downto 0);
|
89 |
|
|
b32 : in std_logic_vector (31 downto 0);
|
90 |
|
|
c32 : out std_logic_vector (31 downto 0)
|
91 |
|
|
);
|
92 |
|
|
end component;
|
93 |
|
|
component fmul32
|
94 |
|
|
port (
|
95 |
|
|
clk : in std_logic;
|
96 |
|
|
a32 : in std_logic_vector (31 downto 0);
|
97 |
|
|
b32 : in std_logic_vector (31 downto 0);
|
98 |
|
|
p32 : out std_logic_vector (31 downto 0)
|
99 |
|
|
);
|
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_writeable_blocks : integer;
|
249 |
|
|
external_readable_blocks : integer;
|
250 |
|
|
external_readable_widthad : integer;
|
251 |
|
|
external_writeable_widthad : integer
|
252 |
|
|
);
|
253 |
|
|
port (
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
clk,rst,dpfifo_rd,normfifo_rd,dpfifo_wr,normfifo_wr : in std_logic;
|
257 |
|
|
instrfifo_rd : in std_logic;
|
258 |
|
|
resultfifo_wr: in std_logic_vector(external_readable_blocks-1 downto 0);
|
259 |
|
|
instrfifo_empty: out std_logic; ext_rd,ext_wr: in std_logic;
|
260 |
|
|
ext_wr_add : in std_logic_vector(external_writeable_widthad+widthadmemblock-1 downto 0);
|
261 |
|
|
ext_rd_add : in std_logic_vector(external_readable_widthad-1 downto 0);
|
262 |
152 |
jguarin200 |
ext_d: in std_logic_vector(floatwidth-1 downto 0);
|
263 |
|
|
int_d : in std_logic_vector(external_readable_blocks*floatwidth-1 downto 0);
|
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 |
|
|
int_q : out std_logic_vector(external_writeable_blocks*floatwidth-1 downto 0);
|
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 |
152 |
jguarin200 |
paraminput : in std_logic_vector ((12*floatwidth)-1 downto 0); --! Vectores A,B,C,D
|
279 |
|
|
prd32blko : in std_logic_vector ((06*floatwidth)-1 downto 0); --! Salidas de los 6 multiplicadores.
|
280 |
|
|
add32blko : in std_logic_vector ((04*floatwidth)-1 downto 0); --! Salidas de los 4 sumadores.
|
281 |
|
|
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 |
|
|
prd32blki : out std_logic_vector ((12*floatwidth)-1 downto 0); --! Entrada de los 12 factores en el bloque de multiplicación respectivamente.
|
292 |
|
|
add32blki : out std_logic_vector ((08*floatwidth)-1 downto 0); --! 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 |
152 |
jguarin200 |
resultoutput : out std_logic_vector ((08*floatwidth)-1 downto 0) --! 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 |
|
|
f : in std_logic_vector (12*32-1 downto 0);
|
312 |
|
|
a : in std_logic_vector (8*32-1 downto 0);
|
313 |
|
|
|
314 |
|
|
s : out std_logic_vector (4*32-1 downto 0);
|
315 |
|
|
p : out std_logic_vector (6*32-1 downto 0)
|
316 |
|
|
|
317 |
|
|
);
|
318 |
|
|
end component;
|
319 |
|
|
--! Bloque de Raiz Cuadrada
|
320 |
|
|
component sqrt32
|
321 |
|
|
port (
|
322 |
|
|
|
323 |
|
|
clk : in std_logic;
|
324 |
|
|
rd32: in std_logic_vector(31 downto 0);
|
325 |
|
|
sq32: out std_logic_vector(31 downto 0)
|
326 |
|
|
);
|
327 |
|
|
end component;
|
328 |
|
|
--! Bloque de Inversores.
|
329 |
|
|
component invr32
|
330 |
|
|
port (
|
331 |
|
|
|
332 |
|
|
clk : in std_logic;
|
333 |
|
|
dvd32 : in std_logic_vector(31 downto 0);
|
334 |
|
|
qout32 : out std_logic_vector(31 downto 0)
|
335 |
|
|
);
|
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 |
155 |
jguarin200 |
function ap_slvf2string(sl:std_logic_vector) return string;
|
361 |
156 |
jguarin200 |
function ap_slv2hex (s:std_logic_vector) return string;
|
362 |
|
|
--! Función que devuelve una cadena con el estado de macState.
|
363 |
|
|
function ap_macState2string(s:macState) return string;
|
364 |
153 |
jguarin200 |
|
365 |
156 |
jguarin200 |
--! Función que devuelve la cadena de caracteres de 8 datos en punto flotante IEEE 754.
|
366 |
|
|
function ap_vblk082string(v8:vectorblock08) return string;
|
367 |
153 |
jguarin200 |
|
368 |
156 |
jguarin200 |
--! Función que devuelve la cadena de caracteres de 12 datos en punto flotante IEEE 754.
|
369 |
|
|
function ap_vblk122string(v12:vectorblock12) return string;
|
370 |
153 |
jguarin200 |
|
371 |
156 |
jguarin200 |
--! Función que convierte un array de 2 std_logic_vectors que contienen un par de direcciones en string
|
372 |
|
|
function ap_vnadd022string(va2:vectorblockadd02) return string;
|
373 |
153 |
jguarin200 |
|
374 |
156 |
jguarin200 |
--! Función que devuelve una cadena de caracteres con el estado de la maquina de estados que controla las interrupciones
|
375 |
|
|
function ap_iCtrlState2string(i:iCtrlState) return string;
|
376 |
|
|
|
377 |
|
|
--! Función que devuelve una cadena con los componentes de un vector R3 en punto flotante IEEE754
|
378 |
|
|
function ap_v3f2string(v:v3f) return string;
|
379 |
157 |
jguarin200 |
|
380 |
|
|
--! Función que formatea una instrucción
|
381 |
|
|
function ap_format_instruction(i:string;ac_o,bd_o,ac_f,bd_f:std_logic_vector;comb:std_logic) return std_logic_vector;
|
382 |
|
|
|
383 |
|
|
--! Función que devuelve una cadena de caracteres de un solo caracter con el valor de un bit std_logic
|
384 |
|
|
function ap_sl2string(s:std_logic) return string;
|
385 |
156 |
jguarin200 |
|
386 |
151 |
jguarin200 |
end package;
|
387 |
153 |
jguarin200 |
|
388 |
|
|
|
389 |
|
|
package body arithpack is
|
390 |
|
|
|
391 |
157 |
jguarin200 |
function ap_sl2string(s:std_logic) return string is
|
392 |
|
|
variable tmp:string(1 to 1);
|
393 |
|
|
begin
|
394 |
|
|
|
395 |
|
|
case s is
|
396 |
|
|
when '1' =>
|
397 |
|
|
tmp:="1";
|
398 |
|
|
when '0' =>
|
399 |
|
|
tmp:="0";
|
400 |
|
|
when 'U' =>
|
401 |
|
|
tmp:="U";
|
402 |
|
|
when 'X' =>
|
403 |
|
|
tmp:="X";
|
404 |
|
|
when 'Z' =>
|
405 |
|
|
tmp:="Z";
|
406 |
|
|
when 'W' =>
|
407 |
|
|
tmp:="W";
|
408 |
|
|
when 'L' =>
|
409 |
|
|
tmp:="L";
|
410 |
|
|
when 'H' =>
|
411 |
|
|
tmp:="H";
|
412 |
|
|
when others =>
|
413 |
|
|
tmp:="-"; -- Don't care
|
414 |
|
|
end case;
|
415 |
|
|
|
416 |
|
|
return tmp;
|
417 |
|
|
end function;
|
418 |
|
|
|
419 |
|
|
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
|
420 |
|
|
|
421 |
|
|
alias aco : std_logic_vector (4 downto 0) is ac_o;
|
422 |
|
|
alias acf : std_logic_vector (4 downto 0) is ac_f;
|
423 |
|
|
alias bdo : std_logic_vector (4 downto 0) is bd_o;
|
424 |
|
|
alias bdf : std_logic_vector (4 downto 0) is bd_f;
|
425 |
|
|
variable ins : std_logic_vector (31 downto 0);
|
426 |
|
|
alias it : string (1 to 3) is i;
|
427 |
|
|
begin
|
428 |
|
|
|
429 |
|
|
case it is
|
430 |
|
|
when "mag" =>
|
431 |
|
|
ins(31 downto 29) := "100";
|
432 |
|
|
ins(04 downto 00) := x"18";
|
433 |
|
|
when "nrm" =>
|
434 |
|
|
ins(31 downto 29) := "101";
|
435 |
|
|
ins(04 downto 00) := x"1d";
|
436 |
|
|
when "add" =>
|
437 |
|
|
ins(31 downto 29) := "001";
|
438 |
|
|
ins(04 downto 00) := x"0a";
|
439 |
|
|
when "sub" =>
|
440 |
|
|
ins(31 downto 29) := "011";
|
441 |
|
|
ins(04 downto 00) := x"0a";
|
442 |
|
|
when "dot" =>
|
443 |
|
|
ins(31 downto 29) := "000";
|
444 |
|
|
ins(04 downto 00) := x"17";
|
445 |
|
|
when "crs" =>
|
446 |
|
|
ins(31 downto 29) := "010";
|
447 |
|
|
ins(04 downto 00) := x"0e";
|
448 |
|
|
when others =>
|
449 |
|
|
ins(31 downto 29) := "111";
|
450 |
|
|
ins(04 downto 00) := x"05";
|
451 |
|
|
end case;
|
452 |
|
|
ins(28 downto 24) := aco;
|
453 |
|
|
ins(23 downto 19) := acf;
|
454 |
|
|
ins(18 downto 14) := bdo;
|
455 |
|
|
ins(13 downto 09) := bdf;
|
456 |
|
|
ins(08) := comb;
|
457 |
|
|
ins(07 downto 05) := "000";
|
458 |
|
|
return ins;
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
end function;
|
462 |
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
156 |
jguarin200 |
function ap_v3f2string(v:v3f) return string is
|
466 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
467 |
155 |
jguarin200 |
begin
|
468 |
156 |
jguarin200 |
tmp:="[X]"&ap_slvf2string(v(0))&"[Y]"&ap_slvf2string(v(1))&"[Z]"&ap_slvf2string(v(2));
|
469 |
|
|
return tmp;
|
470 |
|
|
end function;
|
471 |
155 |
jguarin200 |
|
472 |
156 |
jguarin200 |
function ap_iCtrlState2string(i:iCtrlState) return string is
|
473 |
|
|
|
474 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
475 |
156 |
jguarin200 |
|
476 |
|
|
begin
|
477 |
|
|
|
478 |
|
|
case i is
|
479 |
|
|
when WAITING_FOR_AN_EVENT =>
|
480 |
|
|
tmp:="WAIT_EVNT";
|
481 |
|
|
when FIRING_INTERRUPTIONS =>
|
482 |
|
|
tmp:="FIRE_INTx";
|
483 |
|
|
when SUSPEND =>
|
484 |
|
|
tmp:="SUSPENDED";
|
485 |
|
|
when others =>
|
486 |
|
|
tmp:="Pandora Box Opened -- Illegal iCtrlState value";
|
487 |
|
|
end case;
|
488 |
|
|
|
489 |
|
|
return tmp;
|
490 |
|
|
|
491 |
|
|
end function;
|
492 |
|
|
|
493 |
|
|
function ap_vnadd022string(va2:vectorblockadd02) return string is
|
494 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
495 |
156 |
jguarin200 |
begin
|
496 |
|
|
tmp:="[01]"&ap_slv2hex(va2(1))&" [00]"&ap_slv2hex(va2(0));
|
497 |
|
|
return tmp;
|
498 |
|
|
end function;
|
499 |
|
|
|
500 |
|
|
function ap_vblk122string(v12:vectorblock12) return string is
|
501 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
502 |
156 |
jguarin200 |
begin
|
503 |
|
|
|
504 |
|
|
tmp:="["&integer'image(11)&"]";
|
505 |
|
|
for i in 11 downto 0 loop
|
506 |
|
|
tmp:=tmp&ap_slvf2string(v12(i));
|
507 |
|
|
if i>0 then
|
508 |
|
|
tmp:=tmp&"["&integer'image(i)&"]";
|
509 |
|
|
end if;
|
510 |
|
|
end loop;
|
511 |
|
|
return tmp;
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
end function;
|
515 |
|
|
|
516 |
|
|
function ap_vblk082string(v8:vectorblock08) return string is
|
517 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
518 |
156 |
jguarin200 |
begin
|
519 |
|
|
|
520 |
|
|
tmp:="["&integer'image(7)&"]";
|
521 |
|
|
for i in 7 downto 0 loop
|
522 |
|
|
tmp:=tmp&ap_slvf2string(v8(i));
|
523 |
|
|
if i>0 then
|
524 |
|
|
tmp:=tmp&"["&integer'image(i)&"]";
|
525 |
|
|
end if;
|
526 |
|
|
end loop;
|
527 |
|
|
return tmp;
|
528 |
|
|
|
529 |
|
|
|
530 |
|
|
end function;
|
531 |
|
|
|
532 |
|
|
|
533 |
|
|
function ap_macState2string(s:macState) return string is
|
534 |
157 |
jguarin200 |
variable tmp:string (1 to 1024);
|
535 |
156 |
jguarin200 |
begin
|
536 |
|
|
case s is
|
537 |
|
|
when LOAD_INSTRUCTION =>
|
538 |
|
|
tmp:="LD_INS";
|
539 |
|
|
when FLUSH_ARITH_PIPELINE =>
|
540 |
|
|
tmp:="FL_ARP";
|
541 |
|
|
when EXECUTE_INSTRUCTION =>
|
542 |
|
|
tmp:="EX_INS";
|
543 |
|
|
when others =>
|
544 |
|
|
tmp:="macStateException:HELL_ON_EARTH";
|
545 |
|
|
end case;
|
546 |
|
|
return tmp;
|
547 |
|
|
end function;
|
548 |
|
|
|
549 |
|
|
constant hexchars : string (1 to 16) := "0123456789ABCDEF";
|
550 |
|
|
function ap_slv2hex (s:std_logic_vector) return string is
|
551 |
|
|
variable x64 : std_logic_vector(63 downto 0):=x"0000000000000000";
|
552 |
|
|
variable str : string (1 to 16);
|
553 |
|
|
begin
|
554 |
|
|
x64(s'high downto s'low):=s;
|
555 |
|
|
for i in 15 downto 0 loop
|
556 |
|
|
str(i+1):=hexchars(1+ieee.std_logic_unsigned.conv_integer(x64(i*4+3 downto i*4)));
|
557 |
|
|
end loop;
|
558 |
|
|
return str;
|
559 |
|
|
end function;
|
560 |
|
|
|
561 |
153 |
jguarin200 |
function ap_slv2int (sl:std_logic_vector) return integer is
|
562 |
|
|
alias s : std_logic_vector (sl'high downto sl'low) is sl;
|
563 |
|
|
variable i : integer;
|
564 |
|
|
begin
|
565 |
|
|
i:=0;
|
566 |
|
|
for index in s'high downto s'low loop
|
567 |
|
|
if s(index)='1' then
|
568 |
|
|
i:=i*2+1;
|
569 |
|
|
else
|
570 |
|
|
i:=i*2;
|
571 |
|
|
end if;
|
572 |
|
|
end loop;
|
573 |
|
|
return i;
|
574 |
|
|
|
575 |
|
|
end function;
|
576 |
|
|
function ap_fp2slv (f:real) return std_logic_vector is
|
577 |
|
|
variable faux : real;
|
578 |
|
|
variable sef : std_logic_vector (31 downto 0);
|
579 |
|
|
begin
|
580 |
|
|
--! Signo
|
581 |
|
|
if (f<0.0) then
|
582 |
|
|
sef(31) := '1';
|
583 |
|
|
else
|
584 |
|
|
sef(31) := '0';
|
585 |
|
|
end if;
|
586 |
|
|
|
587 |
|
|
--! Exponente
|
588 |
|
|
sef(30 downto 23) := conv_std_logic_vector(integer(floor(log(f,2.0))),8);
|
589 |
|
|
|
590 |
|
|
--! Fraction
|
591 |
|
|
faux :=f/floor(log(f,2.0));
|
592 |
|
|
faux := faux - 1.0;
|
593 |
|
|
|
594 |
|
|
sef(22 downto 0) := conv_std_logic_vector(integer(faux),23);
|
595 |
|
|
|
596 |
|
|
return sef;
|
597 |
|
|
|
598 |
|
|
end function;
|
599 |
|
|
|
600 |
|
|
function ap_slv2fp(sl:std_logic_vector) return real is
|
601 |
|
|
variable expo,frc:integer;
|
602 |
|
|
alias s: std_logic_vector(31 downto 0) is sl;
|
603 |
|
|
variable f: real;
|
604 |
|
|
|
605 |
|
|
begin
|
606 |
|
|
|
607 |
|
|
|
608 |
|
|
expo:=ap_slv2int(s(30 downto 23)) - 127;
|
609 |
|
|
expo:=2**expo;
|
610 |
|
|
frc:=ap_slv2int('1'&s(22 downto 0));
|
611 |
|
|
f:=real(frc)*(2.0**(-23.0));
|
612 |
|
|
f:=f*real(expo);
|
613 |
|
|
|
614 |
|
|
if s(31)='1' then
|
615 |
|
|
return -f;
|
616 |
|
|
else
|
617 |
|
|
return f;
|
618 |
|
|
end if;
|
619 |
|
|
|
620 |
|
|
|
621 |
|
|
end function;
|
622 |
|
|
|
623 |
|
|
function ap_slv_calc_xyvec (x,y:integer; cam:apCamera) return v3f is
|
624 |
|
|
|
625 |
|
|
|
626 |
|
|
variable dx,dy : real;
|
627 |
|
|
variable v : v3f;
|
628 |
|
|
begin
|
629 |
|
|
|
630 |
|
|
dx := cam.width/real(cam.resx);
|
631 |
|
|
dy := cam.height/real(cam.resy);
|
632 |
|
|
|
633 |
|
|
--! Eje X: Tomando el dedo índice de la mano derecha, este eje queda apuntando en la direcci&on en la que mira la cámara u observador siempre.
|
634 |
|
|
v(0):=ap_fp2slv(cam.dist);
|
635 |
|
|
|
636 |
|
|
--! Eje Y: Tomando el dedo corazón de la mano derecha, este eje queda apuntando a la izquierda del observador, desde el observador.
|
637 |
|
|
v(1):=ap_fp2slv(dx*real(cam.resx)*0.5-dx*0.5);
|
638 |
|
|
|
639 |
|
|
--! Eje Z: Tomando el dedo pulgar de la mano derecha, este eje queda apuntando hacia arriba del observador, desde el observador.
|
640 |
|
|
v(2):=ap_fp2slv(dy*real(cam.resy)*0.5-dy*0.5);
|
641 |
|
|
|
642 |
|
|
return v;
|
643 |
|
|
|
644 |
|
|
end function;
|
645 |
155 |
jguarin200 |
|
646 |
|
|
function ap_slvf2string(sl:std_logic_vector) return string is
|
647 |
|
|
alias f: std_logic_vector(31 downto 0) is sl;
|
648 |
|
|
variable r: real;
|
649 |
|
|
|
650 |
|
|
begin
|
651 |
|
|
|
652 |
|
|
r:=ap_slv2fp(f);
|
653 |
|
|
return real'image(r);
|
654 |
|
|
|
655 |
|
|
end function;
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
153 |
jguarin200 |
|
660 |
|
|
end package body;
|