src/osd/sdl/osd_cpu.h
| r1217 | r1218 | |
| 55 | 55 | #define MUL_64_32_32(A,B) ((A)*(INT64)(B)) |
| 56 | 56 | #define MUL_U64_U32_U32(A,B) ((A)*(UINT64)(UINT32)(B)) |
| 57 | 57 | |
| 58 | | |
| 59 | | /*************************************************************************** |
| 60 | | |
| 61 | | Inline math helpers |
| 62 | | |
| 63 | | ***************************************************************************/ |
| 64 | | |
| 65 | | #ifdef __GNUC__ |
| 66 | | |
| 67 | | #if defined(__i386__) || defined(__x86_64__) |
| 68 | | |
| 69 | | INLINE UINT32 _count_leading_zeros(UINT32 value) |
| 70 | | { |
| 71 | | UINT32 result; |
| 72 | | |
| 73 | | __asm__ ( |
| 74 | | "bsrl %1,%0;" |
| 75 | | "xorl $31,%0;" |
| 76 | | : "=r,r" (result) /* result can be in any register */ |
| 77 | | : "r,m" (value) /* 'value' can be register or memory */ |
| 78 | | : "%cc" /* clobbers condition codes */ |
| 79 | | ); |
| 80 | | |
| 81 | | return result; |
| 82 | | } |
| 83 | | #define count_leading_zeros _count_leading_zeros |
| 84 | | |
| 85 | | INLINE UINT32 _count_leading_ones(UINT32 value) |
| 86 | | { |
| 87 | | UINT32 result; |
| 88 | | |
| 89 | | __asm__ ( |
| 90 | | "notl %1;" |
| 91 | | "bsrl %1,%0;" |
| 92 | | "notl %1;" |
| 93 | | "xorl $31,%0;" |
| 94 | | : "=r,r" (result) /* result can be in any register */ |
| 95 | | : "r,m" (value) /* 'value' can be register or memory */ |
| 96 | | : "%cc" /* clobbers condition codes */ |
| 97 | | ); |
| 98 | | |
| 99 | | return result; |
| 100 | | } |
| 101 | | #define count_leading_ones _count_leading_ones |
| 102 | | |
| 103 | | INLINE INT32 _fixed_mul_shift(INT32 val1, INT32 val2, UINT8 shift) |
| 104 | | { |
| 105 | | INT32 result; |
| 106 | | |
| 107 | | __asm__ ( |
| 108 | | "imull %2;" |
| 109 | | "shrdl %3,%%edx,%0;" |
| 110 | | : "=a,a,a,a" (result) /* result ends up in eax */ |
| 111 | | : "0,0,0,0" (val1), /* 'val1' should also be in eax on entry */ |
| 112 | | "r,m,r,m" (val2), /* 'val2' can be memory or register */ |
| 113 | | "I,I,c,c" (shift) /* 'shift' must be constant in 0-31 range or in CL */ |
| 114 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 115 | | ); |
| 116 | | |
| 117 | | return result; |
| 118 | | } |
| 119 | | #define fixed_mul_shift _fixed_mul_shift |
| 120 | | |
| 121 | | #elif defined(__ppc__) || defined(__ppc64__) || defined(__PPC__) || defined(__PPC64__) |
| 122 | | |
| 123 | | INLINE UINT32 _count_leading_zeros(UINT32 value) |
| 124 | | { |
| 125 | | UINT32 result; |
| 126 | | |
| 127 | | __asm__ ( |
| 128 | | " cntlzw %0,%1 \n" |
| 129 | | : "=r" (result) /* result can be in any register */ |
| 130 | | : "r" (value) /* 'value' can be in any register */ |
| 131 | | ); |
| 132 | | |
| 133 | | return result; |
| 134 | | } |
| 135 | | #define count_leading_zeros _count_leading_zeros |
| 136 | | |
| 137 | | INLINE UINT32 _count_leading_ones(UINT32 value) |
| 138 | | { |
| 139 | | UINT32 result; |
| 140 | | |
| 141 | | __asm__ ( |
| 142 | | " not %0,%1 \n" |
| 143 | | " cntlzw %0,%0 \n" |
| 144 | | : "=r" (result) /* result can be in any register */ |
| 145 | | : "r" (value) /* 'value' can be in any register */ |
| 146 | | ); |
| 147 | | |
| 148 | | return result; |
| 149 | | } |
| 150 | | #define count_leading_ones _count_leading_ones |
| 151 | | |
| 152 | | #if defined(__ppc64__) || defined(__PPC64__) |
| 153 | | |
| 154 | | INLINE INT32 _fixed_mul_shift(INT32 val1, INT32 val2, UINT8 shift) |
| 155 | | { |
| 156 | | INT32 result; |
| 157 | | |
| 158 | | __asm__ ( |
| 159 | | " mulld %0,%1,%2 \n" |
| 160 | | " srd %0,%0,%3 \n" |
| 161 | | : "=&r" (result) /* result can go in any register */ |
| 162 | | : "%r" (val1) /* any register, can swap with val2 */ |
| 163 | | "r" (val2) /* any register */ |
| 164 | | "r" (shift) /* any register */ |
| 165 | | ); |
| 166 | | |
| 167 | | return result; |
| 168 | | } |
| 169 | | #define fixed_mul_shift _fixed_mul_shift |
| 170 | | |
| 171 | | #else |
| 172 | | |
| 173 | | INLINE INT32 _fixed_mul_shift(INT32 val1, INT32 val2, UINT8 shift) |
| 174 | | { |
| 175 | | INT32 result; |
| 176 | | |
| 177 | | __asm__ ( |
| 178 | | " mullw %0,%2,%3 \n" |
| 179 | | " mulhw %2,%2,%3 \n" |
| 180 | | " srw %0,%0,%1 \n" |
| 181 | | " subfic %1,%1,0x20 \n" |
| 182 | | " slw %2,%2,%1 \n" |
| 183 | | " or %0,%0,%2 \n" |
| 184 | | : "=&r" (result), |
| 185 | | "+r" (shift), |
| 186 | | "+r" (val1) |
| 187 | | : "r" (val2) |
| 188 | | : "xer" |
| 189 | | ); |
| 190 | | |
| 191 | | return result; |
| 192 | | } |
| 193 | | #define fixed_mul_shift _fixed_mul_shift |
| 194 | | |
| 195 | | #endif |
| 196 | | |
| 197 | | #endif |
| 198 | | |
| 199 | | #endif |
| 200 | | |
| 201 | | |
| 202 | 58 | #endif /* defined OSD_CPU_H */ |
src/osd/sdl/sdlsync.c
| r1217 | r1218 | |
| 39 | 39 | #include "mame.h" |
| 40 | 40 | #include "sdlsync.h" |
| 41 | 41 | |
| 42 | #include "eminline.h" |
| 43 | |
| 42 | 44 | #ifndef SDLMAME_OS2 |
| 43 | 45 | #include <pthread.h> |
| 44 | 46 | #include <errno.h> |
| r1217 | r1218 | |
| 70 | 72 | pthread_t thread; |
| 71 | 73 | }; |
| 72 | 74 | |
| 73 | | static osd_lock *atomic_lck = NULL; |
| 74 | | |
| 75 | 75 | INLINE pthread_t osd_compare_exchange_pthread_t(pthread_t volatile *ptr, pthread_t compare, pthread_t exchange) |
| 76 | 76 | { |
| 77 | 77 | #ifdef PTR64 |
| 78 | | INT64 result = osd_compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange); |
| 78 | INT64 result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange); |
| 79 | 79 | #else |
| 80 | | INT32 result = osd_compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange); |
| 80 | INT32 result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange); |
| 81 | 81 | #endif |
| 82 | 82 | return (pthread_t)result; |
| 83 | 83 | } |
| r1217 | r1218 | |
| 87 | 87 | #ifdef PTR64 |
| 88 | 88 | INT64 result = osd_exchange64((INT64 volatile *)ptr, (INT64)exchange); |
| 89 | 89 | #else |
| 90 | | INT32 result = osd_exchange32((INT32 volatile *)ptr, (INT32)exchange); |
| 90 | INT32 result = atomic_exchange32((INT32 volatile *)ptr, (INT32)exchange); |
| 91 | 91 | #endif |
| 92 | 92 | return (pthread_t)result; |
| 93 | 93 | } |
| r1217 | r1218 | |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | //============================================================ |
| 396 | | // osd_atomic_lock |
| 397 | | //============================================================ |
| 398 | | |
| 399 | | void osd_atomic_lock(void) |
| 400 | | { |
| 401 | | if (!atomic_lck) |
| 402 | | atomic_lck = osd_lock_alloc(); |
| 403 | | osd_lock_acquire(atomic_lck); |
| 404 | | } |
| 405 | | |
| 406 | | //============================================================ |
| 407 | | // osd_atomic_unlock |
| 408 | | //============================================================ |
| 409 | | |
| 410 | | void osd_atomic_unlock(void) |
| 411 | | { |
| 412 | | osd_lock_release(atomic_lck); |
| 413 | | } |
| 414 | | |
| 415 | | //============================================================ |
| 416 | 396 | // osd_thread_create |
| 417 | 397 | //============================================================ |
| 418 | 398 | |
| r1217 | r1218 | |
| 463 | 443 | free(thread); |
| 464 | 444 | } |
| 465 | 445 | |
| 466 | | //============================================================ |
| 467 | | // osd_compare_exchange32 |
| 468 | | //============================================================ |
| 469 | 446 | |
| 470 | | #ifndef osd_compare_exchange32 |
| 471 | | |
| 472 | | INT32 osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange) |
| 473 | | { |
| 474 | | INT32 ret; |
| 475 | | osd_atomic_lock(); |
| 476 | | |
| 477 | | ret = *ptr; |
| 478 | | |
| 479 | | if ( *ptr == compare ) |
| 480 | | { |
| 481 | | *ptr = exchange; |
| 482 | | } |
| 483 | | |
| 484 | | osd_atomic_unlock(); |
| 485 | | return ret; |
| 486 | | } |
| 487 | | |
| 488 | | #endif |
| 489 | | |
| 490 | | //============================================================ |
| 491 | | // osd_compare_exchange64 |
| 492 | | //============================================================ |
| 493 | | |
| 494 | | #ifndef osd_compare_exchange64 |
| 495 | | |
| 496 | | INT64 osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange) |
| 497 | | { |
| 498 | | INT64 ret; |
| 499 | | osd_atomic_lock(); |
| 500 | | |
| 501 | | ret = *ptr; |
| 502 | | |
| 503 | | if ( *ptr == compare ) |
| 504 | | { |
| 505 | | *ptr = exchange; |
| 506 | | } |
| 507 | | |
| 508 | | osd_atomic_unlock(); |
| 509 | | return ret; |
| 510 | | } |
| 511 | | |
| 512 | | #endif |
| 513 | | |
| 514 | 447 | #else // SDLMAME_OS2 |
| 515 | 448 | |
| 449 | |
| 516 | 450 | struct _osd_lock |
| 517 | 451 | { |
| 518 | 452 | HMTX hmtx; |
src/osd/sdl/osinline.h
| r1217 | r1218 | |
| 7 | 7 | #ifndef __OSINLINE__ |
| 8 | 8 | #define __OSINLINE__ |
| 9 | 9 | |
| 10 | | #include "osd_cpu.h" |
| 10 | #include "eminline.h" |
| 11 | 11 | |
| 12 | |
| 12 | 13 | //============================================================ |
| 13 | 14 | // INLINE FUNCTIONS |
| 14 | 15 | //============================================================ |
| 15 | 16 | |
| 16 | | //#define YieldProcessor() sched_yield() |
| 17 | | //#define YieldProcessor() do {} while (0) |
| 18 | | |
| 19 | | #ifndef YieldProcessor |
| 20 | | |
| 21 | 17 | #if defined(__i386__) || defined(__x86_64__) |
| 22 | 18 | |
| 19 | |
| 23 | 20 | INLINE void osd_yield_processor(void) |
| 24 | 21 | { |
| 25 | 22 | __asm__ __volatile__ ( " rep ; nop ;" ); |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | | #elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) |
| 29 | 25 | |
| 30 | | INLINE void osd_yield_processor(void) |
| 31 | | { |
| 32 | | __asm__ __volatile__ ( " nop \n" ); |
| 33 | | } |
| 34 | | |
| 35 | | #endif |
| 36 | | |
| 37 | | #else |
| 38 | | #define osd_yield_processor() YieldProcessor() |
| 39 | | #endif |
| 40 | | |
| 41 | | #ifdef __GNUC__ |
| 42 | | |
| 43 | | #if defined(__i386__) || defined(__x86_64__) |
| 44 | | |
| 45 | | |
| 46 | 26 | //============================================================ |
| 47 | | // osd_compare_exchange32 |
| 48 | | //============================================================ |
| 49 | | #ifndef SDLMAME_WIN32 |
| 50 | | ATTR_UNUSED |
| 51 | | INLINE INT32 _osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange) |
| 52 | | { |
| 53 | | register INT32 ret; |
| 54 | | __asm__ __volatile__ ( |
| 55 | | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 56 | | : [ptr] "+m" (*ptr) |
| 57 | | , [ret] "=a" (ret) |
| 58 | | : [compare] "1" (compare) |
| 59 | | , [exchange] "q" (exchange) |
| 60 | | : "%cc" |
| 61 | | ); |
| 62 | | return ret; |
| 63 | | } |
| 64 | | #define osd_compare_exchange32 _osd_compare_exchange32 |
| 65 | | |
| 66 | | |
| 67 | | //============================================================ |
| 68 | | // osd_exchange32 |
| 69 | | //============================================================ |
| 70 | | |
| 71 | | ATTR_UNUSED |
| 72 | | INLINE INT32 _osd_exchange32(INT32 volatile *ptr, INT32 exchange) |
| 73 | | { |
| 74 | | register INT32 ret; |
| 75 | | __asm__ __volatile__ ( |
| 76 | | " lock ; xchg %[exchange], %[ptr] ;" |
| 77 | | : [ptr] "+m" (*ptr) |
| 78 | | , [ret] "=r" (ret) |
| 79 | | : [exchange] "1" (exchange) |
| 80 | | ); |
| 81 | | return ret; |
| 82 | | } |
| 83 | | #define osd_exchange32 _osd_exchange32 |
| 84 | | #endif |
| 85 | | |
| 86 | | |
| 87 | | //============================================================ |
| 88 | | // osd_sync_add |
| 89 | | //============================================================ |
| 90 | | |
| 91 | | ATTR_UNUSED |
| 92 | | INLINE INT32 _osd_sync_add(INT32 volatile *ptr, INT32 delta) |
| 93 | | { |
| 94 | | register INT32 ret; |
| 95 | | __asm __volatile__ ( |
| 96 | | " mov %[delta],%[ret] ;" |
| 97 | | " lock ; xadd %[ret],%[ptr] ;" |
| 98 | | " add %[delta],%[ret] ;" |
| 99 | | : [ptr] "+m" (*ptr) |
| 100 | | , [ret] "=&r" (ret) |
| 101 | | : [delta] "rmi" (delta) |
| 102 | | : "%cc" |
| 103 | | ); |
| 104 | | return ret; |
| 105 | | } |
| 106 | | #define osd_sync_add _osd_sync_add |
| 107 | | |
| 108 | | |
| 109 | | //============================================================ |
| 110 | 27 | // osd_interlocked_increment |
| 111 | 28 | //============================================================ |
| 112 | 29 | |
| r1217 | r1218 | |
| 153 | 70 | #if defined(__x86_64__) |
| 154 | 71 | |
| 155 | 72 | //============================================================ |
| 156 | | // osd_compare_exchange64 |
| 157 | | //============================================================ |
| 158 | | |
| 159 | | ATTR_UNUSED |
| 160 | | INLINE INT64 _osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange) |
| 161 | | { |
| 162 | | register INT64 ret; |
| 163 | | __asm__ __volatile__ ( |
| 164 | | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 165 | | : [ptr] "+m" (*ptr) |
| 166 | | , [ret] "=a" (ret) |
| 167 | | : [compare] "1" (compare) |
| 168 | | , [exchange] "q" (exchange) |
| 169 | | : "%cc" |
| 170 | | ); |
| 171 | | return ret; |
| 172 | | } |
| 173 | | #define osd_compare_exchange64 _osd_compare_exchange64 |
| 174 | | |
| 175 | | |
| 176 | | //============================================================ |
| 177 | 73 | // osd_exchange64 |
| 178 | 74 | //============================================================ |
| 179 | 75 | |
| r1217 | r1218 | |
| 194 | 90 | #endif /* __x86_64__ */ |
| 195 | 91 | |
| 196 | 92 | |
| 197 | | #elif defined(__ppc__) || defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__) |
| 93 | #elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__) |
| 198 | 94 | |
| 199 | 95 | |
| 200 | | //============================================================ |
| 201 | | // osd_compare_exchange32 |
| 202 | | //============================================================ |
| 203 | | |
| 204 | | ATTR_UNUSED |
| 205 | | INLINE INT32 _osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange) |
| 96 | INLINE void osd_yield_processor(void) |
| 206 | 97 | { |
| 207 | | register INT32 ret; |
| 208 | | __asm__ __volatile__ ( |
| 209 | | "1: lwarx %[ret], 0, %[ptr] \n" |
| 210 | | " cmpw %[compare], %[ret] \n" |
| 211 | | " bne 2f \n" |
| 212 | | " sync \n" |
| 213 | | " stwcx. %[exchange], 0, %[ptr] \n" |
| 214 | | " bne- 1b \n" |
| 215 | | "2: " |
| 216 | | : [ret] "=&r" (ret) |
| 217 | | : [ptr] "r" (ptr) |
| 218 | | , [exchange] "r" (exchange) |
| 219 | | , [compare] "r" (compare) |
| 220 | | : "cr0" |
| 221 | | ); |
| 222 | | return ret; |
| 98 | __asm__ __volatile__ ( " nop \n nop \n" ); |
| 223 | 99 | } |
| 224 | | #define osd_compare_exchange32 _osd_compare_exchange32 |
| 225 | 100 | |
| 226 | 101 | |
| 227 | 102 | //============================================================ |
| 228 | | // osd_exchange32 |
| 229 | | //============================================================ |
| 230 | | |
| 231 | | ATTR_UNUSED |
| 232 | | INLINE INT32 _osd_exchange32(INT32 volatile *ptr, INT32 exchange) |
| 233 | | { |
| 234 | | register INT32 ret; |
| 235 | | __asm__ __volatile__ ( |
| 236 | | "1: lwarx %[ret], 0, %[ptr] \n" |
| 237 | | " sync \n" |
| 238 | | " stwcx. %[exchange], 0, %[ptr] \n" |
| 239 | | " bne- 1b \n" |
| 240 | | : [ret] "=&r" (ret) |
| 241 | | : [ptr] "r" (ptr) |
| 242 | | , [exchange] "r" (exchange) |
| 243 | | : "cr0" |
| 244 | | ); |
| 245 | | return ret; |
| 246 | | } |
| 247 | | #define osd_exchange32 _osd_exchange32 |
| 248 | | |
| 249 | | |
| 250 | | //============================================================ |
| 251 | | // osd_sync_add |
| 252 | | //============================================================ |
| 253 | | |
| 254 | | ATTR_UNUSED |
| 255 | | INLINE INT32 _osd_sync_add(INT32 volatile *ptr, INT32 delta) |
| 256 | | { |
| 257 | | register INT32 ret; |
| 258 | | __asm __volatile__ ( |
| 259 | | "1: lwarx %[ret], 0, %[ptr] \n" |
| 260 | | " add %[ret], %[ret], %[delta] \n" |
| 261 | | " sync \n" |
| 262 | | " stwcx. %[ret], 0, %[ptr] \n" |
| 263 | | " bne- 1b \n" |
| 264 | | : [ret] "=&b" (ret) |
| 265 | | : [ptr] "r" (ptr) |
| 266 | | , [delta] "r" (delta) |
| 267 | | : "cr0" |
| 268 | | ); |
| 269 | | return ret; |
| 270 | | } |
| 271 | | #define osd_sync_add _osd_sync_add |
| 272 | | |
| 273 | | |
| 274 | | //============================================================ |
| 275 | 103 | // osd_interlocked_increment |
| 276 | 104 | //============================================================ |
| 277 | 105 | |
| r1217 | r1218 | |
| 320 | 148 | #if defined(__ppc64__) || defined(__PPC64__) |
| 321 | 149 | |
| 322 | 150 | //============================================================ |
| 323 | | // osd_compare_exchange64 |
| 324 | | //============================================================ |
| 325 | | |
| 326 | | ATTR_UNUSED |
| 327 | | INLINE INT64 _osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange) |
| 328 | | { |
| 329 | | register INT64 ret; |
| 330 | | __asm__ __volatile__ ( |
| 331 | | "1: ldarx %[ret], 0, %[ptr] \n" |
| 332 | | " cmpd %[compare], %[ret] \n" |
| 333 | | " bne 2f \n" |
| 334 | | " stdcx. %[exchange], 0, %[ptr] \n" |
| 335 | | " bne-- 1b \n" |
| 336 | | "2: " |
| 337 | | : [ret] "=&r" (ret) |
| 338 | | : [ptr] "r" (ptr) |
| 339 | | , [exchange] "r" (exchange) |
| 340 | | , [compare] "r" (compare) |
| 341 | | : "cr0" |
| 342 | | ); |
| 343 | | return ret; |
| 344 | | } |
| 345 | | #define osd_compare_exchange64 _osd_compare_exchange64 |
| 346 | | |
| 347 | | |
| 348 | | //============================================================ |
| 349 | 151 | // osd_exchange64 |
| 350 | 152 | //============================================================ |
| 351 | 153 | |
| r1217 | r1218 | |
| 371 | 173 | |
| 372 | 174 | #endif |
| 373 | 175 | |
| 374 | | #endif /* __GNUC__ */ |
| 375 | | |
| 376 | | |
| 377 | 176 | #endif /* __OSINLINE__ */ |
src/osd/sdl/sdlwork.c
| r1217 | r1218 | |
| 32 | 32 | #endif |
| 33 | 33 | #include "sdlsync.h" |
| 34 | 34 | |
| 35 | #include "eminline.h" |
| 35 | 36 | |
| 37 | |
| 36 | 38 | //============================================================ |
| 37 | 39 | // DEBUGGING |
| 38 | 40 | //============================================================ |
| r1217 | r1218 | |
| 56 | 58 | //============================================================ |
| 57 | 59 | |
| 58 | 60 | #if KEEP_STATISTICS |
| 59 | | #define add_to_stat(v,x) do { osd_interlocked_add((v), (x)); } while (0) |
| 61 | #define add_to_stat(v,x) do { atomic_add32((v), (x)); } while (0) |
| 60 | 62 | #define begin_timing(v) do { (v) -= osd_profiling_ticks(); } while (0) |
| 61 | 63 | #define end_timing(v) do { (v) += osd_profiling_ticks(); } while (0) |
| 62 | 64 | #else |
| r1217 | r1218 | |
| 151 | 153 | // INLINE FUNCTIONS |
| 152 | 154 | //============================================================ |
| 153 | 155 | |
| 154 | | #ifndef osd_exchange32 |
| 155 | | INLINE INT32 osd_exchange32(INT32 volatile *ptr, INT32 exchange) |
| 156 | | { |
| 157 | | INT32 origvalue; |
| 158 | | do { |
| 159 | | origvalue = *ptr; |
| 160 | | } while (osd_compare_exchange32(ptr, origvalue, exchange) != origvalue); |
| 161 | | return origvalue; |
| 162 | | } |
| 163 | | #endif |
| 164 | | |
| 165 | 156 | #ifndef osd_interlocked_increment |
| 166 | 157 | INLINE INT32 osd_interlocked_increment(INT32 volatile *ptr) |
| 167 | 158 | { |
| 168 | | return osd_sync_add(ptr, 1); |
| 159 | return atomic_add32(ptr, 1); |
| 169 | 160 | } |
| 170 | 161 | #endif |
| 171 | 162 | |
| 172 | 163 | #ifndef osd_interlocked_decrement |
| 173 | 164 | INLINE INT32 osd_interlocked_decrement(INT32 volatile *ptr) |
| 174 | 165 | { |
| 175 | | return osd_sync_add(ptr, -1); |
| 166 | return atomic_add32(ptr, -1); |
| 176 | 167 | } |
| 177 | 168 | #endif |
| 178 | 169 | |
| 179 | | #ifndef osd_interlocked_add |
| 180 | | INLINE INT32 osd_interlocked_add(INT32 volatile *ptr, INT32 add) |
| 181 | | { |
| 182 | | return osd_sync_add(ptr, add); |
| 183 | | } |
| 184 | | #endif |
| 185 | | |
| 186 | 170 | INLINE void scalable_lock_init(scalable_lock *lock) |
| 187 | 171 | { |
| 188 | 172 | memset(lock, 0, sizeof(*lock)); |
| r1217 | r1218 | |
| 395 | 379 | |
| 396 | 380 | // reset our done event and double-check the items before waiting |
| 397 | 381 | osd_event_reset(queue->doneevent); |
| 398 | | osd_exchange32(&queue->waiting, TRUE); |
| 382 | atomic_exchange32(&queue->waiting, TRUE); |
| 399 | 383 | if (queue->items != 0) |
| 400 | 384 | osd_event_wait(queue->doneevent, timeout); |
| 401 | | osd_exchange32(&queue->waiting, FALSE); |
| 385 | atomic_exchange32(&queue->waiting, FALSE); |
| 402 | 386 | |
| 403 | 387 | // return TRUE if we actually hit 0 |
| 404 | 388 | return (queue->items == 0); |
| r1217 | r1218 | |
| 520 | 504 | do |
| 521 | 505 | { |
| 522 | 506 | item = (osd_work_item *)queue->free; |
| 523 | | } while (item != NULL && osd_compare_exchange_ptr((void * volatile *)&queue->free, item, item->next) != item); |
| 507 | } while (item != NULL && compare_exchange_ptr((void * volatile *)&queue->free, item, item->next) != item); |
| 524 | 508 | |
| 525 | 509 | // if nothing, allocate something new |
| 526 | 510 | if (item == NULL) |
| r1217 | r1218 | |
| 553 | 537 | scalable_lock_release(&queue->lock, lockslot); |
| 554 | 538 | |
| 555 | 539 | // increment the number of items in the queue |
| 556 | | osd_interlocked_add(&queue->items, numitems); |
| 540 | atomic_add32(&queue->items, numitems); |
| 557 | 541 | add_to_stat(&queue->itemsqueued, numitems); |
| 558 | 542 | |
| 559 | 543 | // look for free threads to do the work |
| r1217 | r1218 | |
| 650 | 634 | { |
| 651 | 635 | next = (osd_work_item *)item->queue->free; |
| 652 | 636 | item->next = next; |
| 653 | | } while (osd_compare_exchange_ptr((void * volatile *)&item->queue->free, next, item) != next); |
| 637 | } while (compare_exchange_ptr((void * volatile *)&item->queue->free, next, item) != next); |
| 654 | 638 | } |
| 655 | 639 | |
| 656 | 640 | |
| r1217 | r1218 | |
| 697 | 681 | break; |
| 698 | 682 | |
| 699 | 683 | // indicate that we are live |
| 700 | | osd_exchange32(&thread->active, TRUE); |
| 684 | atomic_exchange32(&thread->active, TRUE); |
| 701 | 685 | osd_interlocked_increment(&queue->livethreads); |
| 702 | 686 | |
| 703 | 687 | // process work items |
| r1217 | r1218 | |
| 724 | 708 | } |
| 725 | 709 | |
| 726 | 710 | // decrement the live thread count |
| 727 | | osd_exchange32(&thread->active, FALSE); |
| 711 | atomic_exchange32(&thread->active, FALSE); |
| 728 | 712 | osd_interlocked_decrement(&queue->livethreads); |
| 729 | 713 | } |
| 730 | 714 | return NULL; |
src/emu/eigccx86.h
| r1217 | r1218 | |
| 23 | 23 | multiply and return the full 64 bit result |
| 24 | 24 | -------------------------------------------------*/ |
| 25 | 25 | |
| 26 | | #ifndef PTR64 |
| 26 | #ifndef __x86_64__ |
| 27 | 27 | #define mul_32x32 _mul_32x32 |
| 28 | 28 | INLINE INT64 _mul_32x32(INT32 a, INT32 b) |
| 29 | 29 | { |
| 30 | 30 | INT64 result; |
| 31 | 31 | |
| 32 | 32 | __asm__ ( |
| 33 | | "imull %2;" |
| 34 | | : "=A,A" (result) /* result in edx:eax */ |
| 35 | | : "0,0" (a), /* 'a' should also be in eax on entry */ |
| 36 | | "r,m" (b) /* 'b' can be memory or register */ |
| 33 | " imull %[b] ;" |
| 34 | : [result] "=A" (result) /* result in edx:eax */ |
| 35 | : [a] "%a" (a) /* 'a' should also be in eax on entry */ |
| 36 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 37 | : "%cc" /* Clobbers condition codes */ |
| 37 | 38 | ); |
| 38 | 39 | |
| 39 | 40 | return result; |
| r1217 | r1218 | |
| 47 | 48 | result |
| 48 | 49 | -------------------------------------------------*/ |
| 49 | 50 | |
| 50 | | #ifndef PTR64 |
| 51 | #ifndef __x86_64__ |
| 51 | 52 | #define mulu_32x32 _mulu_32x32 |
| 52 | 53 | INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b) |
| 53 | 54 | { |
| 54 | 55 | UINT64 result; |
| 55 | 56 | |
| 56 | 57 | __asm__ ( |
| 57 | | "mull %2;" |
| 58 | | : "=A,A" (result) /* result in edx:eax */ |
| 59 | | : "0,0" (a), /* 'a' should also be in eax on entry */ |
| 60 | | "r,m" (b) /* 'b' can be memory or register */ |
| 58 | " mull %[b] ;" |
| 59 | : [result] "=A" (result) /* result in edx:eax */ |
| 60 | : [a] "%a" (a) /* 'a' should also be in eax on entry */ |
| 61 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 62 | : "%cc" /* Clobbers condition codes */ |
| 61 | 63 | ); |
| 62 | 64 | |
| 63 | 65 | return result; |
| r1217 | r1218 | |
| 71 | 73 | result |
| 72 | 74 | -------------------------------------------------*/ |
| 73 | 75 | |
| 74 | | #ifndef PTR64 |
| 75 | 76 | #define mul_32x32_hi _mul_32x32_hi |
| 76 | 77 | INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b) |
| 77 | 78 | { |
| 78 | 79 | INT32 result; |
| 79 | 80 | |
| 80 | 81 | __asm__ ( |
| 81 | | "imull %2;" |
| 82 | | "movl %%edx,%0;" |
| 83 | | : "=a,a" (result) /* result ends up in eax */ |
| 84 | | : "0,0" (a), /* 'a' should also be in eax on entry */ |
| 85 | | "r,m" (b) /* 'b' can be memory or register */ |
| 86 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 82 | " imull %[b] ;" |
| 83 | : [result] "=d" (result) /* result in edx */ |
| 84 | , [a] "+%a" (a) /* 'a' should be in eax on entry (clobbered) */ |
| 85 | : [b] "rm" (b) /* 'b' can be memory or register */ |
| 86 | : "%cc" /* Clobbers condition codes */ |
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | return result; |
| 90 | 90 | } |
| 91 | | #endif |
| 92 | 91 | |
| 93 | 92 | |
| 94 | 93 | /*------------------------------------------------- |
| r1217 | r1218 | |
| 97 | 96 | of the result |
| 98 | 97 | -------------------------------------------------*/ |
| 99 | 98 | |
| 100 | | #ifndef PTR64 |
| 101 | 99 | #define mulu_32x32_hi _mulu_32x32_hi |
| 102 | 100 | INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b) |
| 103 | 101 | { |
| 104 | 102 | UINT32 result; |
| 105 | 103 | |
| 106 | 104 | __asm__ ( |
| 107 | | "mull %2;" |
| 108 | | "movl %%edx,%0;" |
| 109 | | : "=a,a" (result) /* result ends up in eax */ |
| 110 | | : "0,0" (a), /* 'a' should also be in eax on entry */ |
| 111 | | "r,m" (b) /* 'b' can be memory or register */ |
| 112 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 105 | " mull %[b] ;" |
| 106 | : [result] "=d" (result) /* result in edx */ |
| 107 | , [a] "+%a" (a) /* 'a' should be in eax on entry (clobbered) */ |
| 108 | : [b] "rm" (b) /* 'b' can be memory or register */ |
| 109 | : "%cc" /* Clobbers condition codes */ |
| 113 | 110 | ); |
| 114 | 111 | |
| 115 | 112 | return result; |
| 116 | 113 | } |
| 117 | | #endif |
| 118 | 114 | |
| 119 | 115 | |
| 120 | 116 | /*------------------------------------------------- |
| r1217 | r1218 | |
| 124 | 120 | result to 32 bits |
| 125 | 121 | -------------------------------------------------*/ |
| 126 | 122 | |
| 127 | | #ifndef PTR64 |
| 123 | #ifndef __x86_64__ |
| 128 | 124 | #define mul_32x32_shift _mul_32x32_shift |
| 129 | 125 | INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift) |
| 130 | 126 | { |
| 131 | 127 | INT32 result; |
| 132 | 128 | |
| 133 | 129 | __asm__ ( |
| 134 | | "imull %2;" |
| 135 | | "shrdl %3,%%edx,%0;" |
| 136 | | : "=a,a,a,a" (result) /* result ends up in eax */ |
| 137 | | : "0,0,0,0" (a), /* 'a' should also be in eax on entry */ |
| 138 | | "r,m,r,m" (b), /* 'b' can be memory or register */ |
| 139 | | "I,I,c,c" (shift) /* 'shift' must be constant in 0-31 range or in CL */ |
| 140 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 130 | " imull %[b] ;" |
| 131 | " shrdl %[shift], %%edx, %[result] ;" |
| 132 | : [result] "=a" (result) /* result ends up in eax */ |
| 133 | : [a] "%0" (a) /* 'a' should also be in eax on entry */ |
| 134 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 135 | , [shift] "Ic" (shift) /* 'shift' must be constant in 0-31 range or in cl */ |
| 136 | : "%edx", "%cc" /* clobbers edx and condition codes */ |
| 141 | 137 | ); |
| 142 | 138 | |
| 143 | 139 | return result; |
| r1217 | r1218 | |
| 152 | 148 | result to 32 bits |
| 153 | 149 | -------------------------------------------------*/ |
| 154 | 150 | |
| 155 | | #ifndef PTR64 |
| 151 | #ifndef __x86_64__ |
| 156 | 152 | #define mulu_32x32_shift _mulu_32x32_shift |
| 157 | 153 | INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift) |
| 158 | 154 | { |
| 159 | 155 | UINT32 result; |
| 160 | 156 | |
| 161 | 157 | __asm__ ( |
| 162 | | "imull %2;" |
| 163 | | "shrdl %3,%%edx,%0;" |
| 164 | | : "=a,a,a,a" (result) /* result ends up in eax */ |
| 165 | | : "0,0,0,0" (a), /* 'a' should also be in eax on entry */ |
| 166 | | "r,m,r,m" (b), /* 'b' can be memory or register */ |
| 167 | | "I,I,c,c" (shift) /* 'shift' must be constant in 0-31 range or in CL */ |
| 168 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 158 | " mull %[b] ;" |
| 159 | " shrdl %[shift], %%edx, %[result] ;" |
| 160 | : [result] "=a" (result) /* result ends up in eax */ |
| 161 | : [a] "%0" (a) /* 'a' should also be in eax on entry */ |
| 162 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 163 | , [shift] "Ic" (shift) /* 'shift' must be constant in 0-31 range or in cl */ |
| 164 | : "%edx", "%cc" /* clobbers edx and condition codes */ |
| 169 | 165 | ); |
| 170 | 166 | |
| 171 | 167 | return result; |
| r1217 | r1218 | |
| 195 | 191 | division, and returning the 32 bit quotient |
| 196 | 192 | -------------------------------------------------*/ |
| 197 | 193 | |
| 198 | | #ifndef PTR64 |
| 199 | | /* TBD - I get an error if this is enabled: error: 'asm' operand requires impossible reload */ |
| 200 | | #if 0 |
| 194 | #ifndef __x86_64__ |
| 201 | 195 | #define div_32x32_shift _div_32x32_shift |
| 202 | 196 | INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift) |
| 203 | 197 | { |
| 204 | 198 | INT32 result; |
| 205 | 199 | |
| 206 | 200 | __asm__ ( |
| 207 | | "cdq;" |
| 208 | | "shldl %3,%0,%%edx;" |
| 209 | | "shll %3,%0;" |
| 210 | | "idivl %2;" |
| 211 | | : "=a,a,a,a" (result) /* result ends up in eax */ |
| 212 | | : "0,0,0,0" (a), /* 'a' should also be in eax on entry */ |
| 213 | | "r,m,r,m" (b), /* 'b' can be memory or register */ |
| 214 | | "I,I,c,c" (shift) /* 'shift' must be constant in 0-31 range or in CL */ |
| 215 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 201 | " cdq ;" |
| 202 | " shldl %[shift], %[a], %%edx ;" |
| 203 | " shll %[shift], %[a] ;" |
| 204 | " idivl %[b] ;" |
| 205 | : [result] "=&a" (result) /* result ends up in eax */ |
| 206 | : [a] "0" (a) /* 'a' should also be in eax on entry */ |
| 207 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 208 | , [shift] "Ic" (shift) /* 'shift' must be constant in 0-31 range or in cl */ |
| 209 | : "%edx", "%cc" /* clobbers edx and condition codes */ |
| 216 | 210 | ); |
| 217 | 211 | |
| 218 | 212 | return result; |
| 219 | 213 | } |
| 220 | 214 | #endif |
| 221 | | #endif |
| 222 | 215 | |
| 223 | 216 | |
| 224 | 217 | /*------------------------------------------------- |
| r1217 | r1218 | |
| 227 | 220 | division, and returning the 32 bit quotient |
| 228 | 221 | -------------------------------------------------*/ |
| 229 | 222 | |
| 230 | | #ifndef PTR64 |
| 223 | #ifndef __x86_64__ |
| 231 | 224 | #define divu_32x32_shift _divu_32x32_shift |
| 232 | 225 | INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift) |
| 233 | 226 | { |
| 234 | 227 | INT32 result; |
| 235 | 228 | |
| 236 | 229 | __asm__ ( |
| 237 | | "xorl %%edx,%%edx;" |
| 238 | | "shldl %3,%0,%%edx;" |
| 239 | | "shll %3,%0;" |
| 240 | | "divl %2;" |
| 241 | | : "=a,a,a,a" (result) /* result ends up in eax */ |
| 242 | | : "0,0,0,0" (a), /* 'a' should also be in eax on entry */ |
| 243 | | "r,m,r,m" (b), /* 'b' can be memory or register */ |
| 244 | | "I,I,c,c" (shift) /* 'shift' must be constant in 0-31 range or in CL */ |
| 245 | | : "%edx", "%cc" /* clobbers EDX and condition codes */ |
| 230 | " clr %%edx ;" |
| 231 | " shldl %[shift], %[a], %%edx ;" |
| 232 | " shll %[shift], %[a] ;" |
| 233 | " divl %[b] ;" |
| 234 | : [result] "=&a" (result) /* result ends up in eax */ |
| 235 | : [a] "0" (a) /* 'a' should also be in eax on entry */ |
| 236 | , [b] "rm" (b) /* 'b' can be memory or register */ |
| 237 | , [shift] "Ic" (shift) /* 'shift' must be constant in 0-31 range or in cl */ |
| 238 | : "%edx", "%cc" /* clobbers edx and condition codes */ |
| 246 | 239 | ); |
| 247 | 240 | |
| 248 | 241 | return result; |
| r1217 | r1218 | |
| 290 | 283 | UINT32 result; |
| 291 | 284 | |
| 292 | 285 | __asm__ ( |
| 293 | | "bsrl %1,%0;" |
| 294 | | "jnz 1f;" |
| 295 | | "movl $63,%0;" |
| 296 | | "1:xorl $31,%0;" |
| 297 | | : "=r,r" (result) /* result can be in any register */ |
| 298 | | : "r,m" (value) /* 'value' can be register or memory */ |
| 299 | | : "%cc" /* clobbers condition codes */ |
| 286 | " bsrl %[value], %[result] ;" |
| 287 | " jnz 1f ;" |
| 288 | " movl $63, %[result] ;" |
| 289 | "1: xorl $31, %[result] ;" |
| 290 | : [result] "=r" (result) /* result can be in any register */ |
| 291 | : [value] "rm" (value) /* 'value' can be register or memory */ |
| 292 | : "%cc" /* clobbers condition codes */ |
| 300 | 293 | ); |
| 301 | 294 | |
| 302 | 295 | return result; |
| r1217 | r1218 | |
| 314 | 307 | UINT32 result; |
| 315 | 308 | |
| 316 | 309 | __asm__ ( |
| 317 | | "movl %1,%0;" |
| 318 | | "notl %0;" |
| 319 | | "bsrl %0,%0;" |
| 320 | | "jnz 1f;" |
| 321 | | "movl $63,%0;" |
| 322 | | "1:xorl $31,%0;" |
| 323 | | : "=r,r" (result) /* result can be in any register */ |
| 324 | | : "r,m" (value) /* 'value' can be register or memory */ |
| 325 | | : "%cc" /* clobbers condition codes */ |
| 310 | " movl %[value], %[result] ;" |
| 311 | " notl %[result] ;" |
| 312 | " bsrl %[result], %[result] ;" |
| 313 | " jnz 1f ;" |
| 314 | " movl $63, %[result] ;" |
| 315 | "1: xorl $31, %[result] ;" |
| 316 | : [result] "=r" (result) /* result can be in any register */ |
| 317 | : [value] "rmi" (value) /* 'value' can be register, memory or immediate */ |
| 318 | : "%cc" /* clobbers condition codes */ |
| 326 | 319 | ); |
| 327 | 320 | |
| 328 | 321 | return result; |
| r1217 | r1218 | |
| 347 | 340 | register INT32 result; |
| 348 | 341 | |
| 349 | 342 | __asm__ __volatile__ ( |
| 350 | | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 343 | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 351 | 344 | : [ptr] "+m" (*ptr) |
| 352 | 345 | , [result] "=a" (result) |
| 353 | 346 | : [compare] "1" (compare) |
| r1217 | r1218 | |
| 366 | 359 | return the previous value at 'ptr'. |
| 367 | 360 | -------------------------------------------------*/ |
| 368 | 361 | |
| 369 | | #ifdef PTR64 |
| 362 | #ifdef __x86_64__ |
| 370 | 363 | #define compare_exchange64 _compare_exchange64 |
| 371 | 364 | INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange) |
| 372 | 365 | { |
| 373 | 366 | register INT64 result; |
| 374 | 367 | |
| 375 | 368 | __asm__ __volatile__ ( |
| 376 | | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 369 | " lock ; cmpxchg %[exchange], %[ptr] ;" |
| 377 | 370 | : [ptr] "+m" (*ptr) |
| 378 | 371 | , [result] "=a" (result) |
| 379 | 372 | : [compare] "1" (compare) |
| r1217 | r1218 | |
| 398 | 391 | register INT32 result; |
| 399 | 392 | |
| 400 | 393 | __asm__ __volatile__ ( |
| 401 | | " lock ; xchg %[exchange], %[ptr] ;" |
| 394 | " lock ; xchg %[exchange], %[ptr] ;" |
| 402 | 395 | : [ptr] "+m" (*ptr) |
| 403 | 396 | , [result] "=r" (result) |
| 404 | 397 | : [exchange] "1" (exchange) |
| r1217 | r1218 | |
| 419 | 412 | { |
| 420 | 413 | register INT32 result; |
| 421 | 414 | |
| 422 | | __asm __volatile__ ( |
| 423 | | " mov %[delta],%[result] ;" |
| 424 | | " lock ; xadd %[result],%[ptr] ;" |
| 425 | | " add %[delta],%[result] ;" |
| 415 | __asm__ __volatile__ ( |
| 416 | " mov %[delta],%[result] ;" |
| 417 | " lock ; xadd %[result],%[ptr] ;" |
| 418 | " add %[delta],%[result] ;" |
| 426 | 419 | : [ptr] "+m" (*ptr) |
| 427 | 420 | , [result] "=&r" (result) |
| 428 | 421 | : [delta] "rmi" (delta) |
src/emu/eigccppc.h
| r1217 | r1218 | |
| 42 | 42 | -------------------------------------------------*/ |
| 43 | 43 | |
| 44 | 44 | #define mul_32x32_hi _mul_32x32_hi |
| 45 | | INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b) |
| 45 | INLINE INT32 _mul_32x32_hi(INT32 val1, INT32 val2) |
| 46 | 46 | { |
| 47 | 47 | INT32 result; |
| 48 | 48 | |
| 49 | 49 | __asm__ ( |
| 50 | | " mulhw %0,%1,%2 \n" |
| 51 | | : "=&r" (result), |
| 52 | | "+r" (val1) |
| 53 | | : "r" (val2) |
| 54 | | : "xer" |
| 50 | " mulhw %[result], %[val1], %[val2] \n" |
| 51 | : [result] "=r" (result) |
| 52 | : [val1] "%r" (val1) |
| 53 | , [val2] "r" (val2) |
| 55 | 54 | ); |
| 56 | 55 | |
| 57 | 56 | return result; |
| r1217 | r1218 | |
| 65 | 64 | -------------------------------------------------*/ |
| 66 | 65 | |
| 67 | 66 | #define mulu_32x32_hi _mulu_32x32_hi |
| 68 | | INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b) |
| 67 | INLINE UINT32 _mulu_32x32_hi(UINT32 val1, UINT32 val2) |
| 69 | 68 | { |
| 70 | 69 | UINT32 result; |
| 71 | 70 | |
| 72 | 71 | __asm__ ( |
| 73 | | " mulhwu %0,%1,%2 \n" |
| 74 | | : "=&r" (result), |
| 75 | | "+r" (val1) |
| 76 | | : "r" (val2) |
| 77 | | : "xer" |
| 72 | " mulhwu %[result], %[val1], %[val2] \n" |
| 73 | : [result] "=r" (result) |
| 74 | : [val1] "%r" (val1) |
| 75 | , [val2] "r" (val2) |
| 78 | 76 | ); |
| 79 | 77 | |
| 80 | 78 | return result; |
| r1217 | r1218 | |
| 89 | 87 | -------------------------------------------------*/ |
| 90 | 88 | |
| 91 | 89 | #define mul_32x32_shift _mul_32x32_shift |
| 92 | | INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift) |
| 90 | INLINE INT32 _mul_32x32_shift(INT32 val1, INT32 val2, UINT8 shift) |
| 93 | 91 | { |
| 94 | 92 | INT32 result; |
| 95 | 93 | |
| 96 | 94 | #if defined(__ppc64__) || defined(__PPC64__) |
| 97 | 95 | __asm__ ( |
| 98 | | " mulld %0,%1,%2 \n" |
| 99 | | " srd %0,%0,%3 \n" |
| 100 | | : "=&r" (result) /* result can go in any register */ |
| 101 | | : "%r" (val1) /* any register, can swap with val2 */ |
| 102 | | "r" (val2) /* any register */ |
| 103 | | "r" (shift) /* any register */ |
| 96 | " mulld %[result], %[val1], %[val2] \n" |
| 97 | " srd %[result], %[result], %[shift] \n" |
| 98 | : [result] "=&r" (result) /* result can go in any register */ |
| 99 | : [val1] "%r" (val1) /* any register, can swap with val2 */ |
| 100 | , [val2] "r" (val2) /* any register */ |
| 101 | , [shift] "r" (shift) /* any register */ |
| 104 | 102 | ); |
| 105 | 103 | #else |
| 106 | 104 | __asm__ ( |
| 107 | | " mullw %0,%2,%3 \n" |
| 108 | | " mulhw %2,%2,%3 \n" |
| 109 | | " srw %0,%0,%1 \n" |
| 110 | | " subfic %1,%1,0x20 \n" |
| 111 | | " slw %2,%2,%1 \n" |
| 112 | | " or %0,%0,%2 \n" |
| 113 | | : "=&r" (result), |
| 114 | | "+r" (shift), |
| 115 | | "+r" (val1) |
| 116 | | : "r" (val2) |
| 117 | | : "xer" |
| 105 | " mullw %[result], %[val1], %[val2] \n" |
| 106 | " mulhw %[val1], %[val1], %[val2] \n" |
| 107 | " srw %[result], %[result], %[shift] \n" |
| 108 | " subfic %[shift], %[shift], 0x20 \n" |
| 109 | " slw %[val1], %[val1], %[shift] \n" |
| 110 | " or %[result], %[result], %[val1] \n" |
| 111 | : [result] "=&r" (result) |
| 112 | , [shift] "+r" (shift) |
| 113 | , [val1] "+r" (val1) |
| 114 | : [val2] "r" (val2) |
| 115 | : "xer" |
| 118 | 116 | ); |
| 119 | 117 | #endif |
| 120 | 118 | |
| r1217 | r1218 | |
| 130 | 128 | -------------------------------------------------*/ |
| 131 | 129 | |
| 132 | 130 | #define mulu_32x32_shift _mulu_32x32_shift |
| 133 | | INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift) |
| 131 | INLINE UINT32 _mulu_32x32_shift(UINT32 val1, UINT32 val2, UINT8 shift) |
| 134 | 132 | { |
| 135 | 133 | UINT32 result; |
| 136 | 134 | |
| 137 | 135 | #if defined(__ppc64__) || defined(__PPC64__) |
| 138 | 136 | __asm__ ( |
| 139 | | " mulldu %0,%1,%2 \n" |
| 140 | | " srd %0,%0,%3 \n" |
| 141 | | : "=&r" (result) /* result can go in any register */ |
| 142 | | : "%r" (val1) /* any register, can swap with val2 */ |
| 143 | | "r" (val2) /* any register */ |
| 144 | | "r" (shift) /* any register */ |
| 137 | " mulld %[result], %[val1], %[val2] \n" |
| 138 | " srd %[result], %[result], %[shift] \n" |
| 139 | : [result] "=&r" (result) /* result can go in any register */ |
| 140 | : [val1] "%r" (val1) /* any register, can swap with val2 */ |
| 141 | , [val2] "r" (val2) /* any register */ |
| 142 | , [shift] "r" (shift) /* any register */ |
| 145 | 143 | ); |
| 146 | 144 | #else |
| 147 | 145 | __asm__ ( |
| 148 | | " mullw %0,%2,%3 \n" |
| 149 | | " mulhwu %2,%2,%3 \n" |
| 150 | | " srw %0,%0,%1 \n" |
| 151 | | " subfic %1,%1,0x20 \n" |
| 152 | | " slw %2,%2,%1 \n" |
| 153 | | " or %0,%0,%2 \n" |
| 154 | | : "=&r" (result), |
| 155 | | "+r" (shift), |
| 156 | | "+r" (val1) |
| 157 | | : "r" (val2) |
| 158 | | : "xer" |
| 146 | " mullw %[result], %[val1], %[val2] \n" |
| 147 | " mulhwu %[val1], %[val1], %[val2] \n" |
| 148 | " srw %[result], %[result], %[shift] \n" |
| 149 | " subfic %[shift], %[shift], 0x20 \n" |
| 150 | " slw %[val1], %[val1], %[shift] \n" |
| 151 | " or %[result], %[result], %[val1] \n" |
| 152 | : [result] "=&r" (result) |
| 153 | , [shift] "+r" (shift) |
| 154 | , [val1] "+r" (val1) |
| 155 | : [val2] "r" (val2) |
| 156 | : "xer" |
| 159 | 157 | ); |
| 160 | 158 | #endif |
| 161 | 159 | |
| r1217 | r1218 | |
| 237 | 235 | UINT32 result; |
| 238 | 236 | |
| 239 | 237 | __asm__ ( |
| 240 | | " cntlzw %0,%1 \n" |
| 241 | | : "=r" (result) /* result can be in any register */ |
| 242 | | : "r" (value) /* 'value' can be in any register */ |
| 238 | " cntlzw %[result], %[value] \n" |
| 239 | : [result] "=r" (result) /* result can be in any register */ |
| 240 | : [value] "r" (value) /* 'value' can be in any register */ |
| 243 | 241 | ); |
| 244 | 242 | |
| 245 | 243 | return result; |
| r1217 | r1218 | |
| 257 | 255 | UINT32 result; |
| 258 | 256 | |
| 259 | 257 | __asm__ ( |
| 260 | | " not %0,%1 \n" |
| 261 | | " cntlzw %0,%0 \n" |
| 262 | | : "=r" (result) /* result can be in any register */ |
| 263 | | : "r" (value) /* 'value' can be in any register */ |
| 258 | " not %[result], %[value] \n" |
| 259 | " cntlzw %[result], %[result] \n" |
| 260 | : [result] "=r" (result) /* result can be in any register */ |
| 261 | : [value] "r" (value) /* 'value' can be in any register */ |
| 264 | 262 | ); |
| 265 | 263 | |
| 266 | 264 | return result; |
| r1217 | r1218 | |
| 290 | 288 | " bne 2f \n" |
| 291 | 289 | " sync \n" |
| 292 | 290 | " stwcx. %[exchange], 0, %[ptr] \n" |
| 293 | | " bne- 1b \n" |
| 291 | " bne- 1b \n" |
| 294 | 292 | "2: " |
| 295 | 293 | : [result] "=&r" (result) |
| 296 | 294 | : [ptr] "r" (ptr) |
| r1217 | r1218 | |
| 310 | 308 | return the previous value at 'ptr'. |
| 311 | 309 | -------------------------------------------------*/ |
| 312 | 310 | |
| 313 | | #ifdef PTR64 |
| 311 | #if defined(__ppc64__) || defined(__PPC64__) |
| 314 | 312 | #define compare_exchange64 _compare_exchange64 |
| 315 | 313 | INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange) |
| 316 | 314 | { |
| r1217 | r1218 | |
| 320 | 318 | "1: ldarx %[result], 0, %[ptr] \n" |
| 321 | 319 | " cmpd %[compare], %[result] \n" |
| 322 | 320 | " bne 2f \n" |
| 323 | | " sync \n" |
| 324 | 321 | " stdcx. %[exchange], 0, %[ptr] \n" |
| 325 | 322 | " bne-- 1b \n" |
| 326 | 323 | "2: " |
| r1217 | r1218 | |
| 352 | 349 | " sync \n" |
| 353 | 350 | " stwcx. %[exchange], 0, %[ptr] \n" |
| 354 | 351 | " bne- 1b \n" |
| 355 | | : [result] "=&r" (result) |
| 352 | : [result] "=&r" (result) |
| 356 | 353 | : [ptr] "r" (ptr) |
| 357 | 354 | , [exchange] "r" (exchange) |
| 358 | 355 | : "cr0" |
| r1217 | r1218 | |
| 373 | 370 | { |
| 374 | 371 | register INT32 result; |
| 375 | 372 | |
| 376 | | __asm __volatile__ ( |
| 377 | | "1: lwarx %[result], 0, %[ptr] \n" |
| 373 | __asm__ __volatile__ ( |
| 374 | "1: lwarx %[result], 0, %[ptr] \n" |
| 378 | 375 | " add %[result], %[result], %[delta] \n" |
| 379 | | " sync \n" |
| 380 | | " stwcx. %[result], 0, %[ptr] \n" |
| 381 | | " bne- 1b \n" |
| 382 | | : [result] "=&b" (result) |
| 383 | | : [ptr] "r" (ptr) |
| 384 | | , [delta] "r" (delta) |
| 376 | " sync \n" |
| 377 | " stwcx. %[result], 0, %[ptr] \n" |
| 378 | " bne- 1b \n" |
| 379 | : [result] "=&b" (result) |
| 380 | : [ptr] "r" (ptr) |
| 381 | , [delta] "r" (delta) |
| 385 | 382 | : "cr0" |
| 386 | 383 | ); |
| 387 | 384 | |