view src/win32/7zip/7z/C/CpuArch.h @ 6:458a4f18f3cd

working on lua generation
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:48:33 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 /* CpuArch.h
2 2008-08-05
3 Igor Pavlov
4 Public domain */
6 #ifndef __CPUARCH_H
7 #define __CPUARCH_H
9 /*
10 LITTLE_ENDIAN_UNALIGN means:
11 1) CPU is LITTLE_ENDIAN
12 2) it's allowed to make unaligned memory accesses
13 if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
14 about these properties of platform.
15 */
17 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
18 #define LITTLE_ENDIAN_UNALIGN
19 #endif
21 #ifdef LITTLE_ENDIAN_UNALIGN
23 #define GetUi16(p) (*(const UInt16 *)(p))
24 #define GetUi32(p) (*(const UInt32 *)(p))
25 #define GetUi64(p) (*(const UInt64 *)(p))
26 #define SetUi32(p, d) *(UInt32 *)(p) = (d);
28 #else
30 #define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
32 #define GetUi32(p) ( \
33 ((const Byte *)(p))[0] | \
34 ((UInt32)((const Byte *)(p))[1] << 8) | \
35 ((UInt32)((const Byte *)(p))[2] << 16) | \
36 ((UInt32)((const Byte *)(p))[3] << 24))
38 #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
40 #define SetUi32(p, d) { UInt32 _x_ = (d); \
41 ((Byte *)(p))[0] = (Byte)_x_; \
42 ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
43 ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
44 ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
46 #endif
48 #if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
50 #pragma intrinsic(_byteswap_ulong)
51 #pragma intrinsic(_byteswap_uint64)
52 #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
53 #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
55 #else
57 #define GetBe32(p) ( \
58 ((UInt32)((const Byte *)(p))[0] << 24) | \
59 ((UInt32)((const Byte *)(p))[1] << 16) | \
60 ((UInt32)((const Byte *)(p))[2] << 8) | \
61 ((const Byte *)(p))[3] )
63 #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
65 #endif
67 #define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
69 #endif