emuspeed.c revision 1.4
11.4Sis/*	$NetBSD: emuspeed.c,v 1.4 1999/01/31 10:28:57 is Exp $	*/
21.2Sperry
31.1Sis#include <setjmp.h>
41.1Sis#include <signal.h>
51.1Sis#include <stdlib.h>
61.1Sis#include <stdio.h>
71.1Sis#include <time.h>
81.1Sis#include <unistd.h>
91.1Sis
101.1Sis#include "speed.h"
111.1Sis
121.3Sis#define PRECISION 500
131.3Sis
141.1Sisconst struct test {
151.1Sis	char *name;
161.1Sis	void (*func)__P((int));
171.1Sis	char *comment;
181.1Sis} testlist[] = {
191.3Sis	{"Illegal", illegal, "(test: unimplemented)"},
201.3Sis	{"mulsl Da,Db", mul32sreg, "(test: should be native)"},
211.3Sis	{"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"},
221.1Sis
231.3Sis	{"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"},
241.3Sis	{"mulul Dn,Da:Db", mul64ureg, "\t\""},
251.3Sis	{"mulsl sp@(8),Da:Db", mul64smem, "\t\""},
261.3Sis	{"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"},
271.3Sis
281.3Sis	{"divsl Da:Db,Dn", div64sreg, "\t\""},
291.3Sis	{"divul Da:Db,Dn", div64ureg, "\t\""},
301.3Sis	{"divsl Da:Db,sp@(8)", div64smem, "\t\""},
311.3Sis	{"divul Da:Db,sp@(8)", div64umem, "\t\"\n"},
321.1Sis
331.1Sis	{NULL, NULL, NULL}
341.1Sis};
351.1Sis
361.1Sisjmp_buf jbuf;
371.1Sisvoid illhand (int);
381.1Sis
391.1Sisint
401.1Sismain(argc, argv)
411.1Sis	int argc;
421.1Sis	char *argv[];
431.1Sis{
441.1Sis	const struct test *t;
451.1Sis	clock_t start, stop;
461.3Sis	int count;
471.1Sis
481.1Sis
491.1Sis	if (signal(SIGILL, &illhand))
501.1Sis		warn("%s: can't install illegal instruction handler.",
511.1Sis		    argv[0]);
521.1Sis
531.1Sis	printf("Speed of instructions which are emulated on some cpus:\n\n");
541.1Sis	(void)sleep(1);
551.1Sis	for (t=testlist; t->name; t++) {
561.1Sis		printf("%-20s", t->name);
571.1Sis		fflush(stdout);
581.1Sis
591.1Sis		if (setjmp(jbuf)) {
601.4Sis			printf("%12s    %s\n", "[unimplemented]", t->comment);
611.1Sis			continue;
621.1Sis		}
631.1Sis
641.3Sis		count = 1000;
651.3Sis		do {
661.3Sis			count *= 2;
671.3Sis			start = clock();
681.3Sis			t->func(count);
691.3Sis			stop = clock();
701.3Sis		} while ((stop - start) < PRECISION);
711.4Sis		printf("%10d/s    %s\n",
721.3Sis		    CLOCKS_PER_SEC*(count /(stop - start)),
731.1Sis		    t->comment);
741.1Sis	}
751.1Sis	exit (0);
761.1Sis}
771.1Sis
781.1Sisvoid
791.1Sisillhand(int i)
801.1Sis{
811.1Sis	longjmp(jbuf, 1);
821.1Sis}
83