emuspeed.c revision 1.5
11.5Sitojun/* $NetBSD: emuspeed.c,v 1.5 2002/02/21 07:38:19 itojun 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 * 3. All advertising materials mentioning features or use of this software 161.5Sitojun * must display the following acknowledgement: 171.5Sitojun * This product includes software developed by the NetBSD 181.5Sitojun * Foundation, Inc. and its contributors. 191.5Sitojun * 4. Neither the name of The NetBSD Foundation nor the names of its 201.5Sitojun * contributors may be used to endorse or promote products derived 211.5Sitojun * from this software without specific prior written permission. 221.5Sitojun * 231.5Sitojun * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 241.5Sitojun * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 251.5Sitojun * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 261.5Sitojun * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 271.5Sitojun * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281.5Sitojun * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291.5Sitojun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 301.5Sitojun * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 311.5Sitojun * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 321.5Sitojun * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 331.5Sitojun * POSSIBILITY OF SUCH DAMAGE. 341.5Sitojun */ 351.2Sperry 361.1Sis#include <setjmp.h> 371.1Sis#include <signal.h> 381.1Sis#include <stdlib.h> 391.1Sis#include <stdio.h> 401.1Sis#include <time.h> 411.1Sis#include <unistd.h> 421.1Sis 431.1Sis#include "speed.h" 441.1Sis 451.3Sis#define PRECISION 500 461.3Sis 471.1Sisconst struct test { 481.1Sis char *name; 491.1Sis void (*func)__P((int)); 501.1Sis char *comment; 511.1Sis} testlist[] = { 521.3Sis {"Illegal", illegal, "(test: unimplemented)"}, 531.3Sis {"mulsl Da,Db", mul32sreg, "(test: should be native)"}, 541.3Sis {"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"}, 551.1Sis 561.3Sis {"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"}, 571.3Sis {"mulul Dn,Da:Db", mul64ureg, "\t\""}, 581.3Sis {"mulsl sp@(8),Da:Db", mul64smem, "\t\""}, 591.3Sis {"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"}, 601.3Sis 611.3Sis {"divsl Da:Db,Dn", div64sreg, "\t\""}, 621.3Sis {"divul Da:Db,Dn", div64ureg, "\t\""}, 631.3Sis {"divsl Da:Db,sp@(8)", div64smem, "\t\""}, 641.3Sis {"divul Da:Db,sp@(8)", div64umem, "\t\"\n"}, 651.1Sis 661.1Sis {NULL, NULL, NULL} 671.1Sis}; 681.1Sis 691.1Sisjmp_buf jbuf; 701.1Sisvoid illhand (int); 711.1Sis 721.1Sisint 731.1Sismain(argc, argv) 741.1Sis int argc; 751.1Sis char *argv[]; 761.1Sis{ 771.1Sis const struct test *t; 781.1Sis clock_t start, stop; 791.3Sis int count; 801.1Sis 811.1Sis 821.1Sis if (signal(SIGILL, &illhand)) 831.1Sis warn("%s: can't install illegal instruction handler.", 841.1Sis argv[0]); 851.1Sis 861.1Sis printf("Speed of instructions which are emulated on some cpus:\n\n"); 871.1Sis (void)sleep(1); 881.1Sis for (t=testlist; t->name; t++) { 891.1Sis printf("%-20s", t->name); 901.1Sis fflush(stdout); 911.1Sis 921.1Sis if (setjmp(jbuf)) { 931.4Sis printf("%12s %s\n", "[unimplemented]", t->comment); 941.1Sis continue; 951.1Sis } 961.1Sis 971.3Sis count = 1000; 981.3Sis do { 991.3Sis count *= 2; 1001.3Sis start = clock(); 1011.3Sis t->func(count); 1021.3Sis stop = clock(); 1031.3Sis } while ((stop - start) < PRECISION); 1041.4Sis printf("%10d/s %s\n", 1051.3Sis CLOCKS_PER_SEC*(count /(stop - start)), 1061.1Sis t->comment); 1071.1Sis } 1081.1Sis exit (0); 1091.1Sis} 1101.1Sis 1111.1Sisvoid 1121.1Sisillhand(int i) 1131.1Sis{ 1141.1Sis longjmp(jbuf, 1); 1151.1Sis} 116