annotate 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
rev   line source
rlm@1 1 /* CpuArch.h
rlm@1 2 2008-08-05
rlm@1 3 Igor Pavlov
rlm@1 4 Public domain */
rlm@1 5
rlm@1 6 #ifndef __CPUARCH_H
rlm@1 7 #define __CPUARCH_H
rlm@1 8
rlm@1 9 /*
rlm@1 10 LITTLE_ENDIAN_UNALIGN means:
rlm@1 11 1) CPU is LITTLE_ENDIAN
rlm@1 12 2) it's allowed to make unaligned memory accesses
rlm@1 13 if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
rlm@1 14 about these properties of platform.
rlm@1 15 */
rlm@1 16
rlm@1 17 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
rlm@1 18 #define LITTLE_ENDIAN_UNALIGN
rlm@1 19 #endif
rlm@1 20
rlm@1 21 #ifdef LITTLE_ENDIAN_UNALIGN
rlm@1 22
rlm@1 23 #define GetUi16(p) (*(const UInt16 *)(p))
rlm@1 24 #define GetUi32(p) (*(const UInt32 *)(p))
rlm@1 25 #define GetUi64(p) (*(const UInt64 *)(p))
rlm@1 26 #define SetUi32(p, d) *(UInt32 *)(p) = (d);
rlm@1 27
rlm@1 28 #else
rlm@1 29
rlm@1 30 #define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
rlm@1 31
rlm@1 32 #define GetUi32(p) ( \
rlm@1 33 ((const Byte *)(p))[0] | \
rlm@1 34 ((UInt32)((const Byte *)(p))[1] << 8) | \
rlm@1 35 ((UInt32)((const Byte *)(p))[2] << 16) | \
rlm@1 36 ((UInt32)((const Byte *)(p))[3] << 24))
rlm@1 37
rlm@1 38 #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
rlm@1 39
rlm@1 40 #define SetUi32(p, d) { UInt32 _x_ = (d); \
rlm@1 41 ((Byte *)(p))[0] = (Byte)_x_; \
rlm@1 42 ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
rlm@1 43 ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
rlm@1 44 ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
rlm@1 45
rlm@1 46 #endif
rlm@1 47
rlm@1 48 #if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
rlm@1 49
rlm@1 50 #pragma intrinsic(_byteswap_ulong)
rlm@1 51 #pragma intrinsic(_byteswap_uint64)
rlm@1 52 #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
rlm@1 53 #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
rlm@1 54
rlm@1 55 #else
rlm@1 56
rlm@1 57 #define GetBe32(p) ( \
rlm@1 58 ((UInt32)((const Byte *)(p))[0] << 24) | \
rlm@1 59 ((UInt32)((const Byte *)(p))[1] << 16) | \
rlm@1 60 ((UInt32)((const Byte *)(p))[2] << 8) | \
rlm@1 61 ((const Byte *)(p))[3] )
rlm@1 62
rlm@1 63 #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
rlm@1 64
rlm@1 65 #endif
rlm@1 66
rlm@1 67 #define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
rlm@1 68
rlm@1 69 #endif