2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : cpu.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : CPU and memory detection.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
// license: GPL; see lib/license.txt
|
2006-04-12 01:59:08 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#ifndef INCLUDED_CPU
|
|
|
|
#define INCLUDED_CPU
|
2005-05-18 07:32:09 +02:00
|
|
|
|
2006-09-22 15:19:40 +02:00
|
|
|
namespace ERR
|
|
|
|
{
|
|
|
|
const LibError CPU_FEATURE_MISSING = -130000;
|
|
|
|
const LibError CPU_UNKNOWN_OPCODE = -130001;
|
2007-04-25 20:19:35 +02:00
|
|
|
const LibError CPU_UNKNOWN_VENDOR = -130002;
|
2008-05-12 20:15:08 +02:00
|
|
|
|
2006-09-22 15:19:40 +02:00
|
|
|
}
|
2004-06-19 16:45:04 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// CPU detection
|
2004-06-19 16:45:04 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
/**
|
|
|
|
* @return string identifying the CPU (usually a cleaned-up version of the
|
|
|
|
* brand string)
|
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API const char* cpu_IdentifierString();
|
2007-09-23 17:36:29 +02:00
|
|
|
|
2005-05-03 07:05:16 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// lock-free support routines
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atomic "compare and swap".
|
|
|
|
*
|
|
|
|
* @param location address of the word to compare and possibly overwrite
|
|
|
|
* @param expected its expected value
|
|
|
|
* @param newValue the value with which to replace it
|
|
|
|
* @return false if the target word doesn't match the expected value,
|
|
|
|
* otherwise true (also overwriting the contents of location)
|
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API bool cpu_CAS(volatile uintptr_t* location, uintptr_t expected, uintptr_t newValue);
|
2005-05-03 07:05:16 +02:00
|
|
|
|
2008-05-12 20:15:08 +02:00
|
|
|
/**
|
|
|
|
* specialization of cpu_CAS for pointer types. this avoids error-prone
|
|
|
|
* casting in user code.
|
|
|
|
**/
|
|
|
|
template<typename T>
|
|
|
|
bool cpu_CAS(volatile T* location, T expected, T new_value)
|
|
|
|
{
|
|
|
|
return cpu_CAS((volatile uintptr_t*)location, (uintptr_t)expected, (uintptr_t)new_value);
|
|
|
|
}
|
|
|
|
|
2007-04-30 21:58:04 +02:00
|
|
|
/**
|
|
|
|
* add a signed value to a variable without the possibility of interference
|
|
|
|
* from other threads/CPUs.
|
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API void cpu_AtomicAdd(volatile intptr_t* location, intptr_t increment);
|
2005-05-03 07:05:16 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
/**
|
|
|
|
* enforce strict instruction ordering in the CPU pipeline.
|
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API void cpu_Serialize();
|
2007-05-16 17:56:47 +02:00
|
|
|
|
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// misc
|
2007-04-25 20:19:35 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
/**
|
2008-05-01 17:41:42 +02:00
|
|
|
* drop-in replacement for POSIX memcpy().
|
2007-09-23 17:36:29 +02:00
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API void* cpu_memcpy(void* RESTRICT dst, const void* RESTRICT src, size_t size);
|
2008-03-24 16:44:37 +01:00
|
|
|
|
2007-04-25 20:19:35 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
/**
|
|
|
|
* set the FPU control word to "desirable" values (see implementation)
|
|
|
|
**/
|
2008-05-01 17:41:42 +02:00
|
|
|
LIB_API void cpu_ConfigureFloatingPoint();
|
2007-04-25 20:19:35 +02:00
|
|
|
|
|
|
|
// convert float to int much faster than _ftol2, which would normally be
|
|
|
|
// used by (int) casts.
|
2008-04-19 20:10:00 +02:00
|
|
|
// VC8 and GCC with -ffast-math now manage to generate SSE instructions,
|
|
|
|
// so our implementation is no longer needed.
|
2008-07-05 10:27:33 +02:00
|
|
|
#define cpu_i32FromFloat(f) ((i32)(f))
|
|
|
|
#define cpu_i32FromDouble(d) ((i32)(d))
|
|
|
|
#define cpu_i64FromDouble(d) ((i64)(d))
|
2005-05-03 07:05:16 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
#endif // #ifndef INCLUDED_CPU
|