Previous 15994 Revisions Next

r1218 Saturday 3rd November, 2007 at 14:59:52 UTC by R. Belmont
[SDLMESS] Updated to 0.120u1. emu/ parts have been submitted to MAMEdev. [Vas Crabb]
[src/emu]eigccppc.h eigccx86.h eminline.h validity.c
[src/osd/sdl]osd_cpu.h osinline.h sdlsync.c sdlsync.h sdlwork.c video.c window.c

src/osd/sdl/osd_cpu.h
r1217r1218
5555#define MUL_64_32_32(A,B)     ((A)*(INT64)(B))
5656#define MUL_U64_U32_U32(A,B)  ((A)*(UINT64)(UINT32)(B))
5757
58
59/***************************************************************************
60
61    Inline math helpers
62
63***************************************************************************/
64
65#ifdef __GNUC__
66
67#if defined(__i386__) || defined(__x86_64__)
68
69INLINE 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
85INLINE 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
103INLINE 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
123INLINE 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
137INLINE 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
154INLINE 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
173INLINE 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
20258#endif   /* defined OSD_CPU_H */
src/osd/sdl/video.c
r1217r1218
855855
856856   config->width = config->height = config->depth = config->refresh = 0;
857857   if (strcmp(data, "auto") == 0)
858   {
858859      return;
860   }
859861   else if (sscanf(data, "%dx%dx%d@%d", &config->width, &config->height, &config->depth, &config->refresh) < 2 && report_error)
860862      mame_printf_error("Illegal resolution value for %s = %s\n", name, data);
861863}
src/osd/sdl/window.c
r1217r1218
713713      window->windowed_width = config->width;
714714      window->windowed_height = config->height;
715715   }
716   window->totalColors = config->totalColors;
716     window->totalColors = config->totalColors;
717717
718718   // add us to the list
719719   *last_window_ptr = window;
r1217r1218
727727   if (window->target == NULL)
728728      goto error;
729729
730   // set the specific view
730   // set the specific view               
731731   sprintf(option, SDLOPTION_VIEW("%d"), index);
732732   set_starting_view(index, window, options_get_string(mame_options(), option));
733733
src/osd/sdl/sdlsync.c
r1217r1218
3939#include "mame.h"
4040#include "sdlsync.h"
4141
42#include "eminline.h"
43
4244#ifndef SDLMAME_OS2
4345#include <pthread.h>
4446#include <errno.h>
r1217r1218
7072   pthread_t         thread;
7173};
7274
73static osd_lock         *atomic_lck = NULL;
74
7575INLINE pthread_t osd_compare_exchange_pthread_t(pthread_t volatile *ptr, pthread_t compare, pthread_t exchange)
7676{
7777#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);
7979#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);
8181#endif
8282   return (pthread_t)result;
8383}
r1217r1218
8787#ifdef PTR64
8888   INT64 result = osd_exchange64((INT64 volatile *)ptr, (INT64)exchange);
8989#else
90   INT32 result = osd_exchange32((INT32 volatile *)ptr, (INT32)exchange);
90   INT32 result = atomic_exchange32((INT32 volatile *)ptr, (INT32)exchange);
9191#endif
9292   return (pthread_t)result;
9393}
r1217r1218
393393}
394394 
395395//============================================================
396//  osd_atomic_lock
397//============================================================
398
399void 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
410void osd_atomic_unlock(void)
411{
412   osd_lock_release(atomic_lck);
413}
414
415//============================================================
416396//  osd_thread_create
417397//============================================================
418398
r1217r1218
463443   free(thread);
464444}
465445
466//============================================================
467//  osd_compare_exchange32
468//============================================================
469446
470#ifndef osd_compare_exchange32
471
472INT32 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
496INT64 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
514447#else   // SDLMAME_OS2
515448
449
516450struct _osd_lock
517451{
518452     HMTX   hmtx;
src/osd/sdl/sdlsync.h
r1217r1218
198198int osd_num_processors(void);
199199
200200
201/*-----------------------------------------------------------------------------
202    osd_atomic_lock: block other processes
203
204    Parameters:
205
206        None.
207
208    Return value:
209
210        None.
211   
212    Notes:
213        This will be used on certain platforms to emulate atomic operations
214        Please see osinclude.h
215-----------------------------------------------------------------------------*/
216void osd_atomic_lock(void);
217
218/*-----------------------------------------------------------------------------
219    osd_atomic_unlock: unblock other processes
220
221    Parameters:
222
223        None.
224
225    Return value:
226
227        None.
228   
229    Notes:
230        This will be used on certain platforms to emulate atomic operations
231        Please see osinclude.h
232-----------------------------------------------------------------------------*/
233void osd_atomic_unlock(void);
234
235
236201#endif   /* SDLMAME_WIN32 */
237202
238203#endif   /* __SDL_SYNC__ */
src/osd/sdl/osinline.h
r1217r1218
77#ifndef __OSINLINE__
88#define __OSINLINE__
99
10#include "osd_cpu.h"
10#include "eminline.h"
1111
12
1213//============================================================
1314//   INLINE FUNCTIONS
1415//============================================================
1516
16//#define YieldProcessor() sched_yield()
17//#define YieldProcessor() do {} while (0)
18
19#ifndef YieldProcessor
20
2117#if defined(__i386__) || defined(__x86_64__)
2218
19
2320INLINE void osd_yield_processor(void)
2421{
2522   __asm__ __volatile__ ( " rep ; nop ;" );
2623}
2724
28#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
2925
30INLINE 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
4626//============================================================
47//  osd_compare_exchange32
48//============================================================
49#ifndef SDLMAME_WIN32
50ATTR_UNUSED
51INLINE 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
71ATTR_UNUSED
72INLINE 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
91ATTR_UNUSED
92INLINE 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//============================================================
11027//  osd_interlocked_increment
11128//============================================================
11229
r1217r1218
15370#if defined(__x86_64__)
15471
15572//============================================================
156//  osd_compare_exchange64
157//============================================================
158
159ATTR_UNUSED
160INLINE 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//============================================================
17773//  osd_exchange64
17874//============================================================
17975
r1217r1218
19490#endif /* __x86_64__ */
19591
19692
197#elif defined(__ppc__) || defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__)
93#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
19894
19995
200//============================================================
201//  osd_compare_exchange32
202//============================================================
203
204ATTR_UNUSED
205INLINE INT32 _osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
96INLINE void osd_yield_processor(void)
20697{
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" );
22399}
224#define osd_compare_exchange32 _osd_compare_exchange32
225100
226101
227102//============================================================
228//  osd_exchange32
229//============================================================
230
231ATTR_UNUSED
232INLINE 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
254ATTR_UNUSED
255INLINE 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//============================================================
275103//  osd_interlocked_increment
276104//============================================================
277105
r1217r1218
320148#if defined(__ppc64__) || defined(__PPC64__)
321149
322150//============================================================
323//  osd_compare_exchange64
324//============================================================
325
326ATTR_UNUSED
327INLINE 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//============================================================
349151//  osd_exchange64
350152//============================================================
351153
r1217r1218
371173
372174#endif
373175
374#endif /* __GNUC__ */
375
376
377176#endif /* __OSINLINE__ */
src/osd/sdl/sdlwork.c
r1217r1218
3232#endif
3333#include "sdlsync.h"
3434
35#include "eminline.h"
3536
37
3638//============================================================
3739//  DEBUGGING
3840//============================================================
r1217r1218
5658//============================================================
5759
5860#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)
6062#define begin_timing(v)         do { (v) -= osd_profiling_ticks(); } while (0)
6163#define end_timing(v)         do { (v) += osd_profiling_ticks(); } while (0)
6264#else
r1217r1218
151153//  INLINE FUNCTIONS
152154//============================================================
153155
154#ifndef osd_exchange32
155INLINE 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
165156#ifndef osd_interlocked_increment
166157INLINE INT32 osd_interlocked_increment(INT32 volatile *ptr)
167158{
168   return osd_sync_add(ptr, 1);
159   return atomic_add32(ptr, 1);
169160}
170161#endif
171162
172163#ifndef osd_interlocked_decrement
173164INLINE INT32 osd_interlocked_decrement(INT32 volatile *ptr)
174165{
175   return osd_sync_add(ptr, -1);
166   return atomic_add32(ptr, -1);
176167}
177168#endif
178169
179#ifndef osd_interlocked_add
180INLINE INT32 osd_interlocked_add(INT32 volatile *ptr, INT32 add)
181{
182   return osd_sync_add(ptr, add);
183}
184#endif
185
186170INLINE void scalable_lock_init(scalable_lock *lock)
187171{
188172   memset(lock, 0, sizeof(*lock));
r1217r1218
395379
396380   // reset our done event and double-check the items before waiting
397381   osd_event_reset(queue->doneevent);
398   osd_exchange32(&queue->waiting, TRUE);
382   atomic_exchange32(&queue->waiting, TRUE);
399383   if (queue->items != 0)
400384      osd_event_wait(queue->doneevent, timeout);
401   osd_exchange32(&queue->waiting, FALSE);
385   atomic_exchange32(&queue->waiting, FALSE);
402386
403387   // return TRUE if we actually hit 0
404388   return (queue->items == 0);
r1217r1218
520504      do
521505      {
522506         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);
524508
525509      // if nothing, allocate something new
526510      if (item == NULL)
r1217r1218
553537   scalable_lock_release(&queue->lock, lockslot);
554538
555539   // increment the number of items in the queue
556   osd_interlocked_add(&queue->items, numitems);
540   atomic_add32(&queue->items, numitems);
557541   add_to_stat(&queue->itemsqueued, numitems);
558542
559543   // look for free threads to do the work
r1217r1218
650634   {
651635      next = (osd_work_item *)item->queue->free;
652636      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);
654638}
655639
656640
r1217r1218
697681         break;
698682
699683      // indicate that we are live
700      osd_exchange32(&thread->active, TRUE);
684      atomic_exchange32(&thread->active, TRUE);
701685      osd_interlocked_increment(&queue->livethreads);
702686
703687      // process work items
r1217r1218
724708      }
725709
726710      // decrement the live thread count
727      osd_exchange32(&thread->active, FALSE);
711      atomic_exchange32(&thread->active, FALSE);
728712      osd_interlocked_decrement(&queue->livethreads);
729713   }
730714   return NULL;
src/emu/eigccx86.h
r1217r1218
2323    multiply and return the full 64 bit result
2424-------------------------------------------------*/
2525
26#ifndef PTR64
26#ifndef __x86_64__
2727#define mul_32x32 _mul_32x32
2828INLINE INT64 _mul_32x32(INT32 a, INT32 b)
2929{
3030   INT64 result;
3131
3232   __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 */
3738   );
3839
3940   return result;
r1217r1218
4748    result
4849-------------------------------------------------*/
4950
50#ifndef PTR64
51#ifndef __x86_64__
5152#define mulu_32x32 _mulu_32x32
5253INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b)
5354{
5455   UINT64 result;
5556
5657   __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 */
6163   );
6264
6365   return result;
r1217r1218
7173    result
7274-------------------------------------------------*/
7375
74#ifndef PTR64
7576#define mul_32x32_hi _mul_32x32_hi
7677INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
7778{
7879   INT32 result;
7980
8081   __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 */
8787   );
8888
8989   return result;
9090}
91#endif
9291
9392
9493/*-------------------------------------------------
r1217r1218
9796    of the result
9897-------------------------------------------------*/
9998
100#ifndef PTR64
10199#define mulu_32x32_hi _mulu_32x32_hi
102100INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
103101{
104102   UINT32 result;
105103
106104   __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 */
113110   );
114111
115112   return result;
116113}
117#endif
118114
119115
120116/*-------------------------------------------------
r1217r1218
124120    result to 32 bits
125121-------------------------------------------------*/
126122
127#ifndef PTR64
123#ifndef __x86_64__
128124#define mul_32x32_shift _mul_32x32_shift
129125INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
130126{
131127   INT32 result;
132128
133129   __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 */
141137   );
142138
143139   return result;
r1217r1218
152148    result to 32 bits
153149-------------------------------------------------*/
154150
155#ifndef PTR64
151#ifndef __x86_64__
156152#define mulu_32x32_shift _mulu_32x32_shift
157153INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
158154{
159155   UINT32 result;
160156
161157   __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 */
169165   );
170166
171167   return result;
r1217r1218
195191    division, and returning the 32 bit quotient
196192-------------------------------------------------*/
197193
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__
201195#define div_32x32_shift _div_32x32_shift
202196INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
203197{
204198   INT32 result;
205199
206200   __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 */
216210   );
217211
218212   return result;
219213}
220214#endif
221#endif
222215
223216
224217/*-------------------------------------------------
r1217r1218
227220    division, and returning the 32 bit quotient
228221-------------------------------------------------*/
229222
230#ifndef PTR64
223#ifndef __x86_64__
231224#define divu_32x32_shift _divu_32x32_shift
232225INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
233226{
234227   INT32 result;
235228
236229   __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 */
246239   );
247240
248241   return result;
r1217r1218
290283   UINT32 result;
291284
292285   __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 */
300293   );
301294
302295   return result;
r1217r1218
314307   UINT32 result;
315308
316309   __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 */
326319   );
327320
328321   return result;
r1217r1218
347340   register INT32 result;
348341
349342   __asm__ __volatile__ (
350      " lock ; cmpxchg %[exchange], %[ptr] ;"
343      " lock ; cmpxchg %[exchange], %[ptr] ;"
351344     : [ptr]      "+m" (*ptr)
352345     , [result]   "=a" (result)
353346     : [compare]  "1"  (compare)
r1217r1218
366359    return the previous value at 'ptr'.
367360-------------------------------------------------*/
368361
369#ifdef PTR64
362#ifdef __x86_64__
370363#define compare_exchange64 _compare_exchange64
371364INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
372365{
373366   register INT64 result;
374367
375368   __asm__ __volatile__ (
376      " lock ; cmpxchg %[exchange], %[ptr] ;"
369      " lock ; cmpxchg %[exchange], %[ptr] ;"
377370     : [ptr]      "+m" (*ptr)
378371     , [result]   "=a" (result)
379372     : [compare]  "1"  (compare)
r1217r1218
398391   register INT32 result;
399392
400393   __asm__ __volatile__ (
401      " lock ; xchg %[exchange], %[ptr] ;"
394      " lock ; xchg %[exchange], %[ptr] ;"
402395      : [ptr]      "+m" (*ptr)
403396      , [result]   "=r" (result)
404397      : [exchange] "1"  (exchange)
r1217r1218
419412{
420413   register INT32 result;
421414
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] ;"
426419     : [ptr]    "+m"  (*ptr)
427420     , [result] "=&r" (result)
428421     : [delta]  "rmi" (delta)
src/emu/eminline.h
r1217r1218
308308    return the previous value at 'ptr'.
309309-------------------------------------------------*/
310310
311#ifdef PTR64
312311#ifndef compare_exchange_ptr
313312INLINE void *compare_exchange_ptr(void * volatile *ptr, void *compare, void *exchange)
314313{
315314#ifdef PTR64
316   return (void *)compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
315   INT64 result;
316   result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
317317#else
318   return (void *)compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
318   INT32 result;
319   result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
319320#endif
321   return (void *)result;
320322}
321323#endif
322#endif
323324
324325
325326/*-------------------------------------------------
src/emu/eigccppc.h
r1217r1218
4242-------------------------------------------------*/
4343
4444#define mul_32x32_hi _mul_32x32_hi
45INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
45INLINE INT32 _mul_32x32_hi(INT32 val1, INT32 val2)
4646{
4747   INT32 result;
4848
4949   __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)
5554   );
5655
5756   return result;
r1217r1218
6564-------------------------------------------------*/
6665
6766#define mulu_32x32_hi _mulu_32x32_hi
68INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
67INLINE UINT32 _mulu_32x32_hi(UINT32 val1, UINT32 val2)
6968{
7069   UINT32 result;
7170
7271   __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)
7876   );
7977
8078   return result;
r1217r1218
8987-------------------------------------------------*/
9088
9189#define mul_32x32_shift _mul_32x32_shift
92INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
90INLINE INT32 _mul_32x32_shift(INT32 val1, INT32 val2, UINT8 shift)
9391{
9492   INT32 result;
9593
9694#if defined(__ppc64__) || defined(__PPC64__)
9795   __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 */
104102   );
105103#else
106104   __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"
118116   );
119117#endif
120118
r1217r1218
130128-------------------------------------------------*/
131129
132130#define mulu_32x32_shift _mulu_32x32_shift
133INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
131INLINE UINT32 _mulu_32x32_shift(UINT32 val1, UINT32 val2, UINT8 shift)
134132{
135133   UINT32 result;
136134
137135#if defined(__ppc64__) || defined(__PPC64__)
138136   __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 */
145143   );
146144#else
147145   __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"
159157   );
160158#endif
161159
r1217r1218
237235   UINT32 result;
238236
239237   __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 */
243241   );
244242
245243   return result;
r1217r1218
257255   UINT32 result;
258256
259257   __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 */
264262   );
265263
266264   return result;
r1217r1218
290288      "   bne    2f                     \n"
291289      "   sync                          \n"
292290      "   stwcx. %[exchange], 0, %[ptr] \n"
293      "   bne- 1b                       \n"
291      "   bne-   1b                     \n"
294292      "2:                                 "
295293      : [result]   "=&r" (result)
296294      : [ptr]      "r"   (ptr)
r1217r1218
310308    return the previous value at 'ptr'.
311309-------------------------------------------------*/
312310
313#ifdef PTR64
311#if defined(__ppc64__) || defined(__PPC64__)
314312#define compare_exchange64 _compare_exchange64
315313INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
316314{
r1217r1218
320318      "1: ldarx  %[result], 0, %[ptr]   \n"
321319      "   cmpd   %[compare], %[result]  \n"
322320      "   bne    2f                     \n"
323      "   sync                          \n"
324321      "   stdcx. %[exchange], 0, %[ptr] \n"
325322      "   bne--  1b                     \n"
326323      "2:                                 "
r1217r1218
352349      "   sync                          \n"
353350      "   stwcx. %[exchange], 0, %[ptr] \n"
354351      "   bne-   1b                     \n"
355      : [result]      "=&r" (result)
352      : [result]   "=&r" (result)
356353      : [ptr]      "r"   (ptr)
357354      , [exchange] "r"   (exchange)
358355      : "cr0"
r1217r1218
373370{
374371   register INT32 result;
375372
376   __asm __volatile__ (
377      "1: lwarx  %[result], 0, %[ptr]     \n"
373   __asm__ __volatile__ (
374      "1: lwarx  %[result], 0, %[ptr]           \n"
378375      "   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)
385382      : "cr0"
386383   );
387384
src/emu/validity.c
r1217r1218
220220   int test2 = rand() | (rand() << 15);
221221   int error = FALSE;
222222
223   if (mul_32x32(test1, test2) != (INT64)test1 * (INT64)test2) { mame_printf_error("Error testing mul_32x32\n"); error = TRUE; }
224   if (mulu_32x32(test1, test2) != (UINT64)test1 * (UINT64)test2) { mame_printf_error("Error testing mulu_32x32\n"); error = TRUE; }
225   if (mul_32x32_hi(test1, test2) != ((INT64)test1 * (INT64)test2) >> 32) { mame_printf_error("Error testing mul_32x32_hi\n"); error = TRUE; }
226   if (mulu_32x32_hi(test1, test2) != ((UINT64)test1 * (UINT64)test2) >> 32) { mame_printf_error("Error testing mulu_32x32_hi\n"); error = TRUE; }
223   if (mul_32x32(test1, test2) != (INT64)(INT32)test1 * (INT64)(INT32)test2) { mame_printf_error("Error testing mul_32x32\n"); error = TRUE; }
224   if (mulu_32x32(test1, test2) != (UINT64)(UINT32)test1 * (UINT64)(UINT32)test2) { mame_printf_error("Error testing mulu_32x32\n"); error = TRUE; }
225   if (mul_32x32_hi(test1, test2) != ((INT64)(INT32)test1 * (INT64)(INT32)test2) >> 32) { mame_printf_error("Error testing mul_32x32_hi\n"); error = TRUE; }
226   if (mulu_32x32_hi(test1, test2) != ((UINT64)(UINT32)test1 * (UINT64)(UINT32)test2) >> 32) { mame_printf_error("Error testing mulu_32x32_hi\n"); error = TRUE; }
227227   if (mul_32x32_shift(test1, test2, 7) != (INT32)(((INT64)test1 * (INT64)test2) >> 7)) { mame_printf_error("Error testing mul_32x32_shift\n"); error = TRUE; }
228   if (mulu_32x32_shift(test1, test2, 7) != (UINT32)(((UINT64)test1 * (UINT64)test2) >> 7)) { mame_printf_error("Error testing mulu_32x32_shift\n"); error = TRUE; }
228   if (mulu_32x32_shift(test1, test2, 7) != (UINT32)(((UINT64)(UINT32)test1 * (UINT64)(UINT32)test2) >> 7)) { mame_printf_error("Error testing mulu_32x32_shift\n"); error = TRUE; }
229229   if (fabs(recip_approx(100.0) - 0.01) > 0.0001) { mame_printf_error("Error testing recip_approx\n"); error = TRUE; }
230230   test1 = (test1 & 0x0000ffff) | 0x400000;
231231   if (count_leading_zeros(test1) != 9) { mame_printf_error("Error testing count_leading_zeros\n"); error = TRUE; }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team