Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / lzma_sdk / CpuArch.h
blob8c0c84d6fcb78621dac68d2f2facd15cad64904a
1 /* CpuArch.h -- CPU specific code
2 2010-10-26: Igor Pavlov : Public domain */
4 #ifndef __CPU_ARCH_H
5 #define __CPU_ARCH_H
7 #include <stdlib.h>
8 #include "Types.h"
10 EXTERN_C_BEGIN
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__)
21 #define MY_CPU_AMD64
22 #endif
24 #if defined(MY_CPU_AMD64) || defined(_M_IA64)
25 #define MY_CPU_64BIT
26 #endif
28 #if defined(_M_IX86) || defined(__i386__)
29 #define MY_CPU_X86
30 #endif
32 #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
33 #define MY_CPU_X86_OR_AMD64
34 #endif
36 #if defined(MY_CPU_X86) || defined(_M_ARM)
37 #define MY_CPU_32BIT
38 #endif
40 #if defined(_WIN32) && defined(_M_ARM)
41 #define MY_CPU_ARM_LE
42 #endif
44 #if defined(_WIN32) && defined(_M_IA64)
45 #define MY_CPU_IA64_LE
46 #endif
48 #if defined(MY_CPU_X86_OR_AMD64)
49 #define MY_CPU_LE_UNALIGN
50 #endif
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__)
53 #define MY_CPU_LE
54 #endif
56 #if defined(__BIG_ENDIAN__)
57 #define MY_CPU_BE
58 #endif
60 #if defined(MY_CPU_LE) && defined(MY_CPU_BE)
61 Stop_Compiling_Bad_Endian
62 #endif
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);
73 #else
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)); }
99 #endif
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))
108 #else
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))
118 #endif
120 #define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
123 #ifdef MY_CPU_X86_OR_AMD64
125 typedef struct
127 UInt32 maxFunc;
128 UInt32 vendor[3];
129 UInt32 ver;
130 UInt32 b;
131 UInt32 c;
132 UInt32 d;
133 } Cx86cpuid;
135 enum
137 CPU_FIRM_INTEL,
138 CPU_FIRM_AMD,
139 CPU_FIRM_VIA
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();
152 #endif
154 EXTERN_C_END
156 #endif