summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2007-12-17 16:33:33 +0000
committer Aaron Giles <aaron@aarongiles.com>2007-12-17 16:33:33 +0000
commit8a8ccc594989d85f2277c48d3c158f7cee41d06b (patch)
tree821ddcb66109a2340909394308a4b348d4cb2a53 /src/osd
parent7b77f1218624ea26dbb2efd85a19f795f5d4e02e (diff)
Changes for MAME 0.121u1.mame0121u1
Diffstat (limited to 'src/osd')
-rw-r--r--src/osd/windows/eivc.h158
-rw-r--r--src/osd/windows/eivcx86.h463
-rw-r--r--src/osd/windows/osinline.h552
-rw-r--r--src/osd/windows/vconv.c6
-rw-r--r--src/osd/windows/winalloc.c164
-rw-r--r--src/osd/windows/windows.mak2
-rw-r--r--src/osd/windows/winsync.c33
7 files changed, 766 insertions, 612 deletions
diff --git a/src/osd/windows/eivc.h b/src/osd/windows/eivc.h
new file mode 100644
index 00000000000..b8a9ce320ba
--- /dev/null
+++ b/src/osd/windows/eivc.h
@@ -0,0 +1,158 @@
+//============================================================
+//
+// eivc.h
+//
+// Inline implementations for MSVC compiler.
+//
+// Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+//============================================================
+
+#ifndef __EIVC__
+#define __EIVC__
+
+#ifdef PTR64
+#include <intrin.h>
+#pragma intrinsic(_BitScanReverse)
+#else
+#pragma intrinsic(_InterlockedCompareExchange)
+#pragma intrinsic(_InterlockedExchange)
+#pragma intrinsic(_InterlockedExchangeAdd)
+#endif
+
+
+/***************************************************************************
+ INLINE BIT MANIPULATION FUNCTIONS
+***************************************************************************/
+
+/*-------------------------------------------------
+ count_leading_zeros - return the number of
+ leading zero bits in a 32-bit value
+-------------------------------------------------*/
+
+#ifndef count_leading_zeros
+#define count_leading_zeros _count_leading_zeros
+INLINE UINT8 _count_leading_zeros(UINT32 value)
+{
+ UINT32 index;
+ return _BitScanReverse(&index, value) ? (index ^ 31) : 32;
+}
+#endif
+
+
+/*-------------------------------------------------
+ count_leading_ones - return the number of
+ leading one bits in a 32-bit value
+-------------------------------------------------*/
+
+#ifndef count_leading_ones
+#define count_leading_ones _count_leading_ones
+INLINE UINT8 _count_leading_ones(UINT32 value)
+{
+ UINT32 index;
+ return _BitScanReverse(&index, ~value) ? (index ^ 31) : 32;
+}
+#endif
+
+
+
+/***************************************************************************
+ INLINE SYNCHRONIZATION FUNCTIONS
+***************************************************************************/
+
+/*-------------------------------------------------
+ compare_exchange32 - compare the 'compare'
+ value against the memory at 'ptr'; if equal,
+ swap in the 'exchange' value. Regardless,
+ return the previous value at 'ptr'.
+-------------------------------------------------*/
+
+#ifndef compare_exchange32
+#define compare_exchange32 _compare_exchange32
+INLINE INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
+{
+ return _InterlockedCompareExchange(ptr, exchange, compare);
+}
+#endif
+
+
+/*-------------------------------------------------
+ compare_exchange64 - compare the 'compare'
+ value against the memory at 'ptr'; if equal,
+ swap in the 'exchange' value. Regardless,
+ return the previous value at 'ptr'.
+-------------------------------------------------*/
+
+#ifdef PTR64
+#ifndef compare_exchange64
+#define compare_exchange64 _compare_exchange64
+INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
+{
+ return _InterlockedCompareExchange64(ptr, exchange, compare);
+}
+#endif
+#endif
+
+
+/*-------------------------------------------------
+ atomic_exchange32 - atomically exchange the
+ exchange value with the memory at 'ptr',
+ returning the original value.
+-------------------------------------------------*/
+
+#ifndef atomic_exchange32
+#define atomic_exchange32 _atomic_exchange32
+INLINE INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
+{
+ return _InterlockedExchange(ptr, exchange);
+}
+#endif
+
+
+/*-------------------------------------------------
+ atomic_add32 - atomically add the delta value
+ to the memory at 'ptr', returning the final
+ result.
+-------------------------------------------------*/
+
+#ifndef atomic_add32
+#define atomic_add32 _atomic_add32
+INLINE INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
+{
+ return _InterlockedExchangeAdd(ptr, delta) + delta;
+}
+#endif
+
+
+/*-------------------------------------------------
+ atomic_increment32 - atomically increment the
+ 32-bit value in memory at 'ptr', returning the
+ final result.
+-------------------------------------------------*/
+
+#ifndef atomic_increment32
+#define atomic_increment32 _atomic_increment32
+INLINE INT32 _atomic_increment32(INT32 volatile *ptr)
+{
+ return _InterlockedIncrement(ptr);
+}
+#endif
+
+
+/*-------------------------------------------------
+ atomic_decrement32 - atomically decrement the
+ 32-bit value in memory at 'ptr', returning the
+ final result.
+-------------------------------------------------*/
+
+#ifndef atomic_decrement32
+#define atomic_decrement32 _atomic_decrement32
+INLINE INT32 _atomic_decrement32(INT32 volatile *ptr)
+{
+ return _InterlockedDecrement(ptr);
+}
+#endif
+
+
+#endif /* __EIVC__ */
diff --git a/src/osd/windows/eivcx86.h b/src/osd/windows/eivcx86.h
new file mode 100644
index 00000000000..fb40091dd9a
--- /dev/null
+++ b/src/osd/windows/eivcx86.h
@@ -0,0 +1,463 @@
+//============================================================
+//
+// eivcx86.h
+//
+// x86 inline implementations for MSVC compiler.
+//
+// Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
+// Visit http://mamedev.org for licensing and usage restrictions.
+//
+//============================================================
+
+#ifndef __EIVCX86__
+#define __EIVCX86__
+
+#ifdef PTR64
+#include <emmintrin.h>
+#endif
+
+
+/***************************************************************************
+ INLINE MATH FUNCTIONS
+***************************************************************************/
+
+/*-------------------------------------------------
+ mul_32x32 - perform a signed 32 bit x 32 bit
+ multiply and return the full 64 bit result
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mul_32x32 _mul_32x32
+INLINE INT64 _mul_32x32(INT32 a, INT32 b)
+{
+ // in theory this should work, but it is untested
+ __asm
+ {
+ mov eax,a
+ imul b
+ // leave results in edx:eax
+ }
+}
+#endif
+
+
+/*-------------------------------------------------
+ mulu_32x32 - perform an unsigned 32 bit x
+ 32 bit multiply and return the full 64 bit
+ result
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mulu_32x32 _mulu_32x32
+INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b)
+{
+ // in theory this should work, but it is untested
+ __asm
+ {
+ mov eax,a
+ mul b
+ // leave results in edx:eax
+ }
+}
+#endif
+
+
+/*-------------------------------------------------
+ mul_32x32_hi - perform a signed 32 bit x 32 bit
+ multiply and return the upper 32 bits of the
+ result
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mul_32x32_hi _mul_32x32_hi
+INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,a
+ imul b
+ mov result,edx
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ mulu_32x32_hi - perform an unsigned 32 bit x
+ 32 bit multiply and return the upper 32 bits
+ of the result
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mulu_32x32_hi _mulu_32x32_hi
+INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,a
+ mul b
+ mov result,edx
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ mul_32x32_shift - perform a signed 32 bit x
+ 32 bit multiply and shift the result by the
+ given number of bits before truncating the
+ result to 32 bits
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mul_32x32_shift _mul_32x32_shift
+INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,a
+ imul b
+ mov cl,shift
+ shrd eax,edx,cl
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ mulu_32x32_shift - perform an unsigned 32 bit x
+ 32 bit multiply and shift the result by the
+ given number of bits before truncating the
+ result to 32 bits
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mulu_32x32_shift _mulu_32x32_shift
+INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,a
+ mul b
+ mov cl,shift
+ shrd eax,edx,cl
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ div_64x32 - perform a signed 64 bit x 32 bit
+ divide and return the 32 bit quotient
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define div_64x32 _div_64x32
+INLINE INT32 _div_64x32(INT64 a, INT32 b)
+{
+ INT32 result;
+ INT32 alow = a;
+ INT32 ahigh = a >> 32;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ idiv b
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ divu_64x32 - perform an unsigned 64 bit x 32 bit
+ divide and return the 32 bit quotient
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define divu_64x32 _divu_64x32
+INLINE UINT32 _divu_64x32(UINT64 a, UINT32 b)
+{
+ UINT32 result;
+ UINT32 alow = a;
+ UINT32 ahigh = a >> 32;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ div b
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ div_64x32_rem - perform a signed 64 bit x 32
+ bit divide and return the 32 bit quotient and
+ 32 bit remainder
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define div_64x32_rem _div_64x32_rem
+INLINE INT32 _div_64x32_rem(INT64 a, INT32 b, INT32 *remainder)
+{
+ INT32 result;
+ INT32 alow = a;
+ INT32 ahigh = a >> 32;
+ INT32 rem;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ idiv b
+ mov result,eax
+ mov rem,edx
+ }
+
+ *remainder = rem;
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ divu_64x32_rem - perform an unsigned 64 bit x
+ 32 bit divide and return the 32 bit quotient
+ and 32 bit remainder
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define divu_64x32_rem _divu_64x32_rem
+INLINE UINT32 _divu_64x32_rem(UINT64 a, UINT32 b, UINT32 *remainder)
+{
+ UINT32 result;
+ UINT32 alow = a;
+ UINT32 ahigh = a >> 32;
+ UINT32 rem;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ div b
+ mov result,eax
+ mov rem,edx
+ }
+
+ *remainder = rem;
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ div_32x32_shift - perform a signed divide of
+ two 32 bit values, shifting the first before
+ division, and returning the 32 bit quotient
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define div_32x32_shift _div_32x32_shift
+INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,a
+ cdq
+ mov cl,shift
+ shld edx,eax,cl
+ shl eax,cl
+ idiv b
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ divu_32x32_shift - perform an unsigned divide of
+ two 32 bit values, shifting the first before
+ division, and returning the 32 bit quotient
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define divu_32x32_shift _divu_32x32_shift
+INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
+{
+ UINT32 result;
+
+ __asm
+ {
+ mov eax,a
+ xor edx,edx
+ mov cl,shift
+ shld edx,eax,cl
+ shl eax,cl
+ div b
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ mod_64x32 - perform a signed 64 bit x 32 bit
+ divide and return the 32 bit remainder
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define mod_64x32 _mod_64x32
+INLINE INT32 _mod_64x32(INT64 a, INT32 b)
+{
+ INT32 result;
+ INT32 alow = a;
+ INT32 ahigh = a >> 32;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ idiv b
+ mov result,edx
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ modu_64x32 - perform an unsigned 64 bit x 32 bit
+ divide and return the 32 bit remainder
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define modu_64x32 _modu_64x32
+INLINE UINT32 _modu_64x32(UINT64 a, UINT32 b)
+{
+ UINT32 result;
+ UINT32 alow = a;
+ UINT32 ahigh = a >> 32;
+
+ __asm
+ {
+ mov eax,alow
+ mov edx,ahigh
+ div b
+ mov result,edx
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ recip_approx - compute an approximate floating
+ point reciprocal
+-------------------------------------------------*/
+
+#ifdef PTR64
+#define recip_approx _recip_approx
+INLINE float _recip_approx(float z)
+{
+ __m128 mz = _mm_set_ss(z);
+ __m128 mooz = _mm_rcp_ss(mz);
+ float ooz;
+ _mm_store_ss(&ooz, mooz);
+ return ooz;
+}
+#endif
+
+
+
+/***************************************************************************
+ INLINE BIT MANIPULATION FUNCTIONS
+***************************************************************************/
+
+/*-------------------------------------------------
+ count_leading_zeros - return the number of
+ leading zero bits in a 32-bit value
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define count_leading_zeros _count_leading_zeros
+INLINE UINT8 _count_leading_zeros(UINT32 value)
+{
+ INT32 result;
+
+ __asm
+ {
+ bsr eax,value
+ jnz skip
+ mov eax,63
+ skip:
+ xor eax,31
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+
+/*-------------------------------------------------
+ count_leading_ones - return the number of
+ leading one bits in a 32-bit value
+-------------------------------------------------*/
+
+#ifndef PTR64
+#define count_leading_ones _count_leading_ones
+INLINE UINT8 _count_leading_ones(UINT32 value)
+{
+ INT32 result;
+
+ __asm
+ {
+ mov eax,value
+ not eax
+ bsr eax,eax
+ jnz skip
+ mov eax,63
+ skip:
+ xor eax,31
+ mov result,eax
+ }
+
+ return result;
+}
+#endif
+
+#endif /* __EIVCX86__ */
diff --git a/src/osd/windows/osinline.h b/src/osd/windows/osinline.h
index e6131724886..6839638a7a9 100644
--- a/src/osd/windows/osinline.h
+++ b/src/osd/windows/osinline.h
@@ -2,7 +2,7 @@
//
// osinline.h
//
-// x86 inline implementations for MSVC compiler.
+// Inline implementations for non-GCC Win32 compilers
//
// Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
// Visit http://mamedev.org for licensing and usage restrictions.
@@ -12,551 +12,41 @@
#ifndef __OSINLINE__
#define __OSINLINE__
-#ifdef PTR64
-#include <intrin.h>
-#pragma intrinsic(_BitScanReverse)
-#else
-#pragma intrinsic(_InterlockedCompareExchange)
-#pragma intrinsic(_InterlockedExchange)
-#pragma intrinsic(_InterlockedExchangeAdd)
-#endif
-
-
-/***************************************************************************
- INLINE MATH FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- mul_32x32 - perform a signed 32 bit x 32 bit
- multiply and return the full 64 bit result
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mul_32x32 _mul_32x32
-INLINE INT64 _mul_32x32(INT32 a, INT32 b)
-{
- // in theory this should work, but it is untested
- __asm
- {
- mov eax,a
- imul b
- // leave results in edx:eax
- }
-}
-#endif
-
-
-/*-------------------------------------------------
- mulu_32x32 - perform an unsigned 32 bit x
- 32 bit multiply and return the full 64 bit
- result
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mulu_32x32 _mulu_32x32
-INLINE UINT64 _mulu_32x32(UINT32 a, UINT32 b)
-{
- // in theory this should work, but it is untested
- __asm
- {
- mov eax,a
- mul b
- // leave results in edx:eax
- }
-}
-#endif
-
-
-/*-------------------------------------------------
- mul_32x32_hi - perform a signed 32 bit x 32 bit
- multiply and return the upper 32 bits of the
- result
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mul_32x32_hi _mul_32x32_hi
-INLINE INT32 _mul_32x32_hi(INT32 a, INT32 b)
-{
- INT32 result;
-
- __asm
- {
- mov eax,a
- imul b
- mov result,edx
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- mulu_32x32_hi - perform an unsigned 32 bit x
- 32 bit multiply and return the upper 32 bits
- of the result
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mulu_32x32_hi _mulu_32x32_hi
-INLINE UINT32 _mulu_32x32_hi(UINT32 a, UINT32 b)
-{
- INT32 result;
-
- __asm
- {
- mov eax,a
- mul b
- mov result,edx
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- mul_32x32_shift - perform a signed 32 bit x
- 32 bit multiply and shift the result by the
- given number of bits before truncating the
- result to 32 bits
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mul_32x32_shift _mul_32x32_shift
-INLINE INT32 _mul_32x32_shift(INT32 a, INT32 b, UINT8 shift)
-{
- INT32 result;
-
- __asm
- {
- mov eax,a
- imul b
- mov cl,shift
- shrd eax,edx,cl
- mov result,eax
- }
-
- return result;
-}
+#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
+#include "eivcx86.h"
#endif
-
-/*-------------------------------------------------
- mulu_32x32_shift - perform an unsigned 32 bit x
- 32 bit multiply and shift the result by the
- given number of bits before truncating the
- result to 32 bits
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mulu_32x32_shift _mulu_32x32_shift
-INLINE UINT32 _mulu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
-{
- INT32 result;
-
- __asm
- {
- mov eax,a
- mul b
- mov cl,shift
- shrd eax,edx,cl
- mov result,eax
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- div_64x32 - perform a signed 64 bit x 32 bit
- divide and return the 32 bit quotient
--------------------------------------------------*/
-
-#ifndef PTR64
-#define div_64x32 _div_64x32
-INLINE INT32 _div_64x32(INT64 a, INT32 b)
-{
- INT32 result;
- INT32 alow = a;
- INT32 ahigh = a >> 32;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- idiv b
- mov result,eax
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- divu_64x32 - perform an unsigned 64 bit x 32 bit
- divide and return the 32 bit quotient
--------------------------------------------------*/
-
-#ifndef PTR64
-#define divu_64x32 _divu_64x32
-INLINE UINT32 _divu_64x32(UINT64 a, UINT32 b)
-{
- UINT32 result;
- UINT32 alow = a;
- UINT32 ahigh = a >> 32;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- div b
- mov result,eax
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- div_64x32_rem - perform a signed 64 bit x 32
- bit divide and return the 32 bit quotient and
- 32 bit remainder
--------------------------------------------------*/
-
-#ifndef PTR64
-#define div_64x32_rem _div_64x32_rem
-INLINE INT32 _div_64x32_rem(INT64 a, INT32 b, INT32 *remainder)
-{
- INT32 result;
- INT32 alow = a;
- INT32 ahigh = a >> 32;
- INT32 rem;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- idiv b
- mov result,eax
- mov rem,edx
- }
-
- *remainder = rem;
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- divu_64x32_rem - perform an unsigned 64 bit x
- 32 bit divide and return the 32 bit quotient
- and 32 bit remainder
--------------------------------------------------*/
-
-#ifndef PTR64
-#define divu_64x32_rem _divu_64x32_rem
-INLINE UINT32 _divu_64x32_rem(UINT64 a, UINT32 b, UINT32 *remainder)
-{
- UINT32 result;
- UINT32 alow = a;
- UINT32 ahigh = a >> 32;
- UINT32 rem;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- div b
- mov result,eax
- mov rem,edx
- }
-
- *remainder = rem;
- return result;
-}
+#if defined(_MSC_VER)
+#include "eivc.h"
#endif
-
-/*-------------------------------------------------
- div_32x32_shift - perform a signed divide of
- two 32 bit values, shifting the first before
- division, and returning the 32 bit quotient
--------------------------------------------------*/
-
-#ifndef PTR64
-#define div_32x32_shift _div_32x32_shift
-INLINE INT32 _div_32x32_shift(INT32 a, INT32 b, UINT8 shift)
-{
- INT32 result;
-
- __asm
- {
- mov eax,a
- cdq
- mov cl,shift
- shld edx,eax,cl
- shl eax,cl
- idiv b
- mov result,eax
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- divu_32x32_shift - perform an unsigned divide of
- two 32 bit values, shifting the first before
- division, and returning the 32 bit quotient
--------------------------------------------------*/
-
-#ifndef PTR64
-#define divu_32x32_shift _divu_32x32_shift
-INLINE UINT32 _divu_32x32_shift(UINT32 a, UINT32 b, UINT8 shift)
-{
- UINT32 result;
-
- __asm
- {
- mov eax,a
- xor edx,edx
- mov cl,shift
- shld edx,eax,cl
- shl eax,cl
- div b
- mov result,eax
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- mod_64x32 - perform a signed 64 bit x 32 bit
- divide and return the 32 bit remainder
--------------------------------------------------*/
-
-#ifndef PTR64
-#define mod_64x32 _mod_64x32
-INLINE INT32 _mod_64x32(INT64 a, INT32 b)
-{
- INT32 result;
- INT32 alow = a;
- INT32 ahigh = a >> 32;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- idiv b
- mov result,edx
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- modu_64x32 - perform an unsigned 64 bit x 32 bit
- divide and return the 32 bit remainder
--------------------------------------------------*/
-
-#ifndef PTR64
-#define modu_64x32 _modu_64x32
-INLINE UINT32 _modu_64x32(UINT64 a, UINT32 b)
-{
- UINT32 result;
- UINT32 alow = a;
- UINT32 ahigh = a >> 32;
-
- __asm
- {
- mov eax,alow
- mov edx,ahigh
- div b
- mov result,edx
- }
-
- return result;
-}
-#endif
-
-
-/*-------------------------------------------------
- recip_approx - compute an approximate floating
- point reciprocal
--------------------------------------------------*/
+INT32 win_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange);
+INT32 win_atomic_exchange32(INT32 volatile *ptr, INT32 exchange);
+INT32 win_atomic_add32(INT32 volatile *ptr, INT32 delta);
#ifdef PTR64
-#define recip_approx _recip_approx
-INLINE float _recip_approx(float z)
-{
- __m128 mz = _mm_set_ss(z);
- __m128 mooz = _mm_rcp_ss(mz);
- float ooz;
- _mm_store_ss(&ooz, mooz);
- return ooz;
-}
+INT64 win_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange);
#endif
+#ifndef compare_exchange32
+#define compare_exchange32 win_compare_exchange32
+#endif /* compare_exchange32 */
-/***************************************************************************
- INLINE BIT MANIPULATION FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- count_leading_zeros - return the number of
- leading zero bits in a 32-bit value
--------------------------------------------------*/
-
-#define count_leading_zeros _count_leading_zeros
-INLINE UINT8 _count_leading_zeros(UINT32 value)
-{
#ifdef PTR64
- UINT32 index;
- return _BitScanReverse(&index, value) ? (index ^ 31) : 32;
-#else
- INT32 result;
-
- __asm
- {
- bsr eax,value
- jnz skip
- mov eax,63
- skip:
- xor eax,31
- mov result,eax
- }
-
- return result;
-#endif
-}
-
-
-/*-------------------------------------------------
- count_leading_ones - return the number of
- leading one bits in a 32-bit value
--------------------------------------------------*/
-
-#define count_leading_ones _count_leading_ones
-INLINE UINT8 _count_leading_ones(UINT32 value)
-{
-#ifdef PTR64
- UINT32 index;
- return _BitScanReverse(&index, ~value) ? (index ^ 31) : 32;
-#else
- INT32 result;
-
- __asm
- {
- mov eax,value
- not eax
- bsr eax,eax
- jnz skip
- mov eax,63
- skip:
- xor eax,31
- mov result,eax
- }
-
- return result;
+#ifndef compare_exchange64
+#define compare_exchange64 win_compare_exchange64
+#endif /* compare_exchange64 */
#endif
-}
-
-
-
-/***************************************************************************
- INLINE SYNCHRONIZATION FUNCTIONS
-***************************************************************************/
-
-/*-------------------------------------------------
- compare_exchange32 - compare the 'compare'
- value against the memory at 'ptr'; if equal,
- swap in the 'exchange' value. Regardless,
- return the previous value at 'ptr'.
--------------------------------------------------*/
-
-#define compare_exchange32 _compare_exchange32
-INLINE INT32 _compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
-{
- return _InterlockedCompareExchange(ptr, exchange, compare);
-}
-
-
-/*-------------------------------------------------
- compare_exchange64 - compare the 'compare'
- value against the memory at 'ptr'; if equal,
- swap in the 'exchange' value. Regardless,
- return the previous value at 'ptr'.
--------------------------------------------------*/
-
-#ifdef PTR64
-#define compare_exchange64 _compare_exchange64
-INLINE INT64 _compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
-{
- return _InterlockedCompareExchange64(ptr, exchange, compare);
-}
-#endif
-
-
-/*-------------------------------------------------
- atomic_exchange32 - atomically exchange the
- exchange value with the memory at 'ptr',
- returning the original value.
--------------------------------------------------*/
-
-#define atomic_exchange32 _atomic_exchange32
-INLINE INT32 _atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
-{
- return _InterlockedExchange(ptr, exchange);
-}
-
-
-/*-------------------------------------------------
- atomic_add32 - atomically add the delta value
- to the memory at 'ptr', returning the final
- result.
--------------------------------------------------*/
-
-#define atomic_add32 _atomic_add32
-INLINE INT32 _atomic_add32(INT32 volatile *ptr, INT32 delta)
-{
- return _InterlockedExchangeAdd(ptr, delta) + delta;
-}
-
-
-/*-------------------------------------------------
- atomic_increment32 - atomically increment the
- 32-bit value in memory at 'ptr', returning the
- final result.
--------------------------------------------------*/
-
-#define atomic_increment32 _atomic_increment32
-INLINE INT32 _atomic_increment32(INT32 volatile *ptr)
-{
- return _InterlockedIncrement(ptr);
-}
+#ifndef atomic_exchange32
+#define atomic_exchange32 win_atomic_exchange32
+#endif /* atomic_exchange32 */
-/*-------------------------------------------------
- atomic_decrement32 - atomically decrement the
- 32-bit value in memory at 'ptr', returning the
- final result.
--------------------------------------------------*/
-#define atomic_decrement32 _atomic_decrement32
-INLINE INT32 _atomic_decrement32(INT32 volatile *ptr)
-{
- return _InterlockedDecrement(ptr);
-}
+#ifndef atomic_add32
+#define atomic_add32 win_atomic_add32
+#endif /* atomic_add32 */
#endif /* __OSINLINE__ */
diff --git a/src/osd/windows/vconv.c b/src/osd/windows/vconv.c
index 2f034f2d369..039dcb082f3 100644
--- a/src/osd/windows/vconv.c
+++ b/src/osd/windows/vconv.c
@@ -74,13 +74,15 @@ static const translation_info gcc_translate[] =
{ 0, "-W*", "" },
{ VS2005, "-march=*", "" }, // deprecated in VS2005
{ 0, "-march=pentium", "/G5" },
- { 0, "-march=athlon", "/G7" },
{ 0, "-march=pentiumpro", "/G6" },
+ { 0, "-march=pentium3", "/G6" },
+ { 0, "-march=pentium-m", "/G6" },
+ { 0, "-march=athlon", "/G7" },
{ 0, "-march=pentium4", "/G7" },
{ 0, "-march=athlon64", "/G7" },
- { 0, "-march=pentium3", "/G6" },
{ VS71, "-msse2", "/arch:SSE2" },
{ 0, "-msse2", "" },
+ { 0, "-msse3", "" },
{ 0, "-mwindows", "" },
{ 0, "-mno-cygwin", "" },
{ 0, "-std=gnu89", "" },
diff --git a/src/osd/windows/winalloc.c b/src/osd/windows/winalloc.c
index a355ebca3c8..c54eda5e768 100644
--- a/src/osd/windows/winalloc.c
+++ b/src/osd/windows/winalloc.c
@@ -30,9 +30,6 @@
#define PAGE_SIZE 4096
#define COOKIE_VAL 0x11335577
-// set this to 0 to not use guard pages
-#define USE_GUARD_PAGES 1
-
// set this to 1 to align memory blocks to the start of a page;
// otherwise, they are aligned to the end, thus catching array
// overruns
@@ -188,6 +185,20 @@ INLINE void free_entry(memory_entry *entry)
}
+INLINE int use_malloc_tracking(void)
+{
+#ifdef MESS
+ extern BOOL win_is_gui_application(void);
+ return !win_is_gui_application();
+#elif defined(WINUI)
+ return FALSE;
+#else
+ return TRUE;
+#endif
+
+}
+
+
//============================================================
// IMPLEMENTATION
@@ -195,12 +206,15 @@ INLINE void free_entry(memory_entry *entry)
void *malloc_file_line(size_t size, const char *file, int line)
{
- UINT8 *page_base, *block_base;
- size_t rounded_size;
- memory_entry *entry;
+ UINT8 *block_base;
+ int id = current_id++;
- if (USE_GUARD_PAGES)
+ if (use_malloc_tracking())
{
+ UINT8 *page_base;
+ size_t rounded_size;
+ memory_entry *entry;
+
// round the size up to a page boundary
rounded_size = ((size + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
@@ -219,29 +233,27 @@ void *malloc_file_line(size_t size, const char *file, int line)
block_base = page_base;
else
block_base = page_base + rounded_size - size;
+
+ // fill in the entry
+ entry = allocate_entry();
+ entry->size = size;
+ entry->base = block_base;
+ entry->file = file;
+ entry->line = line;
+ entry->id = id;
}
else
{
block_base = (UINT8 *)GlobalAlloc(GMEM_FIXED, size);
}
- // fill in the entry
- entry = allocate_entry();
- entry->size = size;
- entry->base = block_base;
- entry->file = file;
- entry->line = line;
- entry->id = current_id++;
-
-//if (entry->size == 72 && IsDebuggerPresent()) DebugBreak();
-
#if LOG_CALLS
// logging
- if (entry->file)
- logerror("malloc #%06d size = %d (%s:%d)\n", entry->size, entry->file, entry->line);
+ if (file != NULL)
+ logerror("malloc #%06d size = %d (%s:%d)\n", id, size, file, line);
else
- logerror("malloc #%06d size = %d\n", entry->id, entry->size);
-#endif
+ logerror("malloc #%06d size = %d\n", id, size);
+#endif // LOG_CALLS
return block_base;
}
@@ -283,34 +295,41 @@ void *realloc_file_line(void *memory, size_t size, const char *file, int line)
{
void *newmemory = NULL;
- // if size is non-zero, we need to reallocate memory
- if (size != 0)
+ if (use_malloc_tracking())
{
- // allocate space for the new amount
- newmemory = malloc_file_line(size, file, line);
- if (newmemory == NULL)
- return NULL;
-
- // if we have an old pointer, copy it
- if (memory != NULL)
+ // if size is non-zero, we need to reallocate memory
+ if (size != 0)
{
- memory_entry *entry = find_entry(memory);
- if (entry == NULL)
+ // allocate space for the new amount
+ newmemory = malloc_file_line(size, file, line);
+ if (newmemory == NULL)
+ return NULL;
+
+ // if we have an old pointer, copy it
+ if (memory != NULL)
{
- if (winalloc_in_main_code)
+ memory_entry *entry = find_entry(memory);
+ if (entry == NULL)
{
- fprintf(stderr, "Error: realloc a non-existant block (%s:%d)\n", file, line);
- osd_break_into_debugger("Error: realloc a non-existant block\n");
+ if (winalloc_in_main_code)
+ {
+ fprintf(stderr, "Error: realloc a non-existant block (%s:%d)\n", file, line);
+ osd_break_into_debugger("Error: realloc a non-existant block\n");
+ }
}
+ else
+ memcpy(newmemory, memory, (size < entry->size) ? size : entry->size);
}
- else
- memcpy(newmemory, memory, (size < entry->size) ? size : entry->size);
}
- }
- // if we have an original pointer, free it
- if (memory != NULL)
- free(memory);
+ // if we have an original pointer, free it
+ if (memory != NULL)
+ free(memory);
+ }
+ else
+ {
+ newmemory = (void *) GlobalReAlloc(memory, size, GMEM_MOVEABLE);
+ }
return newmemory;
}
@@ -330,28 +349,32 @@ void CLIB_DECL free(void *memory)
if (memory == NULL)
return;
- // error if no entry found
- entry = find_entry(memory);
- if (entry == NULL)
+ if (use_malloc_tracking())
{
- if (winalloc_in_main_code)
+ // error if no entry found
+ entry = find_entry(memory);
+ if (entry == NULL)
{
- fprintf(stderr, "Error: free a non-existant block\n");
- osd_break_into_debugger("Error: free a non-existant block");
+ if (winalloc_in_main_code)
+ {
+ fprintf(stderr, "Error: free a non-existant block\n");
+ osd_break_into_debugger("Error: free a non-existant block");
+ }
+ return;
}
- return;
- }
- free_entry(entry);
+ free_entry(entry);
- // free the memory
- if (USE_GUARD_PAGES)
+ // free the memory
VirtualFree((UINT8 *)memory - ((size_t)memory & (PAGE_SIZE-1)) - PAGE_SIZE, 0, MEM_RELEASE);
- else
- GlobalFree(memory);
#if LOG_CALLS
- logerror("free #%06d size = %d\n", entry->id, entry->size);
-#endif
+ logerror("free #%06d size = %d\n", entry->id, entry->size);
+#endif // LOG_CALLS
+ }
+ else
+ {
+ GlobalFree(memory);
+ }
}
@@ -376,20 +399,23 @@ void check_unfreed_mem(void)
memory_entry *entry;
int total = 0;
- memory_lock_acquire();
+ if (use_malloc_tracking())
+ {
+ memory_lock_acquire();
- // check for leaked memory
- for (entry = alloc_list; entry; entry = entry->next)
- if (entry->file != NULL)
- {
- if (total == 0)
- fprintf(stderr, "--- memory leak warning ---\n");
- total += entry->size;
- fprintf(stderr, "allocation #%06d, %d bytes (%s:%d)\n", entry->id, entry->size, entry->file, entry->line);
- }
+ // check for leaked memory
+ for (entry = alloc_list; entry; entry = entry->next)
+ if (entry->file != NULL)
+ {
+ if (total == 0)
+ fprintf(stderr, "--- memory leak warning ---\n");
+ total += entry->size;
+ fprintf(stderr, "allocation #%06d, %d bytes (%s:%d)\n", entry->id, entry->size, entry->file, entry->line);
+ }
- memory_lock_release();
+ memory_lock_release();
- if (total > 0)
- fprintf(stderr, "a total of %d bytes were not free()'d\n", total);
+ if (total > 0)
+ fprintf(stderr, "a total of %d bytes were not free()'d\n", total);
+ }
}
diff --git a/src/osd/windows/windows.mak b/src/osd/windows/windows.mak
index be5bc9c4948..d969bc490aa 100644
--- a/src/osd/windows/windows.mak
+++ b/src/osd/windows/windows.mak
@@ -152,11 +152,9 @@ DEFS += -Dmain=utf8_main
# debug build: enable guard pages on all memory allocations
ifdef DEBUG
-ifndef WINUI
DEFS += -DMALLOC_DEBUG
LDFLAGS += -Wl,--allow-multiple-definition
endif
-endif
# enable UNICODE flags for unicode builds
ifdef UNICODE
diff --git a/src/osd/windows/winsync.c b/src/osd/windows/winsync.c
index 4d86d2ef061..ac84373e43d 100644
--- a/src/osd/windows/winsync.c
+++ b/src/osd/windows/winsync.c
@@ -132,26 +132,43 @@ void osd_lock_free(osd_lock *lock)
//============================================================
-// osd_compare_exchange32
+// win_compare_exchange32
//============================================================
-#ifndef osd_compare_exchange32
-INT32 osd_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
+INT32 win_compare_exchange32(INT32 volatile *ptr, INT32 compare, INT32 exchange)
{
return InterlockedCompareExchange((LPLONG)ptr, (LONG)exchange, (LONG)compare);
}
-#endif
//============================================================
-// osd_compare_exchange64
+// win_compare_exchange64
//============================================================
#ifdef PTR64
-#ifndef osd_compare_exchange64
-INT64 osd_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
+INT64 win_compare_exchange64(INT64 volatile *ptr, INT64 compare, INT64 exchange)
{
return InterlockedCompareExchange64((LONGLONG*)ptr, (LONGLONG)exchange, (LONGLONG)compare);
}
#endif
-#endif
+
+
+//============================================================
+// win_atomic_exchange32
+//============================================================
+
+INT32 win_atomic_exchange32(INT32 volatile *ptr, INT32 exchange)
+{
+ return InterlockedExchange((LONG *) ptr, exchange);
+}
+
+
+//============================================================
+// win_atomic_add32
+//============================================================
+
+INT32 win_atomic_add32(INT32 volatile *ptr, INT32 delta)
+{
+ return InterlockedExchangeAdd((LONG *) ptr, delta) + delta;
+}
+