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

Subversion Repositories special_functions_unit

[/] [special_functions_unit/] [Open_source_SFU/] [sfu_tb.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 divadnauj
 
2
library ieee;
3
use ieee.std_logic_1164.all;
4
use ieee.numeric_std.all;
5
use std.textio.all;
6
use ieee.std_logic_textio.all; -- require for writing/reading std_logic etc
7
 
8
entity sfu_tb is
9
end entity sfu_tb;
10
 
11
 
12
architecture verification of sfu_tb is
13
file f_input_cordic  : text;
14
file f_input_rsqrt  : text;
15
file f_input_log2  : text;
16
file f_input_ex2   : text;
17
 
18
file f_output_sin : text;
19
file f_output_cos: text;
20
file f_output_rsqrt : text;
21
file f_output_log2 : text;
22
file f_output_ex2 : text;
23
 
24
 
25
signal s_clk_i    :std_logic :='0';
26
signal s_rst_n    :std_logic :='0';
27
signal s_start_i  :std_logic :='0';
28
signal s_src1_i   :std_logic_vector(31 downto 0) :=(others=>'0');
29
signal s_selop_i  :std_logic_vector(2 downto 0) :=(others=>'0');
30
signal s_Result_o :std_logic_vector(31 downto 0);
31
signal s_stall_o  :std_logic;
32
 
33
signal lsfr_input  :std_logic_vector(31 downto 0):=X"00000001";
34
signal lsfr_op     :std_logic_vector(3 downto 0) :="1000";
35
 
36
begin
37
DUT: entity work.sfu
38
        port map(clk_i    => s_clk_i,
39
                 rst_n    => s_rst_n,
40
                 start_i  => s_start_i,
41
                 src1_i   => s_src1_i,
42
                 selop_i  => s_selop_i,
43
                 Result_o => s_Result_o,
44
                 stall_o  => s_stall_o);
45
 
46
clk_gen: process
47
                begin
48
                        wait for 50 ns;
49
                        s_clk_i <= not s_clk_i;
50
                end process;
51
 
52
rst_gen: process
53
                begin
54
                        wait for 500 ns;
55
                        s_rst_n <= '1';
56
                        wait;
57
                end process;
58
 
59
gata_gen:process
60
    variable v_i_line   : line; -- read lines one by one from f_input
61
    variable v_o_line   : line; -- write lines one by one to f_output
62
    variable v_x          : std_logic_vector(31 downto 0); -- valor de entrada
63
    variable v_comma            : character;
64
 
65
    variable v_character: character;
66
    variable hex_val    : std_logic_vector(3 downto 0);
67
    variable offset     : integer;
68
 
69
  begin
70
 
71
  -- open files
72
  file_open(f_input_cordic, "input_cordic.csv", read_mode);
73
  file_open(f_input_rsqrt , "input_rsqrt.csv", read_mode);
74
  file_open(f_input_log2  , "input_log2.csv", read_mode);
75
  file_open(f_input_ex2   , "input_ex2.csv", read_mode);
76
 
77
  file_open(f_output_sin, "output_sin.csv", write_mode);
78
  file_open(f_output_cos, "output_cos.csv", write_mode);
79
  file_open(f_output_rsqrt , "output_rsqrt.csv", write_mode);
80
  file_open(f_output_log2  , "output_log2.csv", write_mode);
81
  file_open(f_output_ex2   , "output_ex2.csv", write_mode);
82
 
83
        wait on s_clk_i until s_rst_n='1';
84
  --========================SIN=============================================    
85
  -- encabezado de texto
86
  write(v_o_line, string'("Input,Sin"));
87
  writeline(f_output_sin, v_o_line);
88
  -----------------------------------------------------------------------------
89
  readline(f_input_cordic, v_i_line);           -- se omite linea de encabezado
90
  while not endfile(f_input_cordic) loop
91
        readline(f_input_cordic, v_i_line);
92
        -- lectura de hexadecimal
93
    offset := 0;
94
    while offset < v_x'left loop
95
      read(v_i_line, v_character);
96
      case v_character is
97
        when '0' => hex_val := "0000";
98
              when '1' => hex_val := "0001";
99
              when '2' => hex_val := "0010";
100
              when '3' => hex_val := "0011";
101
              when '4' => hex_val := "0100";
102
              when '5' => hex_val := "0101";
103
              when '6' => hex_val := "0110";
104
              when '7' => hex_val := "0111";
105
              when '8' => hex_val := "1000";
106
              when '9' => hex_val := "1001";
107
              when 'A' | 'a' => hex_val := "1010";
108
              when 'B' | 'b' => hex_val := "1011";
109
              when 'C' | 'c' => hex_val := "1100";
110
              when 'D' | 'd' => hex_val := "1101";
111
              when 'E' | 'e' => hex_val := "1110";
112
              when 'F' | 'f' => hex_val := "1111";
113
              when others       =>      hex_val := "XXXX";
114
               assert false report "Found non-hex character '" & v_character & "'";
115
      end case;
116
      v_x(v_x'left - offset downto v_x'left-offset-3) := hex_val;
117
      offset := offset + 4;
118
    end loop;
119
 
120
    -- iniciar calculo
121
        s_selop_i <= "000";
122
    s_src1_i <= v_x;
123
        s_start_i <= '1';
124
        wait until falling_edge(s_clk_i);
125
        s_start_i <= '0';
126
        wait on s_clk_i until s_stall_o='0';
127
    -- escribir resultados
128
    hwrite(v_o_line, s_src1_i);
129
    write(v_o_line, string'(","));
130
    hwrite(v_o_line, s_Result_o);
131
    writeline(f_output_sin, v_o_line);
132
        wait until falling_edge(s_clk_i);
133
  end  loop;
134
  --file_close(f_output_sin);
135
  file_close(f_input_cordic);
136
  file_open(f_input_cordic, "input_cordic.csv", read_mode);
137
  --========================COS=============================================
138
   -- encabezado de texto
139
  write(v_o_line, string'("Input,cos"));
140
  writeline(f_output_cos, v_o_line);
141
  -----------------------------------------------------------------------------
142
  readline(f_input_cordic, v_i_line);           -- se omite linea de encabezado
143
  while not endfile(f_input_cordic) loop
144
        readline(f_input_cordic, v_i_line);
145
        -- lectura de hexadecimal
146
    offset := 0;
147
    while offset < v_x'left loop
148
      read(v_i_line, v_character);
149
      case v_character is
150
        when '0' => hex_val := "0000";
151
              when '1' => hex_val := "0001";
152
              when '2' => hex_val := "0010";
153
              when '3' => hex_val := "0011";
154
              when '4' => hex_val := "0100";
155
              when '5' => hex_val := "0101";
156
              when '6' => hex_val := "0110";
157
              when '7' => hex_val := "0111";
158
              when '8' => hex_val := "1000";
159
              when '9' => hex_val := "1001";
160
              when 'A' | 'a' => hex_val := "1010";
161
              when 'B' | 'b' => hex_val := "1011";
162
              when 'C' | 'c' => hex_val := "1100";
163
              when 'D' | 'd' => hex_val := "1101";
164
              when 'E' | 'e' => hex_val := "1110";
165
              when 'F' | 'f' => hex_val := "1111";
166
              when others       =>      hex_val := "XXXX";
167
               assert false report "Found non-hex character '" & v_character & "'";
168
      end case;
169
      v_x(v_x'left - offset downto v_x'left-offset-3) := hex_val;
170
      offset := offset + 4;
171
    end loop;
172
 
173
    -- iniciar calculo
174
        s_selop_i <= "001";
175
    s_src1_i <= v_x;
176
        s_start_i <= '1';
177
        wait until falling_edge(s_clk_i);
178
        s_start_i <= '0';
179
        wait on s_clk_i until s_stall_o='0';
180
    -- escribir resultados
181
    hwrite(v_o_line, s_src1_i);
182
    write(v_o_line, string'(","));
183
    hwrite(v_o_line, s_Result_o);
184
    writeline(f_output_cos, v_o_line);
185
        wait until falling_edge(s_clk_i);
186
  end  loop;
187
 
188
  --=======================RSQRT=============================================
189
  -- encabezado de texto
190
  write(v_o_line, string'("Input,rsqrt"));
191
  writeline(f_output_rsqrt, v_o_line);
192
  -----------------------------------------------------------------------------
193
  readline(f_input_rsqrt, v_i_line);            -- se omite linea de encabezado
194
  while not endfile(f_input_rsqrt) loop
195
        readline(f_input_rsqrt, v_i_line);
196
        -- lectura de hexadecimal
197
    offset := 0;
198
    while offset < v_x'left loop
199
      read(v_i_line, v_character);
200
      case v_character is
201
        when '0' => hex_val := "0000";
202
              when '1' => hex_val := "0001";
203
              when '2' => hex_val := "0010";
204
              when '3' => hex_val := "0011";
205
              when '4' => hex_val := "0100";
206
              when '5' => hex_val := "0101";
207
              when '6' => hex_val := "0110";
208
              when '7' => hex_val := "0111";
209
              when '8' => hex_val := "1000";
210
              when '9' => hex_val := "1001";
211
              when 'A' | 'a' => hex_val := "1010";
212
              when 'B' | 'b' => hex_val := "1011";
213
              when 'C' | 'c' => hex_val := "1100";
214
              when 'D' | 'd' => hex_val := "1101";
215
              when 'E' | 'e' => hex_val := "1110";
216
              when 'F' | 'f' => hex_val := "1111";
217
              when others       =>      hex_val := "XXXX";
218
               assert false report "Found non-hex character '" & v_character & "'";
219
      end case;
220
      v_x(v_x'left - offset downto v_x'left-offset-3) := hex_val;
221
      offset := offset + 4;
222
    end loop;
223
 
224
    -- iniciar calculo
225
        s_selop_i <= "010";
226
    s_src1_i <= v_x;
227
        s_start_i <= '1';
228
        wait until falling_edge(s_clk_i);
229
        s_start_i <= '0';
230
        wait on s_clk_i until s_stall_o='0';
231
    -- escribir resultados
232
    hwrite(v_o_line, s_src1_i);
233
    write(v_o_line, string'(","));
234
    hwrite(v_o_line, s_Result_o);
235
    writeline(f_output_rsqrt, v_o_line);
236
        wait until falling_edge(s_clk_i);
237
  end  loop;
238
  --========================LOG2=============================================
239
    -- encabezado de texto
240
  write(v_o_line, string'("Input,log2"));
241
  writeline(f_output_log2, v_o_line);
242
  -----------------------------------------------------------------------------
243
  readline(f_input_log2, v_i_line);             -- se omite linea de encabezado
244
  while not endfile(f_input_log2) loop
245
        readline(f_input_log2, v_i_line);
246
        -- lectura de hexadecimal
247
    offset := 0;
248
    while offset < v_x'left loop
249
      read(v_i_line, v_character);
250
      case v_character is
251
        when '0' => hex_val := "0000";
252
              when '1' => hex_val := "0001";
253
              when '2' => hex_val := "0010";
254
              when '3' => hex_val := "0011";
255
              when '4' => hex_val := "0100";
256
              when '5' => hex_val := "0101";
257
              when '6' => hex_val := "0110";
258
              when '7' => hex_val := "0111";
259
              when '8' => hex_val := "1000";
260
              when '9' => hex_val := "1001";
261
              when 'A' | 'a' => hex_val := "1010";
262
              when 'B' | 'b' => hex_val := "1011";
263
              when 'C' | 'c' => hex_val := "1100";
264
              when 'D' | 'd' => hex_val := "1101";
265
              when 'E' | 'e' => hex_val := "1110";
266
              when 'F' | 'f' => hex_val := "1111";
267
              when others       =>      hex_val := "XXXX";
268
               assert false report "Found non-hex character '" & v_character & "'";
269
      end case;
270
      v_x(v_x'left - offset downto v_x'left-offset-3) := hex_val;
271
      offset := offset + 4;
272
    end loop;
273
 
274
    -- iniciar calculo
275
        s_selop_i <= "011";
276
    s_src1_i <= v_x;
277
        s_start_i <= '1';
278
        wait until falling_edge(s_clk_i);
279
        s_start_i <= '0';
280
        wait on s_clk_i until s_stall_o='0';
281
    -- escribir resultados
282
    hwrite(v_o_line, s_src1_i);
283
    write(v_o_line, string'(","));
284
    hwrite(v_o_line, s_Result_o);
285
    writeline(f_output_log2, v_o_line);
286
        wait until falling_edge(s_clk_i);
287
  end  loop;
288
  --========================EX22=============================================
289
    -- encabezado de texto
290
  write(v_o_line, string'("Input,ex2"));
291
  writeline(f_output_ex2, v_o_line);
292
  -----------------------------------------------------------------------------
293
  readline(f_input_ex2, v_i_line);              -- se omite linea de encabezado
294
  while not endfile(f_input_ex2) loop
295
        readline(f_input_ex2, v_i_line);
296
        -- lectura de hexadecimal
297
    offset := 0;
298
    while offset < v_x'left loop
299
      read(v_i_line, v_character);
300
      case v_character is
301
        when '0' => hex_val := "0000";
302
              when '1' => hex_val := "0001";
303
              when '2' => hex_val := "0010";
304
              when '3' => hex_val := "0011";
305
              when '4' => hex_val := "0100";
306
              when '5' => hex_val := "0101";
307
              when '6' => hex_val := "0110";
308
              when '7' => hex_val := "0111";
309
              when '8' => hex_val := "1000";
310
              when '9' => hex_val := "1001";
311
              when 'A' | 'a' => hex_val := "1010";
312
              when 'B' | 'b' => hex_val := "1011";
313
              when 'C' | 'c' => hex_val := "1100";
314
              when 'D' | 'd' => hex_val := "1101";
315
              when 'E' | 'e' => hex_val := "1110";
316
              when 'F' | 'f' => hex_val := "1111";
317
              when others       =>      hex_val := "XXXX";
318
               assert false report "Found non-hex character '" & v_character & "'";
319
      end case;
320
      v_x(v_x'left - offset downto v_x'left-offset-3) := hex_val;
321
      offset := offset + 4;
322
    end loop;
323
 
324
    -- iniciar calculo
325
        s_selop_i <= "100";
326
    s_src1_i <= v_x;
327
        s_start_i <= '1';
328
        wait until falling_edge(s_clk_i);
329
        s_start_i <= '0';
330
        wait on s_clk_i until s_stall_o='0';
331
    -- escribir resultados
332
    hwrite(v_o_line, s_src1_i);
333
    write(v_o_line, string'(","));
334
    hwrite(v_o_line, s_Result_o);
335
    writeline(f_output_ex2, v_o_line);
336
        wait until falling_edge(s_clk_i);
337
  end  loop;
338
  -----------------------------------------------------------------------------
339
  -- close  files
340
  file_close(f_input_cordic);
341
  file_close(f_input_rsqrt );
342
  file_close(f_input_log2  );
343
  file_close(f_input_ex2   );
344
 
345
  file_close(f_output_sin );
346
  file_close(f_output_cos );
347
  file_close(f_output_rsqrt);
348
  file_close(f_output_log2 );
349
  file_close(f_output_ex2  );
350
 
351
 
352
  for i in 0 to 20000 loop
353
 
354
        s_selop_i <= lsfr_op(2 downto 0);
355
    s_src1_i <= lsfr_input;
356
        s_start_i <= '1';
357
        wait until falling_edge(s_clk_i);
358
        s_start_i <= '0';
359
        wait on s_clk_i until s_stall_o='0';
360
        wait until falling_edge(s_clk_i);
361
        lsfr_input(30 downto 0) <=lsfr_input(31 downto 1);
362
        lsfr_input(31) <= lsfr_input(0) xor lsfr_input(5)xor lsfr_input(12)xor lsfr_input(15)xor lsfr_input(22)xor lsfr_input(24);
363
        lsfr_op(2 downto 0) <= lsfr_op(3 downto 1);
364
        lsfr_op(3) <= lsfr_op(0) xor lsfr_op(2);
365
  end loop;
366
 
367
  wait;
368
  end process;
369
 
370
 
371
end verification;

powered by: WebSVN 2.1.0

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