~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/emu/eminline.h

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
    eminline.h
4
 
 
5
 
    Definitions for inline functions that can be overriden by OSD-
6
 
    specific code.
7
 
 
8
 
    Copyright Nicola Salmoria and the MAME Team.
9
 
    Visit http://mamedev.org for licensing and usage restrictions.
10
 
 
11
 
***************************************************************************/
12
 
 
13
 
#ifndef __EMINLINE__
14
 
#define __EMINLINE__
15
 
 
16
 
/* we come with implementations for GCC x86 and PPC */
17
 
#ifdef __GNUC__
18
 
 
19
 
#if defined(__i386__) || defined(__x86_64__)
20
 
#include "eigccx86.h"
21
 
#elif defined(__ppc__) || defined (__PPC__) || defined(__ppc64__) || defined(__PPC64__)
22
 
#include "eigccppc.h"
23
 
#else
24
 
#include "osinline.h"
25
 
#endif
26
 
 
27
 
#else
28
 
 
29
 
#include "osinline.h"
30
 
 
31
 
#endif
32
 
 
33
 
 
34
 
/***************************************************************************
35
 
    INLINE MATH FUNCTIONS
36
 
***************************************************************************/
37
 
 
38
 
/*-------------------------------------------------
39
 
    mul_32x32 - perform a signed 32 bit x 32 bit
40
 
    multiply and return the full 64 bit result
41
 
-------------------------------------------------*/
42
 
 
43
 
#ifndef mul_32x32
44
 
INLINE INT64 mul_32x32(INT32 a, INT32 b)
45
 
{
46
 
        return (INT64)a * (INT64)b;
47
 
}
48
 
#endif
49
 
 
50
 
 
51
 
/*-------------------------------------------------
52
 
    mulu_32x32 - perform an unsigned 32 bit x
53
 
    32 bit multiply and return the full 64 bit
54
 
    result
55
 
-------------------------------------------------*/
56
 
 
57
 
#ifndef mulu_32x32
58
 
INLINE UINT64 mulu_32x32(UINT32 a, UINT32 b)
59
 
{
60
 
        return (UINT64)a * (UINT64)b;
61
 
}
62
 
#endif
63
 
 
64
 
 
65
 
/*-------------------------------------------------
66
 
    mul_32x32_hi - perform a signed 32 bit x 32 bit
67
 
    multiply and return the upper 32 bits of the
68
 
    result
69
 
-------------------------------------------------*/
70
 
 
71
 
#ifndef mul_32x32_hi
72
 
INLINE INT32 mul_32x32_hi(INT32 a, INT32 b)
73
 
{
74
 
        return (UINT32)(((INT64)a * (INT64)b) >> 32);
75
 
}
76
 
#endif
77
 
 
78
 
 
79
 
/*-------------------------------------------------
80
 
    mulu_32x32_hi - perform an unsigned 32 bit x
81
 
    32 bit multiply and return the upper 32 bits
82
 
    of the result
83
 
-------------------------------------------------*/
84
 
 
85
 
#ifndef mulu_32x32_hi
86
 
INLINE UINT32 mulu_32x32_hi(UINT32 a, UINT32 b)
87
 
{
88
 
        return (UINT32)(((UINT64)a * (UINT64)b) >> 32);
89
 
}
90
 
#endif
91
 
 
92
 
 
93
 
/*-------------------------------------------------
94
 
    mul_32x32_shift - perform a signed 32 bit x
95
 
    32 bit multiply and shift the result by the
96
 
    given number of bits before truncating the
97
 
    result to 32 bits
98
 
-------------------------------------------------*/
99
 
 
100
 
#ifndef mul_32x32_shift
101
 
INLINE INT32 mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
102
 
{
103
 
        return (INT32)(((INT64)a * (INT64)b) >> shift);
104
 
}
105
 
#endif
106
 
 
107
 
 
108
 
/*-------------------------------------------------
109
 
    mulu_32x32_shift - perform an unsigned 32 bit x
110
 
    32 bit multiply and shift the result by the
111
 
    given number of bits before truncating the
112
 
    result to 32 bits
113
 
-------------------------------------------------*/
114
 
 
115
 
