|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Miscellaneous machine dependent support functions and definitions
5: *
6: * Copyright 1996 Bernd Schmidt
7: */
8:
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12:
13: #include "config.h"
14: #include "options.h"
15: #include "machdep/m68k.h"
16:
1.1.1.2 ! root 17: #ifndef USE_UNDERSCORE
! 18: #define LARGE_ALIGNMENT ".align 16\n"
! 19: #else
! 20: #define LARGE_ALIGNMENT ".align 4,0x90\n"
! 21: #endif
! 22:
1.1 root 23: struct flag_struct regflags;
24:
25: /*
26: * Careful: No unique labels. Unfortunately, not each installation of GCC
27: * comes with GAS. Bletch.
28: */
29:
30: int fast_memcmp(const void *foo, const void *bar, int len)
31: {
32: int differs, baz;
33: __asm__ __volatile__ ("subl $4, %2\n"
34: "jc LLA2\n"
35: "LLA1:\n"
36: "movl (%0),%%ebx\n"
37: "cmpl (%1),%%ebx\n"
38: "jne LLA5\n"
39: "addl $4, %0\n"
40: "addl $4, %1\n"
41: "subl $4, %2\n"
42: "jnc LLA1\n"
43: "LLA2:\n"
44: "addl $4, %2\n"
45: "jz LLA4\n"
46: "LLA3:\n"
47: "movb (%0),%%bl\n"
48: "cmpb (%1),%%bl\n"
49: "jne LLA5\n"
50: "incl %0\n"
51: "incl %1\n"
52: "decl %2\n"
53: "jnz LLA3\n"
54: "LLA4:\n"
55: "movl $0, %3\n"
56: "jmp LLA6\n"
57: "LLA5:\n"
58: "movl $1, %3\n"
59: "LLA6:\n"
60: : "=&r" (foo), "=&r" (bar), "=&rm" (len), "=rm" (differs),
61: "=&b" (baz)
62: : "0" (foo), "1" (bar), "2" (len), "3" (baz) : "cc");
63: return differs;
64: }
65:
66: int memcmpy(void *foo, const void *bar, int len)
67: {
1.1.1.2 ! root 68: int differs = 0, baz = 0, uupzuq = 0;
1.1 root 69:
70: __asm__ __volatile__ ("subl %1, %2\n"
71: "subl $16, %3\n"
72: "jc LLB7\n"
1.1.1.2 ! root 73: LARGE_ALIGNMENT
1.1 root 74: "LLB8:\n"
75: "movl (%2,%1),%%ebx\n"
1.1.1.2 ! root 76: "movl (%1),%%ecx\n"
! 77: "cmpl %%ebx, %%ecx\n"
! 78: "jne LLC1\n"
1.1 root 79:
80: "movl 4(%2,%1),%%ebx\n"
81: "movl 4(%1),%%ecx\n"
1.1.1.2 ! root 82: "cmpl %%ebx, %%ecx\n"
! 83: "jne LLC2\n"
1.1 root 84:
85: "movl 8(%2,%1),%%ebx\n"
86: "movl 8(%1),%%ecx\n"
1.1.1.2 ! root 87: "cmpl %%ebx, %%ecx\n"
! 88: "jne LLC3\n"
1.1 root 89:
90: "movl 12(%2,%1),%%ebx\n"
91: "movl 12(%1),%%ecx\n"
1.1.1.2 ! root 92: "cmpl %%ebx, %%ecx\n"
! 93: "jne LLC4\n"
1.1 root 94:
95: "addl $16, %1\n"
96: "subl $16, %3\n"
97: "jnc LLB8\n"
98:
99: "LLB7:\n"
100: "addl $16, %3\n"
101: "subl $4, %3\n"
102: "jc LLB2\n"
1.1.1.2 ! root 103:
1.1 root 104: "LLB1:\n"
105: "movl (%2,%1),%%ebx\n"
106: "movl (%1),%%ecx\n"
1.1.1.2 ! root 107: "cmpl %%ebx, %%ecx\n"
! 108: "jne LLC5\n"
1.1 root 109: "addl $4, %1\n"
110: "subl $4, %3\n"
111: "jnc LLB1\n"
112:
113: "LLB2:\n"
114: "addl $4, %3\n"
1.1.1.2 ! root 115: "jz LLB9\n"
1.1 root 116:
117: "LLB3:\n"
118: "movb (%2,%1),%%bl\n"
119: "movb (%1),%%cl\n"
1.1.1.2 ! root 120: "cmpb %%bl,%%cl\n"
! 121: "jne LLC6\n"
1.1 root 122: "incl %1\n"
123: "decl %3\n"
124: "jnz LLB3\n"
125:
1.1.1.2 ! root 126: "jmp LLB9\n"
! 127:
! 128: LARGE_ALIGNMENT
! 129: /* Once we find a difference, we switch to plain memcpy() */
! 130: "LLC01:\n"
! 131: "movl (%2,%1),%%ebx\n"
! 132: "LLC1:\n"
! 133: "movl %%ebx, (%1)\n"
! 134:
! 135: "movl 4(%2,%1),%%ebx\n"
! 136: "LLC2:\n"
! 137: "movl %%ebx, 4(%1)\n"
! 138:
! 139: "movl 8(%2,%1),%%ebx\n"
! 140: "LLC3:\n"
! 141: "movl %%ebx, 8(%1)\n"
! 142:
! 143: "movl 12(%2,%1),%%ebx\n"
! 144: "LLC4:\n"
! 145: "movl %%ebx, 12(%1)\n"
! 146:
! 147: "addl $16, %1\n"
! 148: #if 0
! 149: "movl $1,%0\n"
! 150:
! 151: "addl %1,%2\n"
! 152: "movl %3,%%ecx\n"
! 153: "shrl $2,%%ecx\n"
! 154: "je LLC02a\n"
! 155: "rep\n"
! 156: "movsl\n"
! 157: "andl $3,%3\n"
! 158: "je LLB9\n"
! 159: "LLC02a:\n"
! 160: "movb (%2),%%bl\n"
! 161:
! 162: "movb %%bl,(%1)\n"
! 163: "incl %1\n"
! 164: "decl %3\n"
! 165: "jnz LLC02a\n"
! 166: "jmp LLB9\n"
! 167: #else
! 168: #if 0
! 169: "movl $1,%0\n"
! 170: "jnc LLB8\n"
! 171: #else
! 172: "subl $16, %3\n"
! 173: "jnc LLC01\n"
! 174: #endif
! 175:
! 176: "addl $16, %3\n"
! 177: "subl $4, %3\n"
! 178: "jc LLC03\n"
! 179: #endif
! 180:
! 181: "LLC02:\n"
! 182: "movl (%2,%1),%%ebx\n"
! 183: "LLC5:\n"
! 184: "movl %%ebx, (%1)\n"
! 185: "addl $4, %1\n"
! 186: "subl $4, %3\n"
! 187: "jnc LLC02\n"
! 188:
! 189: "LLC03:\n"
! 190: "addl $4, %3\n"
! 191: "jz LLC05\n"
! 192:
! 193: "LLC04:\n"
! 194: "movb (%2,%1),%%bl\n"
! 195: "LLC6:\n"
! 196: "movb %%bl,(%1)\n"
! 197: "incl %1\n"
! 198: "decl %3\n"
! 199: "jnz LLC04\n"
! 200:
! 201: "LLC05:\n"
! 202: "movl $1,%0\n"
! 203: "LLB9:"
1.1 root 204: : "=m" (differs)
1.1.1.2 ! root 205: : "D" (foo), "S" (bar), "r" (len), "b" (baz), "c" (uupzuq), "0" (differs) : "cc", "memory");
1.1 root 206: /* Now tell the compiler that foo, bar and len have been modified
207: * If someone finds a way to express all this cleaner in constraints that
208: * GCC 2.7.2 understands, please FIXME */
209: __asm__ __volatile__ ("" : "=rm" (foo), "=rm" (bar), "=rm" (len) : : "ebx", "ecx", "edx", "eax", "esi", "memory");
210:
211: return differs;
212: }
1.1.1.2 ! root 213:
! 214: #ifdef HAVE_RDTSC
! 215:
! 216: #include <signal.h>
! 217:
! 218: static volatile frame_time_t last_time, best_time;
! 219: static volatile int loops_to_go;
! 220:
! 221: #ifdef __cplusplus
! 222: static RETSIGTYPE alarmhandler(...)
! 223: #else
! 224: static RETSIGTYPE alarmhandler(int foo)
! 225: #endif
! 226: {
! 227: frame_time_t bar;
! 228: bar = read_processor_time ();
! 229: if (bar - last_time < best_time)
! 230: best_time = bar - last_time;
! 231: if (--loops_to_go > 0) {
! 232: signal (SIGALRM, alarmhandler);
! 233: last_time = read_processor_time();
! 234: alarm (1);
! 235: }
! 236: }
! 237:
! 238: void machdep_init (void)
! 239: {
! 240: fprintf(stderr, "Calibrating delay loop.. ");
! 241: fflush(stderr);
! 242: best_time = (frame_time_t)-1;
! 243: loops_to_go = 5;
! 244: signal (SIGALRM, alarmhandler);
! 245: /* We want exact values... */
! 246: sync (); sync (); sync ();
! 247: last_time = read_processor_time();
! 248: alarm (1);
! 249: while (loops_to_go != 0)
! 250: usleep(1000000);
! 251: fprintf (stderr, "ok - %.2f BogoMIPS\n",
! 252: ((double)best_time / 1000000), best_time);
! 253: vsynctime = best_time / 50;
! 254: }
! 255:
! 256: #else
! 257:
! 258: void machdep_init (void)
! 259: {
! 260: }
! 261:
! 262: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.