1/*	$NetBSD: emuspeed.c,v 1.7 2008/04/28 20:23:06 martin Exp $	*/
2
3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <err.h>
30#include <setjmp.h>
31#include <signal.h>
32#include <stdlib.h>
33#include <stdio.h>
34#include <time.h>
35#include <unistd.h>
36
37#include "speed.h"
38
39#define PRECISION 500
40
41const struct test {
42	const char *name;
43	void (*func)(int);
44	const char *comment;
45} testlist[] = {
46	{"Illegal", illegal, "(test: unimplemented)"},
47	{"mulsl Da,Db", mul32sreg, "(test: should be native)"},
48	{"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"},
49
50	{"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"},
51	{"mulul Dn,Da:Db", mul64ureg, "\t\""},
52	{"mulsl sp@(8),Da:Db", mul64smem, "\t\""},
53	{"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"},
54
55	{"divsl Da:Db,Dn", div64sreg, "\t\""},
56	{"divul Da:Db,Dn", div64ureg, "\t\""},
57	{"divsl Da:Db,sp@(8)", div64smem, "\t\""},
58	{"divul Da:Db,sp@(8)", div64umem, "\t\"\n"},
59
60	{NULL, NULL, NULL}
61};
62
63jmp_buf jbuf;
64void illhand (int);
65int main(int, char *[]);
66
67int
68main(argc, argv)
69	int argc;
70	char *argv[];
71{
72	const struct test *t;
73	clock_t start, stop;
74	int count;
75
76
77	if (signal(SIGILL, &illhand))
78		warn("%s: can't install illegal instruction handler.",
79		    argv[0]);
80
81	printf("Speed of instructions which are emulated on some cpus:\n\n");
82	(void)sleep(1);
83	for (t=testlist; t->name; t++) {
84		printf("%-20s", t->name);
85		fflush(stdout);
86
87		if (setjmp(jbuf)) {
88			printf("%12s    %s\n", "[unimplemented]", t->comment);
89			continue;
90		}
91
92		count = 1000;
93		do {
94			count *= 2;
95			start = clock();
96			t->func(count);
97			stop = clock();
98		} while ((stop - start) < PRECISION);
99		printf("%10lu/s    %s\n",
100		    CLOCKS_PER_SEC*(count /(stop - start)),
101		    t->comment);
102	}
103	exit (0);
104}
105
106void
107illhand(int i)
108{
109	longjmp(jbuf, 1);
110}
111