11.8Stsutsui/*	$NetBSD: emuspeed.c,v 1.8 2011/05/18 18:41:59 tsutsui Exp $	*/
21.5Sitojun
31.5Sitojun/*-
41.5Sitojun * Copyright (c) 1997 The NetBSD Foundation, Inc.
51.5Sitojun * All rights reserved.
61.5Sitojun *
71.5Sitojun * Redistribution and use in source and binary forms, with or without
81.5Sitojun * modification, are permitted provided that the following conditions
91.5Sitojun * are met:
101.5Sitojun * 1. Redistributions of source code must retain the above copyright
111.5Sitojun *    notice, this list of conditions and the following disclaimer.
121.5Sitojun * 2. Redistributions in binary form must reproduce the above copyright
131.5Sitojun *    notice, this list of conditions and the following disclaimer in the
141.5Sitojun *    documentation and/or other materials provided with the distribution.
151.5Sitojun *
161.5Sitojun * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.5Sitojun * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.5Sitojun * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.5Sitojun * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.5Sitojun * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.5Sitojun * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.5Sitojun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.5Sitojun * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.5Sitojun * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.5Sitojun * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.5Sitojun * POSSIBILITY OF SUCH DAMAGE.
271.5Sitojun */
281.2Sperry
291.8Stsutsui#include <err.h>
301.1Sis#include <setjmp.h>
311.1Sis#include <signal.h>
321.1Sis#include <stdlib.h>
331.1Sis#include <stdio.h>
341.1Sis#include <time.h>
351.1Sis#include <unistd.h>
361.1Sis
371.1Sis#include "speed.h"
381.1Sis
391.3Sis#define PRECISION 500
401.3Sis
411.1Sisconst struct test {
421.8Stsutsui	const char *name;
431.6Sperry	void (*func)(int);
441.8Stsutsui	const char *comment;
451.1Sis} testlist[] = {
461.3Sis	{"Illegal", illegal, "(test: unimplemented)"},
471.3Sis	{"mulsl Da,Db", mul32sreg, "(test: should be native)"},
481.3Sis	{"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"},
491.1Sis
501.3Sis	{"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"},
511.3Sis	{"mulul Dn,Da:Db", mul64ureg, "\t\""},
521.3Sis	{"mulsl sp@(8),Da:Db", mul64smem, "\t\""},
531.3Sis	{"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"},
541.3Sis
551.3Sis	{"divsl Da:Db,Dn", div64sreg, "\t\""},
561.3Sis	{"divul Da:Db,Dn", div64ureg, "\t\""},
571.3Sis	{"divsl Da:Db,sp@(8)", div64smem, "\t\""},
581.3Sis	{"divul Da:Db,sp@(8)", div64umem, "\t\"\n"},
591.1Sis
601.1Sis	{NULL, NULL, NULL}
611.1Sis};
621.1Sis
631.1Sisjmp_buf jbuf;
641.1Sisvoid illhand (int);
651.8Stsutsuiint main(int, char *[]);
661.1Sis
671.1Sisint
681.1Sismain(argc, argv)
691.1Sis	int argc;
701.1Sis	char *argv[];
711.1Sis{
721.1Sis	const struct test *t;
731.1Sis	clock_t start, stop;
741.3Sis	int count;
751.1Sis
761.1Sis
771.1Sis	if (signal(SIGILL, &illhand))
781.1Sis		warn("%s: can't install illegal instruction handler.",
791.1Sis		    argv[0]);
801.1Sis
811.1Sis	printf("Speed of instructions which are emulated on some cpus:\n\n");
821.1Sis	(void)sleep(1);
831.1Sis	for (t=testlist; t->name; t++) {
841.1Sis		printf("%-20s", t->name);
851.1Sis		fflush(stdout);
861.1Sis
871.1Sis		if (setjmp(jbuf)) {
881.4Sis			printf("%12s    %s\n", "[unimplemented]", t->comment);
891.1Sis			continue;
901.1Sis		}
911.1Sis
921.3Sis		count = 1000;
931.3Sis		do {
941.3Sis			count *= 2;
951.3Sis			start = clock();
961.3Sis			t->func(count);
971.3Sis			stop = clock();
981.3Sis		} while ((stop - start) < PRECISION);
991.8Stsutsui		printf("%10lu/s    %s\n",
1001.3Sis		    CLOCKS_PER_SEC*(count /(stop - start)),
1011.1Sis		    t->comment);
1021.1Sis	}
1031.1Sis	exit (0);
1041.1Sis}
1051.1Sis
1061.1Sisvoid
1071.1Sisillhand(int i)
1081.1Sis{
1091.1Sis	longjmp(jbuf, 1);
1101.1Sis}
111