forked from 0ad/0ad
OSX compat: remove cpu_CAS64 wrapper, since intptr_t and i64 apparently aren't compatible types. IA-32 code should call ia32_asm_CAS64 if it wants to CAS 64-bit values.
This was SVN commit r8080.
This commit is contained in:
parent
2e7436434d
commit
f5f65c23c0
@ -158,11 +158,6 @@ bool cpu_CAS(volatile intptr_t* location, intptr_t expected, intptr_t new_value)
|
||||
return ia32_asm_CAS(location, expected, new_value);
|
||||
}
|
||||
|
||||
bool cpu_CAS64(volatile i64* location, i64 expected, i64 new_value)
|
||||
{
|
||||
return ia32_asm_CAS64(location, expected, new_value);
|
||||
}
|
||||
|
||||
|
||||
void* cpu_memcpy(void* RESTRICT dst, const void* RESTRICT src, size_t size)
|
||||
{
|
||||
|
@ -27,6 +27,10 @@
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/cpu.h"
|
||||
|
||||
#if ARCH_IA32
|
||||
# include "lib/sysdep/arch/ia32/ia32_asm.h" // ia32_asm_CAS64
|
||||
#endif
|
||||
|
||||
ERROR_ASSOCIATE(ERR::CPU_FEATURE_MISSING, L"This CPU doesn't support a required feature", -1);
|
||||
ERROR_ASSOCIATE(ERR::CPU_UNKNOWN_OPCODE, L"Disassembly failed", -1);
|
||||
ERROR_ASSOCIATE(ERR::CPU_UNKNOWN_VENDOR, L"CPU vendor unknown", -1);
|
||||
@ -39,7 +43,7 @@ ERROR_ASSOCIATE(ERR::CPU_UNKNOWN_VENDOR, L"CPU vendor unknown", -1);
|
||||
cassert(sizeof(void*) == 4);
|
||||
#elif ARCH_AMD64
|
||||
cassert(sizeof(void*) == 8);
|
||||
cassert(sizeof(i64) == sizeof(intptr_t)); // required by cpu_CAS64
|
||||
cassert(sizeof(i64) == sizeof(intptr_t));
|
||||
#endif
|
||||
cassert(sizeof(void*) == sizeof(intptr_t));
|
||||
|
||||
@ -47,9 +51,11 @@ cassert(sizeof(void*) == sizeof(intptr_t));
|
||||
|
||||
static void TestCAS64()
|
||||
{
|
||||
#if ARCH_IA32
|
||||
volatile i64 var = 1;
|
||||
cpu_CAS64(&var, 1ull, 2ull);
|
||||
ia32_asm_CAS64(&var, 1ull, 2ull);
|
||||
debug_assert(var == 2ull);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void TestAtomicAdd()
|
||||
|
@ -90,12 +90,6 @@ bool cpu_CAS(volatile T* location, T expected, T new_value)
|
||||
return cpu_CAS((volatile intptr_t*)location, (intptr_t)expected, (intptr_t)new_value);
|
||||
}
|
||||
|
||||
#if ARCH_AMD64
|
||||
# define cpu_CAS64 cpu_CAS
|
||||
#else
|
||||
LIB_API bool cpu_CAS64(volatile i64* location, i64 expected, i64 newValue);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* add a signed value to a variable without the possibility of interference
|
||||
|
@ -30,8 +30,11 @@
|
||||
#include "lib/config2.h" // CONFIG2_TIMER_ALLOW_RDTSC
|
||||
#include "lib/sysdep/cpu.h" // cpu_AtomicAdd
|
||||
#if ARCH_X86_X64 && CONFIG2_TIMER_ALLOW_RDTSC
|
||||
# include "lib/sysdep/arch/x86_x64/x86_x64.h" // x86_x64_rdtsc
|
||||
# include "lib/sysdep/os_cpu.h" // os_cpu_ClockFrequency
|
||||
# include "lib/sysdep/arch/x86_x64/x86_x64.h" // x86_x64_rdtsc
|
||||
# if ARCH_IA32
|
||||
# include "lib/sysdep/arch/ia32/ia32_asm.h" // ia32_asm_CAS64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
@ -176,10 +179,12 @@ public:
|
||||
const i64 delta = t1.m_cycles - t0.m_cycles;
|
||||
#if ARCH_AMD64
|
||||
cpu_AtomicAdd((volatile intptr_t*)&m_cycles, (intptr_t)delta);
|
||||
#else
|
||||
#elif ARCH_IA32
|
||||
retry:
|
||||
if(!cpu_CAS64(&m_cycles, m_cycles, m_cycles+delta))
|
||||
if(!ia32_asm_CAS64(&m_cycles, m_cycles, m_cycles+delta))
|
||||
goto retry;
|
||||
#else
|
||||
# error "port"
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -233,8 +238,15 @@ retry:
|
||||
i64 newRepresentation;
|
||||
memcpy(&newRepresentation, &seconds, sizeof(newRepresentation));
|
||||
|
||||
if(!cpu_CAS64((volatile i64*)&m_seconds, oldRepresentation, newRepresentation))
|
||||
#if ARCH_AMD64
|
||||
if(!cpu_CAS((volatile intptr_t*)&m_seconds, oldRepresentation, newRepresentation))
|
||||
goto retry;
|
||||
#elif ARCH_IA32
|
||||
if(!ia32_asm_CAS64((volatile i64*)&m_seconds, oldRepresentation, newRepresentation))
|
||||
goto retry;
|
||||
#else
|
||||
# error "port"
|
||||
#endif
|
||||
}
|
||||
|
||||
void Subtract(TimerUnit t)
|
||||
|
Loading…
Reference in New Issue
Block a user