#ifndef mulu_32x32_shift
116
 
INLINE UINT32 mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
117
 
{
118
 
        return (UINT32)(((UINT64)a * (UINT64)b) >> shift);
119
 
}
120
 
#endif
121
 
 
122
 
 
123
 
/*-------------------------------------------------
124
 
    div_64x32 - perform a signed 64 bit x 32 bit
125
 
    divide and return the 32 bit quotient
126
 
-------------------------------------------------*/
127
 
 
128
 
#ifndef div_64x32
129
 
INLINE INT32 div_64x32(INT64 a, INT32 b)
130
 
{
131
 
        return a / (INT64)b;
132
 
}
133
 
#endif
134
 
 
135
 
 
136
 
/*-------------------------------------------------
137
 
    divu_64x32 - perform an unsigned 64 bit x 32 bit
138
 
    divide and return the 32 bit quotient
139
 
-------------------------------------------------*/
140
 
 
141
 
#ifndef divu_64x32
142
 
INLINE UINT32 divu_64x32(UINT64 a, UINT32 b)
143
 
{
144
 
        return a / (UINT64)b;
145
 
}
146
 
#endif
147
 
 
148
 
 
149
 
/*-------------------------------------------------
150
 
    div_64x32_rem - perform a signed 64 bit x 32
151
 
    bit divide and return the 32 bit quotient and
152
 
    32 bit remainder
153
 
-------------------------------------------------*/
154
 
 
155
 
#ifndef div_64x32_rem
156
 
INLINE INT32 div_64x32_rem(INT64 a, INT32 b, INT32 *remainder)
157
 
{
158
 
        *remainder = a % (INT64)b;
159
 
        return a / (INT64)b;
160
 
}
161
 
#endif
162
 
 
163
 
 
164
 
/*-------------------------------------------------
165
 
    divu_64x32_rem - perform an unsigned 64 bit x
166
 
    32 bit divide and return the 32 bit quotient
167
 
    and 32 bit remainder
168
 
-------------------------------------------------*/
169
 
 
170
 
#ifndef divu_64x32_rem
171
 
INLINE UINT32 divu_64x32_rem(UINT64 a, UINT32 b, UINT32 *remainder)
172
 
{
173
 
        *remainder = a % (UINT64)b;
174
 
        return a / (UINT64)b;
175
 
}
176
 
#endif
177
 
 
178
 
 
179
 
/*-------------------------------------------------
180
 
    div_32x32_shift - perform a signed divide of
181
 
    two 32 bit values, shifting the first before
182
 
    division, and returning the 32 bit quotient
183
 
-------------------------------------------------*/
184
 
 
185
 
#ifndef div_32x32_shift
186
 
INLINE INT32 div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
187
 
{
188
 
        return ((INT64)a << shift) / (INT64)b;
189
 
}
190
 
#endif
191
 
 
192
 
 
193
 
/*-------------------------------------------------
194
 
    divu_32x32_shift - perform an unsigned divide of
195
 
    two 32 bit values, shifting the first before
196
 
    division, and returning the 32 bit quotient
197
 
-------------------------------------------------*/
198
 
 
199
 
#ifndef divu_32x32_shift
200
 
INLINE UINT32 divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
201
 
{
202
 
        return ((UINT64)a << shift) / (UINT64)b;
203
 
}
204
 
#endif
205
 
 
206
 
 
207
 
/*-------------------------------------------------
208
 
    mod_64x32 - perform a signed 64 bit x 32 bit
209
 
    divide and return the 32 bit remainder
210
 
-------------------------------------------------*/
211
 
 
212
 
#ifndef mod_64x32
213
 
INLINE INT32 mod_64x32(INT64 a, INT32 b)
214
 
{
215
 
        return a % (INT64)b;
216
 
}
217
 
#endif
218
 
 
219
 
 
220
 
/*-------------------------------------------------
221
 
    modu_64x32 - perform an unsigned 64 bit x 32 bit
222
 
    divide and return the 32 bit remainder
223
 
-------------------------------------------------*/
224
 
 
225
 
