blob: 02904b2c5f0957a3f239ab69fa729955ff96f31f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "asm.h"
#include "tpu.h"
#include "util.h"
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
static struct tis tis;
int (*cleanup)(void) = NULL;
const char *progname = "tis100";
static bool
io_active(struct tis *tis)
{
struct tpu_io_port *io_port;
int i;
for (i = 0; i < TIS_MAX_IO_PORTS; i++) {
io_port = tis->in_ports[i];
if (!io_port || !io_port->file) continue;
if (io_port->port.attached && !io_port->port.writing
&& !feof(io_port->file))
return true;
}
return false;
}
int
main(int argc, const char **argv)
{
struct tis_stats stats;
bool idle, prev_idle;
if (argc < 2) {
fprintf(stderr, "Usage: tis100 FILE [IO..]\n");
exit(1);
}
tis_init(&tis);
tis_load(&tis, argv);
idle = false;
while (!idle || !prev_idle || io_active(&tis)) {
prev_idle = idle;
idle = !tis_step(&tis);
}
if (tis.show_stats) {
stats = tis_gen_stats(&tis);
printf("=== stats ===\n");
printf(" cycles: %zu\n", stats.steps);
printf(" nodes: %zu\n", stats.nodes);
printf(" insts: %zu\n", stats.insts);
printf(" idle: %2.1f%%\n", stats.idle * 100);
printf("=============\n");
}
tis_deinit(&tis);
}
|