1 /* $NetBSD: emuspeed.c,v 1.5 2002/02/21 07:38:19 itojun 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 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the NetBSD 18 * Foundation, Inc. and its contributors. 19 * 4. Neither the name of The NetBSD Foundation nor the names of its 20 * contributors may be used to endorse or promote products derived 21 * from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include <setjmp.h> 37 #include <signal.h> 38 #include <stdlib.h> 39 #include <stdio.h> 40 #include <time.h> 41 #include <unistd.h> 42 43 #include "speed.h" 44 45 #define PRECISION 500 46 47 const struct test { 48 char *name; 49 void (*func)__P((int)); 50 char *comment; 51 } testlist[] = { 52 {"Illegal", illegal, "(test: unimplemented)"}, 53 {"mulsl Da,Db", mul32sreg, "(test: should be native)"}, 54 {"mulsl sp@(8),Da", mul32smem, "(test: should be native)\n"}, 55 56 {"mulsl Dn,Da:Db", mul64sreg, "emulated on 68060"}, 57 {"mulul Dn,Da:Db", mul64ureg, "\t\""}, 58 {"mulsl sp@(8),Da:Db", mul64smem, "\t\""}, 59 {"mulul sp@(8),Da:Db", mul64umem, "\t\"\n"}, 60 61 {"divsl Da:Db,Dn", div64sreg, "\t\""}, 62 {"divul Da:Db,Dn", div64ureg, "\t\""}, 63 {"divsl Da:Db,sp@(8)", div64smem, "\t\""}, 64 {"divul Da:Db,sp@(8)", div64umem, "\t\"\n"}, 65 66 {NULL, NULL, NULL} 67 }; 68 69 jmp_buf jbuf; 70 void illhand (int); 71 72 int 73 main(argc, argv) 74 int argc; 75 char *argv[]; 76 { 77 const struct test *t; 78 clock_t start, stop; 79 int count; 80 81 82 if (signal(SIGILL, &illhand)) 83 warn("%s: can't install illegal instruction handler.", 84 argv[0]); 85 86 printf("Speed of instructions which are emulated on some cpus:\n\n"); 87 (void)sleep(1); 88 for (t=testlist; t->name; t++) { 89 printf("%-20s", t->name); 90 fflush(stdout); 91 92 if (setjmp(jbuf)) { 93 printf("%12s %s\n", "[unimplemented]", t->comment); 94 continue; 95 } 96 97 count = 1000; 98 do { 99 count *= 2; 100 start = clock(); 101 t->func(count); 102 stop = clock(); 103 } while ((stop - start) < PRECISION); 104 printf("%10d/s %s\n", 105 CLOCKS_PER_SEC*(count /(stop - start)), 106 t->comment); 107 } 108 exit (0); 109 } 110 111 void 112 illhand(int i) 113 { 114 longjmp(jbuf, 1); 115 } 116