RetroArch
CpuArch.h
Go to the documentation of this file.
1 /* CpuArch.h -- CPU specific code
2 2010-10-26: Igor Pavlov : Public domain */
3 
4 #ifndef __CPU_ARCH_H
5 #define __CPU_ARCH_H
6 
7 #include "7zTypes.h"
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*
14 MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
15 If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform.
16 */
17 
18 #if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__)
19 #define MY_CPU_AMD64
20 #endif
21 
22 #if defined(MY_CPU_AMD64) || defined(_M_IA64)
23 #define MY_CPU_64BIT
24 #endif
25 
26 #if defined(_M_IX86) || defined(__i386__)
27 #define MY_CPU_X86
28 #endif
29 
30 #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
31 #define MY_CPU_X86_OR_AMD64
32 #endif
33 
34 #if defined(MY_CPU_X86) || defined(_M_ARM)
35 #define MY_CPU_32BIT
36 #endif
37 
38 #if defined(_WIN32) && defined(_M_ARM)
39 #define MY_CPU_ARM_LE
40 #endif
41 
42 #if defined(_WIN32) && defined(_M_IA64)
43 #define MY_CPU_IA64_LE
44 #endif
45 
46 #if defined(MY_CPU_X86_OR_AMD64)
47 #define MY_CPU_LE_UNALIGN
48 #endif
49 
50 #ifdef MY_CPU_LE_UNALIGN
51 
52 #define GetUi16(p) (*(const uint16_t *)(p))
53 #define GetUi32(p) (*(const uint32_t *)(p))
54 #define GetUi64(p) (*(const uint64_t *)(p))
55 #else
56 #define GetUi16(p) (((const uint8_t *)(p))[0] | ((uint16_t)((const uint8_t *)(p))[1] << 8))
57 
58 #define GetUi32(p) ( \
59  ((const uint8_t *)(p))[0] | \
60  ((uint32_t)((const uint8_t *)(p))[1] << 8) | \
61  ((uint32_t)((const uint8_t *)(p))[2] << 16) | \
62  ((uint32_t)((const uint8_t *)(p))[3] << 24))
63 
64 #define GetUi64(p) (GetUi32(p) | ((uint64_t)GetUi32(((const uint8_t *)(p)) + 4) << 32))
65 #endif
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif