Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/ext/lzma-sdk/CpuArch.h
10522 views
1
/* CpuArch.h -- CPU specific code
2
Igor Pavlov : Public domain */
3
4
#ifndef ZIP7_INC_CPU_ARCH_H
5
#define ZIP7_INC_CPU_ARCH_H
6
7
#include "7zTypes.h"
8
9
EXTERN_C_BEGIN
10
11
/*
12
MY_CPU_LE means that CPU is LITTLE ENDIAN.
13
MY_CPU_BE means that CPU is BIG ENDIAN.
14
If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
15
16
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
17
18
MY_CPU_64BIT means that processor can work with 64-bit registers.
19
MY_CPU_64BIT can be used to select fast code branch
20
MY_CPU_64BIT doesn't mean that (sizeof(void *) == 8)
21
*/
22
23
#if !defined(_M_ARM64EC)
24
#if defined(_M_X64) \
25
|| defined(_M_AMD64) \
26
|| defined(__x86_64__) \
27
|| defined(__AMD64__) \
28
|| defined(__amd64__)
29
#define MY_CPU_AMD64
30
#ifdef __ILP32__
31
#define MY_CPU_NAME "x32"
32
#define MY_CPU_SIZEOF_POINTER 4
33
#else
34
#if defined(__APX_EGPR__) || defined(__EGPR__)
35
#define MY_CPU_NAME "x64-apx"
36
#define MY_CPU_AMD64_APX
37
#else
38
#define MY_CPU_NAME "x64"
39
#endif
40
#define MY_CPU_SIZEOF_POINTER 8
41
#endif
42
#define MY_CPU_64BIT
43
#endif
44
#endif
45
46
47
#if defined(_M_IX86) \
48
|| defined(__i386__)
49
#define MY_CPU_X86
50
#define MY_CPU_NAME "x86"
51
/* #define MY_CPU_32BIT */
52
#define MY_CPU_SIZEOF_POINTER 4
53
#endif
54
55
#if defined(__SSE2__) \
56
|| defined(MY_CPU_AMD64) \
57
|| defined(_M_IX86_FP) && (_M_IX86_FP >= 2)
58
#define MY_CPU_SSE2
59
#endif
60
61
62
#if defined(_M_ARM64) \
63
|| defined(_M_ARM64EC) \
64
|| defined(__AARCH64EL__) \
65
|| defined(__AARCH64EB__) \
66
|| defined(__aarch64__)
67
#define MY_CPU_ARM64
68
#if defined(__ILP32__) \
69
|| defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
70
#define MY_CPU_NAME "arm64-32"
71
#define MY_CPU_SIZEOF_POINTER 4
72
#elif defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 16)
73
#define MY_CPU_NAME "arm64-128"
74
#define MY_CPU_SIZEOF_POINTER 16
75
#else
76
#if defined(_M_ARM64EC)
77
#define MY_CPU_NAME "arm64ec"
78
#else
79
#define MY_CPU_NAME "arm64"
80
#endif
81
#define MY_CPU_SIZEOF_POINTER 8
82
#endif
83
#define MY_CPU_64BIT
84
#endif
85
86
87
#if defined(_M_ARM) \
88
|| defined(_M_ARM_NT) \
89
|| defined(_M_ARMT) \
90
|| defined(__arm__) \
91
|| defined(__thumb__) \
92
|| defined(__ARMEL__) \
93
|| defined(__ARMEB__) \
94
|| defined(__THUMBEL__) \
95
|| defined(__THUMBEB__)
96
#define MY_CPU_ARM
97
98
#if defined(__thumb__) || defined(__THUMBEL__) || defined(_M_ARMT)
99
#define MY_CPU_ARMT
100
#define MY_CPU_NAME "armt"
101
#else
102
#define MY_CPU_ARM32
103
#define MY_CPU_NAME "arm"
104
#endif
105
/* #define MY_CPU_32BIT */
106
#define MY_CPU_SIZEOF_POINTER 4
107
#endif
108
109
110
#if defined(_M_IA64) \
111
|| defined(__ia64__)
112
#define MY_CPU_IA64
113
#define MY_CPU_NAME "ia64"
114
#define MY_CPU_64BIT
115
#endif
116
117
118
#if defined(__mips64) \
119
|| defined(__mips64__) \
120
|| (defined(__mips) && (__mips == 64 || __mips == 4 || __mips == 3))
121
#define MY_CPU_NAME "mips64"
122
#define MY_CPU_64BIT
123
#elif defined(__mips__)
124
#define MY_CPU_NAME "mips"
125
/* #define MY_CPU_32BIT */
126
#endif
127
128
129
#if defined(__ppc64__) \
130
|| defined(__powerpc64__) \
131
|| defined(__ppc__) \
132
|| defined(__powerpc__) \
133
|| defined(__PPC__) \
134
|| defined(_POWER)
135
136
#define MY_CPU_PPC_OR_PPC64
137
138
#if defined(__ppc64__) \
139
|| defined(__powerpc64__) \
140
|| defined(_LP64) \
141
|| defined(__64BIT__)
142
#ifdef __ILP32__
143
#define MY_CPU_NAME "ppc64-32"
144
#define MY_CPU_SIZEOF_POINTER 4
145
#else
146
#define MY_CPU_NAME "ppc64"
147
#define MY_CPU_SIZEOF_POINTER 8
148
#endif
149
#define MY_CPU_64BIT
150
#else
151
#define MY_CPU_NAME "ppc"
152
#define MY_CPU_SIZEOF_POINTER 4
153
/* #define MY_CPU_32BIT */
154
#endif
155
#endif
156
157
158
#if defined(__sparc__) \
159
|| defined(__sparc)
160
#define MY_CPU_SPARC
161
#if defined(__LP64__) \
162
|| defined(_LP64) \
163
|| defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)
164
#define MY_CPU_NAME "sparcv9"
165
#define MY_CPU_SIZEOF_POINTER 8
166
#define MY_CPU_64BIT
167
#elif defined(__sparc_v9__) \
168
|| defined(__sparcv9)
169
#define MY_CPU_64BIT
170
#if defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
171
#define MY_CPU_NAME "sparcv9-32"
172
#else
173
#define MY_CPU_NAME "sparcv9m"
174
#endif
175
#elif defined(__sparc_v8__) \
176
|| defined(__sparcv8)
177
#define MY_CPU_NAME "sparcv8"
178
#define MY_CPU_SIZEOF_POINTER 4
179
#else
180
#define MY_CPU_NAME "sparc"
181
#endif
182
#endif
183
184
185
#if defined(__riscv) \
186
|| defined(__riscv__)
187
#define MY_CPU_RISCV
188
#if __riscv_xlen == 32
189
#define MY_CPU_NAME "riscv32"
190
#elif __riscv_xlen == 64
191
#define MY_CPU_NAME "riscv64"
192
#else
193
#define MY_CPU_NAME "riscv"
194
#endif
195
#endif
196
197
198
#if defined(__loongarch__)
199
#define MY_CPU_LOONGARCH
200
#if defined(__loongarch64) || defined(__loongarch_grlen) && (__loongarch_grlen == 64)
201
#define MY_CPU_64BIT
202
#endif
203
#if defined(__loongarch64)
204
#define MY_CPU_NAME "loongarch64"
205
#define MY_CPU_LOONGARCH64
206
#else
207
#define MY_CPU_NAME "loongarch"
208
#endif
209
#endif
210
211
212
// #undef MY_CPU_NAME
213
// #undef MY_CPU_SIZEOF_POINTER
214
// #define __e2k__
215
// #define __SIZEOF_POINTER__ 4
216
#if defined(__e2k__)
217
#define MY_CPU_E2K
218
#if defined(__ILP32__) || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 4)
219
#define MY_CPU_NAME "e2k-32"
220
#define MY_CPU_SIZEOF_POINTER 4
221
#else
222
#define MY_CPU_NAME "e2k"
223
#if defined(__LP64__) || defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)
224
#define MY_CPU_SIZEOF_POINTER 8
225
#endif
226
#endif
227
#define MY_CPU_64BIT
228
#endif
229
230
231
#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
232
#define MY_CPU_X86_OR_AMD64
233
#endif
234
235
#if defined(MY_CPU_ARM) || defined(MY_CPU_ARM64)
236
#define MY_CPU_ARM_OR_ARM64
237
#endif
238
239
240
#ifdef _WIN32
241
242
#ifdef MY_CPU_ARM
243
#define MY_CPU_ARM_LE
244
#endif
245
246
#ifdef MY_CPU_ARM64
247
#define MY_CPU_ARM64_LE
248
#endif
249
250
#ifdef _M_IA64
251
#define MY_CPU_IA64_LE
252
#endif
253
254
#endif
255
256
257
#if defined(MY_CPU_X86_OR_AMD64) \
258
|| defined(MY_CPU_ARM_LE) \
259
|| defined(MY_CPU_ARM64_LE) \
260
|| defined(MY_CPU_IA64_LE) \
261
|| defined(_LITTLE_ENDIAN) \
262
|| defined(__LITTLE_ENDIAN__) \
263
|| defined(__ARMEL__) \
264
|| defined(__THUMBEL__) \
265
|| defined(__AARCH64EL__) \
266
|| defined(__MIPSEL__) \
267
|| defined(__MIPSEL) \
268
|| defined(_MIPSEL) \
269
|| defined(__BFIN__) \
270
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
271
#define MY_CPU_LE
272
#endif
273
274
#if defined(__BIG_ENDIAN__) \
275
|| defined(__ARMEB__) \
276
|| defined(__THUMBEB__) \
277
|| defined(__AARCH64EB__) \
278
|| defined(__MIPSEB__) \
279
|| defined(__MIPSEB) \
280
|| defined(_MIPSEB) \
281
|| defined(__m68k__) \
282
|| defined(__s390__) \
283
|| defined(__s390x__) \
284
|| defined(__zarch__) \
285
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
286
#define MY_CPU_BE
287
#endif
288
289
290
#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
291
#error Stop_Compiling_Bad_Endian
292
#endif
293
294
#if !defined(MY_CPU_LE) && !defined(MY_CPU_BE)
295
#error Stop_Compiling_CPU_ENDIAN_must_be_detected_at_compile_time
296
#endif
297
298
#if defined(MY_CPU_32BIT) && defined(MY_CPU_64BIT)
299
#error Stop_Compiling_Bad_32_64_BIT
300
#endif
301
302
#ifdef __SIZEOF_POINTER__
303
#ifdef MY_CPU_SIZEOF_POINTER
304
#if MY_CPU_SIZEOF_POINTER != __SIZEOF_POINTER__
305
#error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
306
#endif
307
#else
308
#define MY_CPU_SIZEOF_POINTER __SIZEOF_POINTER__
309
#endif
310
#endif
311
312
#if defined(MY_CPU_SIZEOF_POINTER) && (MY_CPU_SIZEOF_POINTER == 4)
313
#if defined (_LP64)
314
#error Stop_Compiling_Bad_MY_CPU_PTR_SIZE
315
#endif
316
#endif
317
318
#ifdef _MSC_VER
319
#if _MSC_VER >= 1300
320
#define MY_CPU_pragma_pack_push_1 __pragma(pack(push, 1))
321
#define MY_CPU_pragma_pop __pragma(pack(pop))
322
#else
323
#define MY_CPU_pragma_pack_push_1
324
#define MY_CPU_pragma_pop
325
#endif
326
#else
327
#ifdef __xlC__
328
#define MY_CPU_pragma_pack_push_1 _Pragma("pack(1)")
329
#define MY_CPU_pragma_pop _Pragma("pack()")
330
#else
331
#define MY_CPU_pragma_pack_push_1 _Pragma("pack(push, 1)")
332
#define MY_CPU_pragma_pop _Pragma("pack(pop)")
333
#endif
334
#endif
335
336
337
#ifndef MY_CPU_NAME
338
// #define MY_CPU_IS_UNKNOWN
339
#ifdef MY_CPU_LE
340
#define MY_CPU_NAME "LE"
341
#elif defined(MY_CPU_BE)
342
#define MY_CPU_NAME "BE"
343
#else
344
/*
345
#define MY_CPU_NAME ""
346
*/
347
#endif
348
#endif
349
350
351
352
353
354
#ifdef __has_builtin
355
#define Z7_has_builtin(x) __has_builtin(x)
356
#else
357
#define Z7_has_builtin(x) 0
358
#endif
359
360
361
#define Z7_BSWAP32_CONST(v) \
362
( (((UInt32)(v) << 24) ) \
363
| (((UInt32)(v) << 8) & (UInt32)0xff0000) \
364
| (((UInt32)(v) >> 8) & (UInt32)0xff00 ) \
365
| (((UInt32)(v) >> 24) ))
366
367
368
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
369
370
#include <stdlib.h>
371
372
/* Note: these macros will use bswap instruction (486), that is unsupported in 386 cpu */
373
374
#pragma intrinsic(_byteswap_ushort)
375
#pragma intrinsic(_byteswap_ulong)
376
#pragma intrinsic(_byteswap_uint64)
377
378
#define Z7_BSWAP16(v) _byteswap_ushort(v)
379
#define Z7_BSWAP32(v) _byteswap_ulong (v)
380
#define Z7_BSWAP64(v) _byteswap_uint64(v)
381
#define Z7_CPU_FAST_BSWAP_SUPPORTED
382
383
/* GCC can generate slow code that calls function for __builtin_bswap32() for:
384
- GCC for RISCV, if Zbb/XTHeadBb extension is not used.
385
- GCC for SPARC.
386
The code from CLANG for SPARC also is not fastest.
387
So we don't define Z7_CPU_FAST_BSWAP_SUPPORTED in some cases.
388
*/
389
#elif (!defined(MY_CPU_RISCV) || defined (__riscv_zbb) || defined(__riscv_xtheadbb)) \
390
&& !defined(MY_CPU_SPARC) \
391
&& ( \
392
(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
393
|| (defined(__clang__) && Z7_has_builtin(__builtin_bswap16)) \
394
)
395
396
#define Z7_BSWAP16(v) __builtin_bswap16(v)
397
#define Z7_BSWAP32(v) __builtin_bswap32(v)
398
#define Z7_BSWAP64(v) __builtin_bswap64(v)
399
#define Z7_CPU_FAST_BSWAP_SUPPORTED
400
401
#else
402
403
#define Z7_BSWAP16(v) ((UInt16) \
404
( ((UInt32)(v) << 8) \
405
| ((UInt32)(v) >> 8) \
406
))
407
408
#define Z7_BSWAP32(v) Z7_BSWAP32_CONST(v)
409
410
#define Z7_BSWAP64(v) \
411
( ( ( (UInt64)(v) ) << 8 * 7 ) \
412
| ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 1) ) << 8 * 5 ) \
413
| ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 2) ) << 8 * 3 ) \
414
| ( ( (UInt64)(v) & ((UInt32)0xff << 8 * 3) ) << 8 * 1 ) \
415
| ( ( (UInt64)(v) >> 8 * 1 ) & ((UInt32)0xff << 8 * 3) ) \
416
| ( ( (UInt64)(v) >> 8 * 3 ) & ((UInt32)0xff << 8 * 2) ) \
417
| ( ( (UInt64)(v) >> 8 * 5 ) & ((UInt32)0xff << 8 * 1) ) \
418
| ( ( (UInt64)(v) >> 8 * 7 ) ) \
419
)
420
421
#endif
422
423
424
425
#ifdef MY_CPU_LE
426
#if defined(MY_CPU_X86_OR_AMD64) \
427
|| defined(MY_CPU_ARM64) \
428
|| defined(MY_CPU_RISCV) && defined(__riscv_misaligned_fast) \
429
|| defined(MY_CPU_E2K) && defined(__iset__) && (__iset__ >= 6)
430
#define MY_CPU_LE_UNALIGN
431
#define MY_CPU_LE_UNALIGN_64
432
#elif defined(__ARM_FEATURE_UNALIGNED)
433
/* === ALIGNMENT on 32-bit arm and LDRD/STRD/LDM/STM instructions.
434
Description of problems:
435
problem-1 : 32-bit ARM architecture:
436
multi-access (pair of 32-bit accesses) instructions (LDRD/STRD/LDM/STM)
437
require 32-bit (WORD) alignment (by 32-bit ARM architecture).
438
So there is "Alignment fault exception", if data is not aligned for 32-bit.
439
440
problem-2 : 32-bit kernels and arm64 kernels:
441
32-bit linux kernels provide fixup for these "paired" instruction "Alignment fault exception".
442
So unaligned paired-access instructions work via exception handler in kernel in 32-bit linux.
443
444
But some arm64 kernels do not handle these faults in 32-bit programs.
445
So we have unhandled exception for such instructions.
446
Probably some new arm64 kernels have fixed it, and unaligned
447
paired-access instructions work in new kernels?
448
449
problem-3 : compiler for 32-bit arm:
450
Compilers use LDRD/STRD/LDM/STM for UInt64 accesses
451
and for another cases where two 32-bit accesses are fused
452
to one multi-access instruction.
453
So UInt64 variables must be aligned for 32-bit, and each
454
32-bit access must be aligned for 32-bit, if we want to
455
avoid "Alignment fault" exception (handled or unhandled).
456
457
problem-4 : performace:
458
Even if unaligned access is handled by kernel, it will be slow.
459
So if we allow unaligned access, we can get fast unaligned
460
single-access, and slow unaligned paired-access.
461
462
We don't allow unaligned access on 32-bit arm, because compiler
463
genarates paired-access instructions that require 32-bit alignment,
464
and some arm64 kernels have no handler for these instructions.
465
Also unaligned paired-access instructions will be slow, if kernel handles them.
466
*/
467
// it must be disabled:
468
// #define MY_CPU_LE_UNALIGN
469
#endif
470
#endif
471
472
473
#ifdef MY_CPU_LE_UNALIGN
474
475
#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
476
#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
477
#ifdef MY_CPU_LE_UNALIGN_64
478
#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
479
#define SetUi64(p, v) { *(UInt64 *)(void *)(p) = (v); }
480
#endif
481
482
#define SetUi16(p, v) { *(UInt16 *)(void *)(p) = (v); }
483
#define SetUi32(p, v) { *(UInt32 *)(void *)(p) = (v); }
484
485
#else
486
487
#define GetUi16(p) ( (UInt16) ( \
488
((const Byte *)(p))[0] | \
489
((UInt16)((const Byte *)(p))[1] << 8) ))
490
491
#define GetUi32(p) ( \
492
((const Byte *)(p))[0] | \
493
((UInt32)((const Byte *)(p))[1] << 8) | \
494
((UInt32)((const Byte *)(p))[2] << 16) | \
495
((UInt32)((const Byte *)(p))[3] << 24))
496
497
#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
498
_ppp_[0] = (Byte)_vvv_; \
499
_ppp_[1] = (Byte)(_vvv_ >> 8); }
500
501
#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
502
_ppp_[0] = (Byte)_vvv_; \
503
_ppp_[1] = (Byte)(_vvv_ >> 8); \
504
_ppp_[2] = (Byte)(_vvv_ >> 16); \
505
_ppp_[3] = (Byte)(_vvv_ >> 24); }
506
507
#endif
508
509
510
#ifndef GetUi64
511
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
512
#endif
513
514
#ifndef SetUi64
515
#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \
516
SetUi32(_ppp2_ , (UInt32)_vvv2_) \
517
SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)) }
518
#endif
519
520
521
#if defined(MY_CPU_LE_UNALIGN) && defined(Z7_CPU_FAST_BSWAP_SUPPORTED)
522
523
#if 0
524
// Z7_BSWAP16 can be slow for x86-msvc
525
#define GetBe16_to32(p) (Z7_BSWAP16 (*(const UInt16 *)(const void *)(p)))
526
#else
527
#define GetBe16_to32(p) (Z7_BSWAP32 (*(const UInt16 *)(const void *)(p)) >> 16)
528
#endif
529
530
#define GetBe32(p) Z7_BSWAP32 (*(const UInt32 *)(const void *)(p))
531
#define SetBe32(p, v) { (*(UInt32 *)(void *)(p)) = Z7_BSWAP32(v); }
532
533
#if defined(MY_CPU_LE_UNALIGN_64)
534
#define GetBe64(p) Z7_BSWAP64 (*(const UInt64 *)(const void *)(p))
535
#define SetBe64(p, v) { (*(UInt64 *)(void *)(p)) = Z7_BSWAP64(v); }
536
#endif
537
538
#else
539
540
#define GetBe32(p) ( \
541
((UInt32)((const Byte *)(p))[0] << 24) | \
542
((UInt32)((const Byte *)(p))[1] << 16) | \
543
((UInt32)((const Byte *)(p))[2] << 8) | \
544
((const Byte *)(p))[3] )
545
546
#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
547
_ppp_[0] = (Byte)(_vvv_ >> 24); \
548
_ppp_[1] = (Byte)(_vvv_ >> 16); \
549
_ppp_[2] = (Byte)(_vvv_ >> 8); \
550
_ppp_[3] = (Byte)_vvv_; }
551
552
#endif
553
554
#ifndef GetBe64
555
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
556
#endif
557
558
#ifndef SetBe64
559
#define SetBe64(p, v) { Byte *_ppp_ = (Byte *)(p); UInt64 _vvv_ = (v); \
560
_ppp_[0] = (Byte)(_vvv_ >> 56); \
561
_ppp_[1] = (Byte)(_vvv_ >> 48); \
562
_ppp_[2] = (Byte)(_vvv_ >> 40); \
563
_ppp_[3] = (Byte)(_vvv_ >> 32); \
564
_ppp_[4] = (Byte)(_vvv_ >> 24); \
565
_ppp_[5] = (Byte)(_vvv_ >> 16); \
566
_ppp_[6] = (Byte)(_vvv_ >> 8); \
567
_ppp_[7] = (Byte)_vvv_; }
568
#endif
569
570
#ifndef GetBe16
571
#ifdef GetBe16_to32
572
#define GetBe16(p) ( (UInt16) GetBe16_to32(p))
573
#else
574
#define GetBe16(p) ( (UInt16) ( \
575
((UInt16)((const Byte *)(p))[0] << 8) | \
576
((const Byte *)(p))[1] ))
577
#endif
578
#endif
579
580
581
#if defined(MY_CPU_BE)
582
#define Z7_CONV_BE_TO_NATIVE_CONST32(v) (v)
583
#define Z7_CONV_LE_TO_NATIVE_CONST32(v) Z7_BSWAP32_CONST(v)
584
#define Z7_CONV_NATIVE_TO_BE_32(v) (v)
585
// #define Z7_GET_NATIVE16_FROM_2_BYTES(b0, b1) ((b1) | ((b0) << 8))
586
#elif defined(MY_CPU_LE)
587
#define Z7_CONV_BE_TO_NATIVE_CONST32(v) Z7_BSWAP32_CONST(v)
588
#define Z7_CONV_LE_TO_NATIVE_CONST32(v) (v)
589
#define Z7_CONV_NATIVE_TO_BE_32(v) Z7_BSWAP32(v)
590
// #define Z7_GET_NATIVE16_FROM_2_BYTES(b0, b1) ((b0) | ((b1) << 8))
591
#else
592
#error Stop_Compiling_Unknown_Endian_CONV
593
#endif
594
595
596
#if defined(MY_CPU_BE)
597
598
#define GetBe64a(p) (*(const UInt64 *)(const void *)(p))
599
#define GetBe32a(p) (*(const UInt32 *)(const void *)(p))
600
#define GetBe16a(p) (*(const UInt16 *)(const void *)(p))
601
#define SetBe32a(p, v) { *(UInt32 *)(void *)(p) = (v); }
602
#define SetBe16a(p, v) { *(UInt16 *)(void *)(p) = (v); }
603
604
// gcc and clang for powerpc can transform load byte access to load reverse word access.
605
// sp we can use byte access instead of word access. Z7_BSWAP64 cab be slow
606
#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED) && defined(MY_CPU_64BIT)
607
#define GetUi64a(p) Z7_BSWAP64 (*(const UInt64 *)(const void *)(p))
608
#else
609
#define GetUi64a(p) GetUi64(p)
610
#endif
611
612
#if 1 && defined(Z7_CPU_FAST_BSWAP_SUPPORTED)
613
#define GetUi32a(p) Z7_BSWAP32 (*(const UInt32 *)(const void *)(p))
614
#else
615
#define GetUi32a(p) GetUi32(p)
616
#endif
617
618
#define GetUi16a(p) GetUi16(p)
619
#define SetUi32a(p, v) SetUi32(p, v)
620
#define SetUi16a(p, v) SetUi16(p, v)
621
622
#elif defined(MY_CPU_LE)
623
624
#define GetUi64a(p) (*(const UInt64 *)(const void *)(p))
625
#define GetUi32a(p) (*(const UInt32 *)(const void *)(p))
626
#define GetUi16a(p) (*(const UInt16 *)(const void *)(p))
627
#define SetUi32a(p, v) { *(UInt32 *)(void *)(p) = (v); }
628
#define SetUi16a(p, v) { *(UInt16 *)(void *)(p) = (v); }
629
630
#define GetBe64a(p) GetBe64(p)
631
#define GetBe32a(p) GetBe32(p)
632
#define GetBe16a(p) GetBe16(p)
633
#define SetBe32a(p, v) SetBe32(p, v)
634
#define SetBe16a(p, v) SetBe16(p, v)
635
636
#else
637
#error Stop_Compiling_Unknown_Endian_CPU_a
638
#endif
639
640
641
#ifndef GetBe16_to32
642
#define GetBe16_to32(p) GetBe16(p)
643
#endif
644
645
646
#if defined(MY_CPU_X86_OR_AMD64) \
647
|| defined(MY_CPU_ARM_OR_ARM64) \
648
|| defined(MY_CPU_PPC_OR_PPC64)
649
#define Z7_CPU_FAST_ROTATE_SUPPORTED
650
#endif
651
652
653
#ifdef MY_CPU_X86_OR_AMD64
654
655
void Z7_FASTCALL z7_x86_cpuid(UInt32 a[4], UInt32 function);
656
UInt32 Z7_FASTCALL z7_x86_cpuid_GetMaxFunc(void);
657
#if defined(MY_CPU_AMD64)
658
#define Z7_IF_X86_CPUID_SUPPORTED
659
#else
660
#define Z7_IF_X86_CPUID_SUPPORTED if (z7_x86_cpuid_GetMaxFunc())
661
#endif
662
663
BoolInt CPU_IsSupported_AES(void);
664
BoolInt CPU_IsSupported_AVX(void);
665
BoolInt CPU_IsSupported_AVX2(void);
666
BoolInt CPU_IsSupported_AVX512F_AVX512VL(void);
667
BoolInt CPU_IsSupported_VAES_AVX2(void);
668
BoolInt CPU_IsSupported_CMOV(void);
669
BoolInt CPU_IsSupported_SSE(void);
670
BoolInt CPU_IsSupported_SSE2(void);
671
BoolInt CPU_IsSupported_SSSE3(void);
672
BoolInt CPU_IsSupported_SSE41(void);
673
BoolInt CPU_IsSupported_SHA(void);
674
BoolInt CPU_IsSupported_SHA512(void);
675
BoolInt CPU_IsSupported_PageGB(void);
676
677
#elif defined(MY_CPU_ARM_OR_ARM64)
678
679
BoolInt CPU_IsSupported_CRC32(void);
680
BoolInt CPU_IsSupported_NEON(void);
681
682
#if defined(_WIN32)
683
BoolInt CPU_IsSupported_CRYPTO(void);
684
#define CPU_IsSupported_SHA1 CPU_IsSupported_CRYPTO
685
#define CPU_IsSupported_SHA2 CPU_IsSupported_CRYPTO
686
#define CPU_IsSupported_AES CPU_IsSupported_CRYPTO
687
#else
688
BoolInt CPU_IsSupported_SHA1(void);
689
BoolInt CPU_IsSupported_SHA2(void);
690
BoolInt CPU_IsSupported_AES(void);
691
#endif
692
BoolInt CPU_IsSupported_SHA512(void);
693
694
#endif
695
696
#if defined(__APPLE__)
697
int z7_sysctlbyname_Get(const char *name, void *buf, size_t *bufSize);
698
int z7_sysctlbyname_Get_UInt32(const char *name, UInt32 *val);
699
#endif
700
701
EXTERN_C_END
702
703
#endif
704
705