emuspeed.c revision 1.4
1/*	$NetBSD: emuspeed.c,v 1.4 1999/01/31 10:28:57 is Exp $	*/
2
3#include <setjmp.h>
4#include <signal.h>
5#include <stdlib.h>
6#include <stdio.h>
7#include <time.h>
8#include <unistd.h>
9
10#include "speed.h"
11
12#define PRECISION 500
13
14const struct test {
15	char *name;
16	void (*func)__P((int));
17	char *comment;
18} testlist[] = {
19	{"Illegal", illegal, "(test: unimplemented)"},
20	{"mulsl Da,Db", mul32sreg, "(test: should be native)"},
21	{"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"},
22
23	{"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"},
24	{"mulul Dn,Da:Db", mul64ureg, "\t\""},
25	{"mulsl sp@(8),Da:Db", mul64smem, "\t\""},
26	{"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"},
27
28	{"divsl Da:Db,Dn", div64sreg, "\t\""},
29	{"divul Da:Db,Dn", div64ureg, "\t\""},
30	{"divsl Da:Db,sp@(8)", div64smem, "\t\""},
31	{"divul Da:Db,sp@(8)", div64umem, "\t\"\n"},
32
33	{NULL, NULL, NULL}
34};
35
36jmp_buf jbuf;
37void illhand (int);
38
39int
40main(argc, argv)
41	int argc;
42	char *argv[];
43{
44	const struct test *t;
45	clock_t start, stop;
46	int count;
47
48
49	if (signal(SIGILL, &illhand))
50		warn("%s: can't install illegal instruction handler.",
51		    argv[0]);
52
53	printf("Speed of instructions which are emulated on some cpus:\n\n");
54	(void)sleep(1);
55	for (t=testlist; t->name; t++) {
56		printf("%-20s", t->name);
57		fflush(stdout);
58
59		if (setjmp(jbuf)) {
60			printf("%12s    %s\n", "[unimplemented]", t->comment);
61			continue;
62		}
63
64		count = 1000;
65		do {
66			count *= 2;
67			start = clock();
68			t->func(count);
69			stop = clock();
70		} while ((stop - start) < PRECISION);
71		printf("%10d/s    %s\n",
72		    CLOCKS_PER_SEC*(count /(stop - start)),
73		    t->comment);
74	}
75	exit (0);
76}
77
78void
79illhand(int i)
80{
81	longjmp(jbuf, 1);
82}
83