--- uae/src/md-i386-gcc/support.c 2018/04/24 16:39:33 1.1.1.1 +++ uae/src/md-i386-gcc/support.c 2018/04/24 17:17:34 1.1.1.10 @@ -1,6 +1,6 @@ - /* + /* * UAE - The Un*x Amiga Emulator - * + * * Miscellaneous machine dependent support functions and definitions * * Copyright 1996 Bernd Schmidt @@ -10,128 +10,110 @@ #include "sysconfig.h" #include "sysdeps.h" -#include "config.h" #include "options.h" #include "machdep/m68k.h" +#include "events.h" +#include "custom.h" + +#ifndef USE_UNDERSCORE +#define LARGE_ALIGNMENT ".align 16\n" +#else +#define LARGE_ALIGNMENT ".align 4,0x90\n" +#endif struct flag_struct regflags; -/* - * Careful: No unique labels. Unfortunately, not each installation of GCC - * comes with GAS. Bletch. - */ +/* All the Win32 configurations handle this in od-win32/win32.c */ +#ifndef _WIN32 + +#include -int fast_memcmp(const void *foo, const void *bar, int len) +static volatile frame_time_t last_time, best_time; +static volatile int loops_to_go; + +#ifndef HAVE_SETITIMER +#define TIME_UNIT 1000000 +#else +#define TIME_UNIT 100000 +#endif + +static void set_alarm (void) { - int differs, baz; - __asm__ __volatile__ ("subl $4, %2\n" - "jc LLA2\n" - "LLA1:\n" - "movl (%0),%%ebx\n" - "cmpl (%1),%%ebx\n" - "jne LLA5\n" - "addl $4, %0\n" - "addl $4, %1\n" - "subl $4, %2\n" - "jnc LLA1\n" - "LLA2:\n" - "addl $4, %2\n" - "jz LLA4\n" - "LLA3:\n" - "movb (%0),%%bl\n" - "cmpb (%1),%%bl\n" - "jne LLA5\n" - "incl %0\n" - "incl %1\n" - "decl %2\n" - "jnz LLA3\n" - "LLA4:\n" - "movl $0, %3\n" - "jmp LLA6\n" - "LLA5:\n" - "movl $1, %3\n" - "LLA6:\n" - : "=&r" (foo), "=&r" (bar), "=&rm" (len), "=rm" (differs), - "=&b" (baz) - : "0" (foo), "1" (bar), "2" (len), "3" (baz) : "cc"); - return differs; +#ifndef HAVE_SETITIMER + alarm (1); +#else + struct itimerval t; + t.it_value.tv_sec = 0; + t.it_value.tv_usec = TIME_UNIT; + t.it_interval.tv_sec = 0; + t.it_interval.tv_usec = TIME_UNIT; + setitimer (ITIMER_REAL, &t, NULL); +#endif } -int memcmpy(void *foo, const void *bar, int len) +static int first_loop = 1; + +#ifdef __cplusplus +static RETSIGTYPE alarmhandler(...) +#else +static RETSIGTYPE alarmhandler(int foo) +#endif { - int differs, baz = 0, uupzuq = 0; + frame_time_t bar; + bar = read_processor_time (); + if (! first_loop && bar - last_time < best_time) + best_time = bar - last_time; + first_loop = 0; + if (--loops_to_go > 0) { + signal (SIGALRM, alarmhandler); + last_time = read_processor_time(); + set_alarm (); + } else { + alarm (0); + signal (SIGALRM, SIG_IGN); + } +} + +#include +jmp_buf catch_test; - __asm__ __volatile__ ("subl %1, %2\n" - "movl $0, %0\n" - "subl $16, %3\n" - "jc LLB7\n" - - "LLB8:\n" - "movl (%1),%%ecx\n" - "movl (%2,%1),%%ebx\n" - "xorl %%ebx, %%ecx\n" - "movl %%ebx, (%1)\n" - "orl %%ecx, %0\n" - - "movl 4(%2,%1),%%ebx\n" - "movl 4(%1),%%ecx\n" - "xorl %%ebx, %%ecx\n" - "movl %%ebx, 4(%1)\n" - "orl %%ecx, %0\n" - - "movl 8(%2,%1),%%ebx\n" - "movl 8(%1),%%ecx\n" - "xorl %%ebx, %%ecx\n" - "movl %%ebx, 8(%1)\n" - "orl %%ecx, %0\n" - - "movl 12(%2,%1),%%ebx\n" - "movl 12(%1),%%ecx\n" - "xorl %%ebx, %%ecx\n" - "movl %%ebx, 12(%1)\n" - "orl %%ecx, %0\n" - - "addl $16, %1\n" - "subl $16, %3\n" - "jnc LLB8\n" - - "LLB7:\n" - "addl $16, %3\n" - "subl $4, %3\n" - "jc LLB2\n" - - "LLB1:\n" - "movl (%2,%1),%%ebx\n" - "movl (%1),%%ecx\n" - "xorl %%ebx, %%ecx\n" - "movl %%ebx, (%1)\n" - "orl %%ecx, %0\n" - "addl $4, %1\n" - "subl $4, %3\n" - "jnc LLB1\n" - - "LLB2:\n" - "addl $4, %3\n" - "jz LLB6\n" - "xorl %%ecx, %%ecx\n" - - "LLB3:\n" - "movb (%2,%1),%%bl\n" - "movb (%1),%%cl\n" - "xorb %%bl,%%cl\n" - "movb %%bl,(%1)\n" - "orl %%ecx, %0\n" - "incl %1\n" - "decl %3\n" - "jnz LLB3\n" - - "LLB6:\n" - : "=m" (differs) - : "r" (foo), "r" (bar), "r" (len), "b" (baz), "c" (uupzuq) : "cc", "memory"); - /* Now tell the compiler that foo, bar and len have been modified - * If someone finds a way to express all this cleaner in constraints that - * GCC 2.7.2 understands, please FIXME */ - __asm__ __volatile__ ("" : "=rm" (foo), "=rm" (bar), "=rm" (len) : : "ebx", "ecx", "edx", "eax", "esi", "memory"); +#ifdef __cplusplus +static RETSIGTYPE illhandler(...) +#else +static RETSIGTYPE illhandler(int foo) +#endif +{ + rpt_available = 0; + longjmp(catch_test,1); +} - return differs; +void machdep_init (void) +{ + rpt_available = 1; + write_log ("Testing the RDTSC instruction ... "); + signal (SIGILL, illhandler); + if (setjmp (catch_test) == 0) + read_processor_time (); + signal (SIGILL, SIG_DFL); + write_log ("done.\n"); + if (! rpt_available) { + write_log ("Your processor does not support the RDTSC instruction.\n"); + return; + } + write_log ("Calibrating delay loop.. "); + fflush (stderr); + best_time = (frame_time_t)-1; + loops_to_go = 5; + signal (SIGALRM, alarmhandler); + /* We want exact values... */ + sync (); sync (); sync (); + last_time = read_processor_time(); + set_alarm (); + while (loops_to_go != 0) + usleep (10000); + write_log ("ok - %.2f BogoMIPS\n", + ((double)best_time / TIME_UNIT), best_time); + syncbase = best_time * (1000000 / TIME_UNIT); } + +#endif