diff src/win32/7zip/7z/C/CpuArch.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/7zip/7z/C/CpuArch.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* CpuArch.h
     1.5 +2008-08-05
     1.6 +Igor Pavlov
     1.7 +Public domain */
     1.8 +
     1.9 +#ifndef __CPUARCH_H
    1.10 +#define __CPUARCH_H
    1.11 +
    1.12 +/*
    1.13 +LITTLE_ENDIAN_UNALIGN means:
    1.14 +  1) CPU is LITTLE_ENDIAN
    1.15 +  2) it's allowed to make unaligned memory accesses
    1.16 +if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
    1.17 +about these properties of platform.
    1.18 +*/
    1.19 +
    1.20 +#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
    1.21 +#define LITTLE_ENDIAN_UNALIGN
    1.22 +#endif
    1.23 +
    1.24 +#ifdef LITTLE_ENDIAN_UNALIGN
    1.25 +
    1.26 +#define GetUi16(p) (*(const UInt16 *)(p))
    1.27 +#define GetUi32(p) (*(const UInt32 *)(p))
    1.28 +#define GetUi64(p) (*(const UInt64 *)(p))
    1.29 +#define SetUi32(p, d) *(UInt32 *)(p) = (d);
    1.30 +
    1.31 +#else
    1.32 +
    1.33 +#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
    1.34 +
    1.35 +#define GetUi32(p) ( \
    1.36 +             ((const Byte *)(p))[0]        | \
    1.37 +    ((UInt32)((const Byte *)(p))[1] <<  8) | \
    1.38 +    ((UInt32)((const Byte *)(p))[2] << 16) | \
    1.39 +    ((UInt32)((const Byte *)(p))[3] << 24))
    1.40 +
    1.41 +#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
    1.42 +
    1.43 +#define SetUi32(p, d) { UInt32 _x_ = (d); \
    1.44 +    ((Byte *)(p))[0] = (Byte)_x_; \
    1.45 +    ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
    1.46 +    ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
    1.47 +    ((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
    1.48 +
    1.49 +#endif
    1.50 +
    1.51 +#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
    1.52 +
    1.53 +#pragma intrinsic(_byteswap_ulong)
    1.54 +#pragma intrinsic(_byteswap_uint64)
    1.55 +#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
    1.56 +#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
    1.57 +
    1.58 +#else
    1.59 +
    1.60 +#define GetBe32(p) ( \
    1.61 +    ((UInt32)((const Byte *)(p))[0] << 24) | \
    1.62 +    ((UInt32)((const Byte *)(p))[1] << 16) | \
    1.63 +    ((UInt32)((const Byte *)(p))[2] <<  8) | \
    1.64 +             ((const Byte *)(p))[3] )
    1.65 +
    1.66 +#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
    1.67 +
    1.68 +#endif
    1.69 +
    1.70 +#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
    1.71 +
    1.72 +#endif