diff --git a/source/lib/sysdep/arch/ia32/ia32.cpp b/source/lib/sysdep/arch/ia32/ia32.cpp index add2aa6ecf..af54b9183e 100644 --- a/source/lib/sysdep/arch/ia32/ia32.cpp +++ b/source/lib/sysdep/arch/ia32/ia32.cpp @@ -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) { diff --git a/source/lib/sysdep/cpu.cpp b/source/lib/sysdep/cpu.cpp index 15f37400c3..5385bbbccd 100644 --- a/source/lib/sysdep/cpu.cpp +++ b/source/lib/sysdep/cpu.cpp @@ -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() diff --git a/source/lib/sysdep/cpu.h b/source/lib/sysdep/cpu.h index 3d287e2677..abd3296438 100644 --- a/source/lib/sysdep/cpu.h +++ b/source/lib/sysdep/cpu.h @@ -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 diff --git a/source/lib/timer.h b/source/lib/timer.h index 9c2b222dc6..e1f5dcff3b 100644 --- a/source/lib/timer.h +++ b/source/lib/timer.h @@ -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)