#ifndef modu_64x32
226
 
INLINE UINT32 modu_64x32(UINT64 a, UINT32 b)
227
 
{
228
 
        return a % (UINT64)b;
229
 
}
230
 
#endif
231
 
 
232
 
 
233
 
/*-------------------------------------------------
234
 
    recip_approx - compute an approximate floating
235
 
    point reciprocal
236
 
-------------------------------------------------*/
237
 
 
238
 
#ifndef recip_approx
239
 
INLINE float recip_approx(float value)
240
 
{
241
 
        return 1.0f / value;
242
 
}
243
 
#endif
244
 
 
245
 
 
246
 
 
247
 
/***************************************************************************
248
 
    INLINE BIT MANIPULATION FUNCTIONS
249
 
***************************************************************************/
250
 
 
251
 
/*-------------------------------------------------
252
 
    count_leading_zeros - return the number of
253
 
    leading zero bits in a 32-bit value
254
 
-------------------------------------------------*/
255
 
 
256
 
#ifndef count_leading_zeros
257
 
INLINE UINT8 count_leading_zeros(UINT32 val)
258
 
{
259
 
        UINT8 count;
260
 
        for (count = 0; (INT32)val >= 0; count++) val <<= 1;
261
 
        return count;
262
 
}
263
 
#endif
264
 
 
265
 
 
266
 
/*-------------------------------------------------
267
 
    count_leading_ones - return the number of
268
 
    leading one bits in a 32-bit value
269
 
-------------------------------------------------*/
270
 
 
271
 
#ifndef count_leading_ones
272
 
INLINE UINT8 count_leading_ones(UINT32 val)
273
 
{
274
 
        UINT8 count;
275
 
        for (count = 0; (INT32)val < 0; count++) val <<= 1;
276
 
        return count;
277
 
}
278
 
#endif
279
 
 
280
 
 
281
 
 
282
 
/***************************************************************************
283
 
    INLINE SYNCHRONIZATION FUNCTIONS
284
 
***************************************************************************/
285
 
 
286
 
/*-------------------------------------------------
287
 
    compare_exchange32 - compare the 'compare'
288
 
    value against the memory at 'ptr'; if equal,
289
 
    swap in the 'exchange' value. Regardless,
290
 
    return the previous value at 'ptr'.
291
 
 
292
 
    Note that the default implementation does
293
 
    no synchronization. You MUST override this
294
 
    in osinline.h for it to be useful in a
295
 
    multithreaded environment!
296
 
-------------------------------------------------*/
297
 
 
298
 
#ifndef compare_exchange32
299
 
INLINE INT32 compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
300
 
{
301
 
        INT32 oldval = *ptr;
302
 
        if (*ptr == compare)
303
 
                *ptr = exchange;
304
 
        return oldval;
305
 
}
306
 
#endif
307
 
 
308
 
 
309
 
/*-------------------------------------------------
310
 
    compare_exchange64 - compare the 'compare'
311
 
    value against the memory at 'ptr'; if equal,
312
 
    swap in the 'exchange' value. Regardless,
313
 
    return the previous value at 'ptr'.
314
 
 
315
 
    Note that the default implementation does
316
 
    no synchronization. You MUST override this
317
 
    in osinline.h for it to be useful in a
318
 
    multithreaded environment!
319
 
-------------------------------------------------*/
320
 
 
321
 
#ifdef PTR64
322
 
#ifndef compare_exchange64
323
 
INLINE INT64 compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
324
 
{
325
 
        INT64 oldval = *ptr;
326
 
        if (*ptr == compare)
327
 
                *ptr = exchange;
328
 
        return oldval;
329
 
}
330
 
#endif
331
 
#endif
332
 
 
333
 
 
334
 
/*-------------------------------------------------
335
 
    compare_exchange_ptr - compare the 'compare'
336
 
    value against the memory at 'ptr'; if equal,
337
 
    swap in the 'exchange' value. Regardless,
338
 
    return the previous value at 'ptr'.
339
 
-------------------------------------------------*/
340
 
 
341
 
