1
0
forked from 0ad/0ad

fixes from work: clarify that cpu_MemoryBarrier has no runtime cost by renaming to COMPILER_FENCE and moving to code_annotation.h; fix 32-bit Parallel Studio 2011 warning.

This was SVN commit r8486.
This commit is contained in:
janwas 2010-10-29 12:54:51 +00:00
parent 8f532b81cd
commit 0c3d69ae29
10 changed files with 33 additions and 29 deletions

View File

@ -30,12 +30,13 @@
#include "lib/bits.h"
#ifndef swap16
u16 swap16(const u16 x)
{
return (u16)(((x & 0xff) << 8) | (x >> 8));
}
#endif
#ifndef swap32
u32 swap32(const u32 x)
{
return (x << 24) |
@ -43,7 +44,9 @@ u32 swap32(const u32 x)
((x << 8) & 0x00ff0000) |
((x >> 8) & 0x0000ff00);
}
#endif
#ifndef swap64
u64 swap64(const u64 x)
{
const u32 lo = (u32)(x & 0xFFFFFFFF);
@ -54,8 +57,7 @@ u64 swap64(const u64 x)
ret |= swap32(hi);
return ret;
}
#endif // #ifndef swap16
#endif
//-----------------------------------------------------------------------------

View File

@ -183,4 +183,19 @@ private:\
# define SENTINEL_ARG
#endif
/**
* prevent the compiler from reordering loads or stores across this point.
**/
#if ICC_VERSION
# define COMPILER_FENCE __memory_barrier()
#elif MSC_VERSION
# include <intrin.h>
# pragma intrinsic(_ReadWriteBarrier)
# define COMPILER_FENCE _ReadWriteBarrier()
#elif GCC_VERSION
# define COMPILER_FENCE asm volatile("" : : : "memory")
#else
# define COMPILER_FENCE
#endif
#endif // #ifndef INCLUDED_CODE_ANNOTATION

View File

@ -510,7 +510,7 @@ void debug_SkipErrors(LibError err)
{
errorToSkip = err;
numSkipped = 0;
cpu_MemoryBarrier();
COMPILER_FENCE;
skipStatus = VALID; // linearization point
}
else
@ -522,7 +522,7 @@ size_t debug_StopSkippingErrors()
if(cpu_CAS(&skipStatus, VALID, BUSY))
{
const size_t ret = numSkipped;
cpu_MemoryBarrier();
COMPILER_FENCE;
skipStatus = INVALID; // linearization point
return ret;
}
@ -539,7 +539,7 @@ static bool ShouldSkipError(LibError err)
{
numSkipped++;
const bool ret = (err == errorToSkip);
cpu_MemoryBarrier();
COMPILER_FENCE;
skipStatus = VALID;
return ret;
}

View File

@ -25,6 +25,7 @@
// so include this header from such source files as well.
#include "lib/sysdep/compiler.h" // ICC_VERSION
#include "lib/sysdep/arch.h" // ARCH_IA32
#if ICC_VERSION
# pragma warning(push)
@ -38,4 +39,7 @@
# pragma warning(disable:1879) // unimplemented pragma ignored
# pragma warning(disable:2270) // the declaration of the copy assignment operator has been suppressed
# pragma warning(disable:2273) // the declaration of the copy constructor has been suppressed
# if ARCH_IA32
# pragma warning(disable:693) // calling convention specified here is ignored
# endif
#endif

View File

@ -228,7 +228,7 @@ extern int error_AddAssociation(LibErrorAssociation*);
* @param max_chars size of buffer [characters]
* @return buf (allows using this function in expressions)
**/
extern wchar_t* error_description_r(LibError err, wchar_t* buf, size_t max_chars);
LIB_API wchar_t* error_description_r(LibError err, wchar_t* buf, size_t max_chars);
//-----------------------------------------------------------------------------

View File

@ -45,7 +45,7 @@ LibError ModuleInit(volatile ModuleInitState* initState, LibError (*init)())
{
LibError ret = init();
*initState = (ret == INFO::OK)? INITIALIZED : ret;
cpu_MemoryBarrier();
COMPILER_FENCE;
return ret;
}
@ -70,7 +70,7 @@ LibError ModuleShutdown(volatile ModuleInitState* initState, void (*shutdown)())
{
shutdown();
*initState = UNINITIALIZED;
cpu_MemoryBarrier();
COMPILER_FENCE;
return INFO::OK;
}

View File

@ -499,7 +499,7 @@ static ALuint srcs_pop(volatile intptr_t* srcs)
{
retry:
intptr_t al_src = srcs[i];
cpu_MemoryBarrier();
COMPILER_FENCE;
if(!cpu_CAS(&srcs[i], al_src, 0))
goto retry;
if(al_src != 0) // got a valid source

View File

@ -52,23 +52,6 @@ LIB_API const char* cpu_IdentifierString();
//-----------------------------------------------------------------------------
// lock-free support routines
/**
* prevent the CPU from reordering previous loads or stores past the barrier,
* thus ensuring they retire before any subsequent memory operations.
* this also prevents compiler reordering.
**/
#if MSC_VERSION
# include <intrin.h>
# if !ICC_VERSION
# pragma intrinsic(_ReadWriteBarrier)
# endif
# define cpu_MemoryBarrier() _ReadWriteBarrier()
#elif GCC_VERSION
# define cpu_MemoryBarrier() asm volatile("" : : : "memory")
#else
# define cpu_MemoryBarrier()
#endif
/**
* atomic "compare and swap".
*

View File

@ -1851,7 +1851,7 @@ LibError debug_DumpStack(wchar_t* buf, size_t maxChars, void* pcontext, const wc
LibError ret = wdbg_sym_WalkStack(dump_frame_cb, 0, (const CONTEXT*)pcontext, lastFuncToSkip);
busy = 0;
cpu_MemoryBarrier();
COMPILER_FENCE;
return ret;
}

View File

@ -211,7 +211,7 @@ double whrt_Time()
retry:
// latch timer state (counter and time must be from the same update)
const double time = ts->time;
cpu_MemoryBarrier();
COMPILER_FENCE;
const u64 counter = ts->counter;
// ts changed after reading time. note: don't compare counter because
// it _might_ have the same value after two updates.