2005-05-18 07:32:09 +02:00
|
|
|
#ifndef SYSDEP_CPU_H
|
|
|
|
#define SYSDEP_CPU_H
|
|
|
|
|
2004-06-19 16:45:04 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-04-19 19:07:05 +02:00
|
|
|
const size_t CPU_TYPE_LEN = 49; // processor brand string is <= 48 chars
|
|
|
|
extern char cpu_type[CPU_TYPE_LEN];
|
|
|
|
|
2004-06-19 16:45:04 +02:00
|
|
|
extern double cpu_freq;
|
|
|
|
|
|
|
|
|
2005-09-14 18:58:10 +02:00
|
|
|
// -1 if detect not yet called, or cannot be determined:
|
|
|
|
|
|
|
|
extern int cpus; // # packages (i.e. sockets; > 1 => SMP system)
|
|
|
|
extern int cpu_ht_units; // degree of hyperthreading, typically 2
|
|
|
|
extern int cpu_cores; // cores per package, typically 2
|
|
|
|
|
|
|
|
extern int cpu_speedstep;
|
2004-06-22 19:20:38 +02:00
|
|
|
|
|
|
|
|
2005-04-19 19:07:05 +02:00
|
|
|
extern void get_cpu_info(void);
|
|
|
|
|
2004-06-22 19:20:38 +02:00
|
|
|
|
2005-05-03 07:05:16 +02:00
|
|
|
// atomic "compare and swap". compare the machine word at <location> against
|
|
|
|
// <expected>; if not equal, return false; otherwise, overwrite it with
|
|
|
|
// <new_value> and return true.
|
|
|
|
extern bool CAS_(uintptr_t* location, uintptr_t expected, uintptr_t new_value);
|
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
// this is often used for pointers, so the macro coerces parameters to
|
|
|
|
// uinptr_t. invalid usage unfortunately also goes through without warnings.
|
|
|
|
// to catch cases where the caller has passed <expected> as <location> or
|
|
|
|
// similar mishaps, the implementation verifies <location> is a valid pointer.
|
2005-05-03 07:05:16 +02:00
|
|
|
#define CAS(l,o,n) CAS_((uintptr_t*)l, (uintptr_t)o, (uintptr_t)n)
|
|
|
|
|
|
|
|
extern void atomic_add(intptr_t* location, intptr_t increment);
|
|
|
|
|
|
|
|
// enforce strong memory ordering.
|
|
|
|
extern void mfence();
|
|
|
|
|
|
|
|
extern void serialize();
|
|
|
|
|
2005-09-14 18:58:10 +02:00
|
|
|
|
2005-08-09 18:23:19 +02:00
|
|
|
// Win32 CONTEXT field abstraction
|
|
|
|
// (there's no harm also defining this for other platforms)
|
|
|
|
#if CPU_AMD64
|
|
|
|
# define PC_ Rip
|
|
|
|
# define FP_ Rbp
|
|
|
|
# define SP_ Rsp
|
|
|
|
#elif CPU_IA32
|
|
|
|
# define PC_ Eip
|
|
|
|
# define FP_ Ebp
|
|
|
|
# define SP_ Esp
|
|
|
|
#endif
|
|
|
|
|
2004-06-19 16:45:04 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
2004-06-22 15:22:46 +02:00
|
|
|
#endif
|
2005-05-18 07:32:09 +02:00
|
|
|
|
|
|
|
#endif
|