#ifndef compare_exchange_ptr
342
 
INLINE void *compare_exchange_ptr(void * volatile *ptr, void *compare, void *exchange)
343
 
{
344
 
#ifdef PTR64
345
 
        INT64 result;
346
 
        result = compare_exchange64((INT64 volatile *)ptr, (INT64)compare, (INT64)exchange);
347
 
#else
348
 
        INT32 result;
349
 
        result = compare_exchange32((INT32 volatile *)ptr, (INT32)compare, (INT32)exchange);
350
 
#endif
351
 
        return (void *)result;
352
 
}
353
 
#endif
354
 
 
355
 
 
356
 
/*-------------------------------------------------
357
 
    atomic_exchange32 - atomically exchange the
358
 
    exchange value with the memory at 'ptr',
359
 
    returning the original value.
360
 
 
361
 
    Note that the default implementation does
362
 
    no synchronization. You MUST override this
363
 
    in osinline.h for it to be useful in a
364
 
    multithreaded environment!
365
 
-------------------------------------------------*/
366
 
 
367
 
#ifndef atomic_exchange32
368
 
INLINE INT32 atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
369
 
{
370
 
        INT32 oldval = *ptr;
371
 
        *ptr = exchange;
372
 
        return oldval;
373
 
}
374
 
#endif
375
 
 
376
 
 
377
 
/*-------------------------------------------------
378
 
    atomic_add32 - atomically add the delta value
379
 
    to the memory at 'ptr', returning the final
380
 
    result.
381
 
 
382
 
    Note that the default implementation does
383
 
    no synchronization. You MUST override this
384
 
    in osinline.h for it to be useful in a
385
 
    multithreaded environment!
386
 
-------------------------------------------------*/
387
 
 
388
 
#ifndef atomic_add32
389
 
INLINE INT32 atomic_add32(INT32 volatile *ptr, INT32 delta)
390
 
{
391
 
        return (*ptr += delta);
392
 
}
393
 
#endif
394
 
 
395
 
 
396
 
/*-------------------------------------------------
397
 
    atomic_increment32 - atomically increment the
398
 
    32-bit value in memory at 'ptr', returning the
399
 
    final result.
400
 
 
401
 
    Note that the default implementation does
402
 
    no synchronization. You MUST override this
403
 
    in osinline.h for it to be useful in a
404
 
    multithreaded environment!
405
 
-------------------------------------------------*/
406
 
 
407
 
#ifndef atomic_increment32
408
 
INLINE INT32 atomic_increment32(INT32 volatile *ptr)
409
 
{
410
 
        return atomic_add32(ptr, 1);
411
 
}
412
 
#endif
413
 
 
414
 
 
415
 
/*-------------------------------------------------
416
 
    atomic_decrement32 - atomically decrement the
417
 
    32-bit value in memory at 'ptr', returning the
418
 
    final result.
419
 
 
420
 
    Note that the default implementation does
421
 
    no synchronization. You MUST override this
422
 
    in osinline.h for it to be useful in a
423
 
    multithreaded environment!
424
 
-------------------------------------------------*/
425
 
 
426
 
#ifndef atomic_decrement32
427
 
INLINE INT32 atomic_decrement32(INT32 volatile *ptr)
428
 
{
429
 
        return atomic_add32(ptr, -1);
430
 
}
431
 
#endif
432
 
 
433
 
 
434
 
 
435
 
/***************************************************************************
436
 
    INLINE TIMING FUNCTIONS
437
 
***************************************************************************/
438
 
 
439
 
/*-------------------------------------------------
440
 
    get_profile_ticks - return a tick counter
441
 
    from the processor that can be used for
442
 
    profiling. It does not need to run at any
443
 
    particular rate.
444
 
-------------------------------------------------*/
445
 
 
446
 
#ifndef get_profile_ticks
447
 
INLINE INT64 get_profile_ticks(void)
448
 
{
449
 
        return osd_ticks();
450
 
}
451
 
#endif
452
 
 
453
 
#endif /* __EMINLINE__ */