summaryrefslogtreecommitdiff
path: root/neozip/zarch.h
blob: 6fdcfaba550237caa5bc16f202b4b77bc642cf17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* zarch.h -- Detect compiler architecture and define ARCH_* macros
 * Copyright (C) 2019 Hans Kristian Rosbach
 * For conditions of distribution and use, see copyright notice in zlib.h
 */

#ifndef ZARCH_H
#define ZARCH_H

#define ZARCH_STRINGIZE(X) ZARCH_DOSTRINGIZE(X)
#define ZARCH_DOSTRINGIZE(X) #X

/* ARM64EC defines both _M_ARM64EC and _M_AMD64/_M_X64, so check for ARM first. */

/* ARM 64-bit */
#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
#  define ARCH_ARM
#  define ARCH_64BIT
#  define ARCH_NAME "aarch64"

/* ARM 32-bit */
#elif defined(__arm__) || defined(__arm) || defined(_M_ARM) || defined(__TARGET_ARCH_ARM)
#  define ARCH_ARM
#  define ARCH_32BIT
#  if defined(__ARM64_ARCH_8__) || defined(__ARM_ARCH_8A__) || defined(__ARMv8__) || defined(__ARMv8_A__)
#    define ARCH_NAME "armv8"
#  elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__)
#    define ARCH_NAME "armv7"
#  elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6T2__) || \
        defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) || \
        defined(__ARM_ARCH_6M__)
#    define ARCH_NAME "armv6"
#  elif defined(__ARM_ARCH_5T__) || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)
#    define ARCH_NAME "armv5"
#  elif defined(__ARM_ARCH_4T__)
#    define ARCH_NAME "armv4"
#  elif defined(__ARM_ARCH_3__)
#    define ARCH_NAME "armv3"
#  elif defined(__ARM_ARCH_2__)
#    define ARCH_NAME "armv2"
#  else
#    define ARCH_NAME "arm"
#  endif

/* x86_64 */
#elif defined(__x86_64__) || defined(_M_X64)
#  define ARCH_X86
#  define ARCH_64BIT
#  define ARCH_NAME "x86_64"

/* x86 (32-bit) */
#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \
      defined(__i386) || defined(_M_IX86)
#  define ARCH_X86
#  define ARCH_32BIT
#  define ARCH_NAME "i686"

/* PowerPC */
#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
#  define ARCH_POWER
#  if defined(__64BIT__) || defined(__powerpc64__) || defined(__ppc64__)
#    define ARCH_64BIT
#    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#      define ARCH_NAME "powerpc64le"
#    else
#      define ARCH_NAME "powerpc64"
#    endif
#  else
#    define ARCH_32BIT
#    define ARCH_NAME "powerpc"
#  endif

/* --------------- Less common architectures alphabetically below --------------- */

/* ALPHA */
#elif defined(__alpha__) || defined(__alpha)
#  define ARCH_ALPHA
#  define ARCH_64BIT
#  define ARCH_NAME "alpha"

/* Blackfin */
#elif defined(__BFIN__)
#  define ARCH_BLACKFIN
#  define ARCH_32BIT
#  define ARCH_NAME "blackfin"

/* Itanium */
#elif defined(__ia64) || defined(_M_IA64)
#  define ARCH_IA64
#  define ARCH_64BIT
#  define ARCH_NAME "ia64"

/* MIPS */
#elif defined(__mips__) || defined(__mips)
#  define ARCH_MIPS
#  if defined(__mips64) || defined(__mips64__)
#    define ARCH_64BIT
#    define ARCH_NAME "mips64"
#  else
#    define ARCH_32BIT
#    define ARCH_NAME "mips"
#  endif

/* Motorola 68000-series */
#elif defined(__m68k__)
#  define ARCH_M68K
#  define ARCH_32BIT
#  define ARCH_NAME "m68k"

/* SuperH */
#elif defined(__sh__)
#  define ARCH_SH
#  define ARCH_32BIT
#  define ARCH_NAME "sh"

/* SPARC */
#elif defined(__sparc__) || defined(__sparc)
#  define ARCH_SPARC
#  if defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__)
#    define ARCH_64BIT
#    define ARCH_NAME "sparc9"
#  elif defined(__sparcv8) || defined(__sparc_v8__)
#    define ARCH_32BIT
#    define ARCH_NAME "sparc8"
#  else
#    define ARCH_32BIT
#    define ARCH_NAME "sparc"
#  endif

/* SystemZ / S390 */
#elif defined(__s390x) || defined(__zarch__)
#  define ARCH_S390
#  define ARCH_64BIT
#  define ARCH_NAME "s390x"
#elif defined(__s390__)
#  define ARCH_S390
#  define ARCH_32BIT
#  define ARCH_NAME "s390"
#elif defined(__370__)
#  define ARCH_S390
#  define ARCH_32BIT
#  define ARCH_NAME "s370"

/* PARISC */
#elif defined(__hppa__)
#  define ARCH_PARISC
#  if defined(__hppa64__) || defined(__LP64__)
#    define ARCH_64BIT
#    define ARCH_NAME "parisc64"
#  else
#    define ARCH_32BIT
#    define ARCH_NAME "parisc"
#  endif

/* RS-6000 */
#elif defined(__THW_RS6000)
#  define ARCH_RS6000
#  define ARCH_32BIT
#  define ARCH_NAME "rs6000"

/* RISC-V */
#elif defined(__riscv)
#  define ARCH_RISCV
#  if __riscv_xlen == 64
#    define ARCH_64BIT
#    define ARCH_NAME "riscv64"
#  elif __riscv_xlen == 32
#    define ARCH_32BIT
#    define ARCH_NAME "riscv32"
#  else
#    define ARCH_NAME "riscv"
#  endif

/* LOONGARCH */
#elif defined(__loongarch_lp64)
#  define ARCH_LOONGARCH
#  define ARCH_64BIT
#  define ARCH_NAME "loongarch64"

/* Emscripten (WebAssembly) */
#elif defined(__EMSCRIPTEN__)
#  define ARCH_WASM
#  if defined(__wasm64__)
#    define ARCH_64BIT
#    define ARCH_NAME "wasm64"
#  else
#    define ARCH_32BIT
#    define ARCH_NAME "wasm32"
#  endif

/* Elbrus 2000 (aka e2k) */
#elif defined(__e2k__)
#  define ARCH_E2K
/* e2k reuse x86 optimizations */
#  define ARCH_X86
#  define ARCH_64BIT
#  define ARCH_NAME "e2k"
#  define ARCH_VERSION_STR ZARCH_STRINGIZE(__iset__)

/* Unrecognized architecture */
#else
#  if defined(__LP64__) || defined(_LP64) || defined(_WIN64)
#    define ARCH_64BIT
#  else
#    define ARCH_32BIT
#  endif
#  define ARCH_NAME "unrecognized"
#endif

#endif /* ZARCH_H */