1 /* CpuArch.h -- CPU specific code
2 2010-10-26: Igor Pavlov : Public domain */
13 MY_CPU_LE means that CPU is LITTLE ENDIAN.
14 If MY_CPU_LE is not defined, we don't know about that property of platform (it can be LITTLE ENDIAN).
16 MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
17 If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
20 #if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
24 #if defined(MY_CPU_AMD64) || defined(_M_IA64)
28 #if defined(_M_IX86) || defined(__i386__)
32 #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
33 #define MY_CPU_X86_OR_AMD64
36 #if defined(MY_CPU_X86) || defined(_M_ARM)
40 #if defined(_WIN32) && defined(_M_ARM)
44 #if defined(_WIN32) && defined(_M_IA64)
45 #define MY_CPU_IA64_LE
48 #if defined(MY_CPU_X86_OR_AMD64)
49 #define MY_CPU_LE_UNALIGN
52 #if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE) || defined(MY_CPU_IA64_LE) || defined(__ARMEL__) || defined(__MIPSEL__) || defined(__LITTLE_ENDIAN__)
56 #if defined(__BIG_ENDIAN__)
60 #if defined(MY_CPU_LE) && defined(MY_CPU_BE)
61 Stop_Compiling_Bad_Endian
64 #ifdef MY_CPU_LE_UNALIGN
66 #define GetUi16(p) (*(const UInt16 *)(p))
67 #define GetUi32(p) (*(const UInt32 *)(p))
68 #define GetUi64(p) (*(const UInt64 *)(p))
69 #define SetUi16(p, d) *(UInt16 *)(p) = (d);
70 #define SetUi32(p, d) *(UInt32 *)(p) = (d);
71 #define SetUi64(p, d) *(UInt64 *)(p) = (d);
75 #define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
77 #define GetUi32(p) ( \
78 ((const Byte *)(p))[0] | \
79 ((UInt32)((const Byte *)(p))[1] << 8) | \
80 ((UInt32)((const Byte *)(p))[2] << 16) | \
81 ((UInt32)((const Byte *)(p))[3] << 24))
83 #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
85 #define SetUi16(p, d) { UInt32 _x_ = (d); \
86 ((Byte *)(p))[0] = (Byte)_x_; \
87 ((Byte *)(p))[1] = (Byte)(_x_ >> 8); }
89 #define SetUi32(p, d) { UInt32 _x_ = (d); \
90 ((Byte *)(p))[0] = (Byte)_x_; \
91 ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
92 ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
93 ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
95 #define SetUi64(p, d) { UInt64 _x64_ = (d); \
96 SetUi32(p, (UInt32)_x64_); \
97 SetUi32(((Byte *)(p)) + 4, (UInt32)(_x64_ >> 32)); }
101 #if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
103 #pragma intrinsic(_byteswap_ulong)
104 #pragma intrinsic(_byteswap_uint64)
105 #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
106 #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
110 #define GetBe32(p) ( \
111 ((UInt32)((const Byte *)(p))[0] << 24) | \
112 ((UInt32)((const Byte *)(p))[1] << 16) | \
113 ((UInt32)((const Byte *)(p))[2] << 8) | \
114 ((const Byte *)(p))[3] )
116 #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
120 #define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
123 #ifdef MY_CPU_X86_OR_AMD64
142 Bool
x86cpuid_CheckAndRead(Cx86cpuid
*p
);
143 int x86cpuid_GetFirm(const Cx86cpuid
*p
);
145 #define x86cpuid_GetFamily(p) (((p)->ver >> 8) & 0xFF00F)
146 #define x86cpuid_GetModel(p) (((p)->ver >> 4) & 0xF00F)
147 #define x86cpuid_GetStepping(p) ((p)->ver & 0xF)
149 Bool
CPU_Is_InOrder();
150 Bool
CPU_Is_Aes_Supported();