diff options
author | Bastien Bouclet | 2017-10-25 19:17:11 +0200 |
---|---|---|
committer | GitHub | 2017-10-25 19:17:11 +0200 |
commit | bd82345f0b634e5ccf7b2412a0d7cad7232057c5 (patch) | |
tree | 724b183a5e39a6f3f52067d2f1214a7728b2709a /common | |
parent | 2ded98b482f30d2a990f06365b7f612ab4d115b2 (diff) | |
parent | bbdbd85324a9c02019e242ab93b3ae569292356c (diff) | |
download | scummvm-rg350-bd82345f0b634e5ccf7b2412a0d7cad7232057c5.tar.gz scummvm-rg350-bd82345f0b634e5ccf7b2412a0d7cad7232057c5.tar.bz2 scummvm-rg350-bd82345f0b634e5ccf7b2412a0d7cad7232057c5.zip |
Merge pull request #1035 from bgK/require-64bits-integers
BUILD: Require 64bits integers
Diffstat (limited to 'common')
-rw-r--r-- | common/endian.h | 24 | ||||
-rw-r--r-- | common/hash-ptr.h | 43 | ||||
-rw-r--r-- | common/scummsys.h | 42 | ||||
-rw-r--r-- | common/stream.h | 20 |
4 files changed, 62 insertions, 67 deletions
diff --git a/common/endian.h b/common/endian.h index e924b5142d..a6b80f2451 100644 --- a/common/endian.h +++ b/common/endian.h @@ -49,7 +49,6 @@ # error No endianness defined #endif -#ifdef HAVE_INT64 #define SWAP_CONSTANT_64(a) \ ((uint64)((((a) >> 56) & 0x000000FF) | \ (((a) >> 40) & 0x0000FF00) | \ @@ -59,7 +58,6 @@ (((a) & 0x00FF0000) << 24) | \ (((a) & 0x0000FF00) << 40) | \ (((a) & 0x000000FF) << 56) )) -#endif #define SWAP_CONSTANT_32(a) \ ((uint32)((((a) >> 24) & 0x00FF) | \ @@ -150,7 +148,6 @@ } #endif -#ifdef HAVE_INT64 /** * Swap the bytes in a 64 bit word in order to convert LE encoded data to BE * and vice versa. @@ -202,7 +199,6 @@ } #endif -#endif // HAVE_INT64 /** @@ -253,7 +249,6 @@ ((Unaligned32 *)ptr)->val = value; } -#ifdef HAVE_INT64 FORCEINLINE uint64 READ_UINT64(const void *ptr) { struct Unaligned64 { uint64 val; } __attribute__ ((__packed__, __may_alias__)); return ((const Unaligned64 *)ptr)->val; @@ -263,7 +258,6 @@ struct Unaligned64 { uint64 val; } __attribute__((__packed__, __may_alias__)); ((Unaligned64 *)ptr)->val = value; } -#endif #elif !defined(SCUMM_NEED_ALIGNMENT) @@ -283,7 +277,6 @@ *(uint32 *)(ptr) = value; } -#ifdef HAVE_INT64 FORCEINLINE uint64 READ_UINT64(const void *ptr) { return *(const uint64 *)(ptr); } @@ -291,7 +284,6 @@ FORCEINLINE void WRITE_UINT64(void *ptr, uint64 value) { *(uint64 *)(ptr) = value; } -#endif // use software fallback by loading each byte explicitely @@ -319,7 +311,6 @@ b[2] = (uint8)(value >> 16); b[3] = (uint8)(value >> 24); } -#ifdef HAVE_INT64 inline uint64 READ_UINT64(const void *ptr) { const uint8 *b = (const uint8 *)ptr; return ((uint64)b[7] << 56) | ((uint64)b[6] << 48) | ((uint64)b[5] << 40) | ((uint64)b[4] << 32) | ((uint64)b[3] << 24) | ((uint64)b[2] << 16) | ((uint64)b[1] << 8) | ((uint64)b[0]); @@ -335,7 +326,6 @@ b[6] = (uint8)(value >> 48); b[7] = (uint8)(value >> 56); } -#endif # elif defined(SCUMM_BIG_ENDIAN) @@ -359,7 +349,6 @@ b[2] = (uint8)(value >> 8); b[3] = (uint8)(value >> 0); } -#ifdef HAVE_INT64 inline uint64 READ_UINT64(const void *ptr) { const uint8 *b = (const uint8 *)ptr; return ((uint64)b[0] << 56) | ((uint64)b[1] << 48) | ((uint64)b[2] << 40) | ((uint64)b[3] << 32) | ((uint64)b[4] << 24) | ((uint64)b[5] << 16) | ((uint64)b[6] << 8) | ((uint64)b[7]); @@ -375,7 +364,6 @@ b[6] = (uint8)(value >> 8); b[7] = (uint8)(value >> 0); } -#endif # endif @@ -409,7 +397,6 @@ #define CONSTANT_BE_32(a) SWAP_CONSTANT_32(a) #define CONSTANT_BE_16(a) SWAP_CONSTANT_16(a) -#ifdef HAVE_INT64 #define READ_LE_UINT64(a) READ_UINT64(a) #define WRITE_LE_UINT64(a, v) WRITE_UINT64(a, v) #define FROM_LE_64(a) ((uint64)(a)) @@ -418,7 +405,6 @@ #define TO_BE_64(a) SWAP_BYTES_64(a) #define CONSTANT_LE_64(a) ((uint64)(a)) #define CONSTANT_BE_64(a) SWAP_CONSTANT_64(a) -#endif // if the unaligned load and the byteswap take alot instructions its better to directly read and invert # if defined(SCUMM_NEED_ALIGNMENT) && !defined(__mips__) @@ -443,7 +429,6 @@ b[2] = (uint8)(value >> 8); b[3] = (uint8)(value >> 0); } -#ifdef HAVE_INT64 inline uint64 READ_BE_UINT64(const void *ptr) { const uint8 *b = (const uint8 *)ptr; return ((uint64)b[0] << 56) | ((uint64)b[1] << 48) | ((uint64)b[2] << 40) | ((uint64)b[3] << 32) | ((uint64)b[4] << 24) | ((uint64)b[5] << 16) | ((uint64)b[6] << 8) | ((uint64)b[7]); @@ -459,7 +444,6 @@ b[6] = (uint8)(value >> 8); b[7] = (uint8)(value >> 0); } -#endif # else @@ -475,14 +459,12 @@ inline void WRITE_BE_UINT32(void *ptr, uint32 value) { WRITE_UINT32(ptr, SWAP_BYTES_32(value)); } -#ifdef HAVE_INT64 inline uint64 READ_BE_UINT64(const void *ptr) { return SWAP_BYTES_64(READ_UINT64(ptr)); } inline void WRITE_BE_UINT64(void *ptr, uint64 value) { WRITE_UINT64(ptr, SWAP_BYTES_64(value)); } -#endif # endif // if defined(SCUMM_NEED_ALIGNMENT) @@ -512,7 +494,6 @@ #define CONSTANT_BE_32(a) ((uint32)(a)) #define CONSTANT_BE_16(a) ((uint16)(a)) -#ifdef HAVE_INT64 #define READ_BE_UINT64(a) READ_UINT64(a) #define WRITE_BE_UINT64(a, v) WRITE_UINT64(a, v) #define FROM_LE_64(a) SWAP_BYTES_64(a) @@ -521,7 +502,6 @@ #define TO_BE_64(a) ((uint64)(a)) #define CONSTANT_LE_64(a) SWAP_CONSTANT_64(a) #define CONSTANT_BE_64(a) ((uint64)(a)) -#endif // if the unaligned load and the byteswap take alot instructions its better to directly read and invert # if defined(SCUMM_NEED_ALIGNMENT) && !defined(__mips__) @@ -547,7 +527,6 @@ b[3] = (uint8)(value >> 24); } -#ifdef HAVE_INT64 inline uint64 READ_LE_UINT64(const void *ptr) { const uint8 *b = (const uint8 *)ptr; return ((uint64)b[7] << 56) | ((uint64)b[6] << 48) | ((uint64)b[5] << 40) | ((uint64)b[4] << 32) | ((uint64)b[3] << 24) | ((uint64)b[2] << 16) | ((uint64)b[1] << 8) | ((uint64)b[0]); @@ -563,7 +542,6 @@ b[6] = (uint8)(value >> 48); b[7] = (uint8)(value >> 56); } -#endif # else @@ -579,14 +557,12 @@ inline void WRITE_LE_UINT32(void *ptr, uint32 value) { WRITE_UINT32(ptr, SWAP_BYTES_32(value)); } -#ifdef HAVE_INT64 inline uint64 READ_LE_UINT64(const void *ptr) { return SWAP_BYTES_64(READ_UINT64(ptr)); } inline void WRITE_LE_UINT64(void *ptr, uint64 value) { WRITE_UINT64(ptr, SWAP_BYTES_64(value)); } -#endif # endif // if defined(SCUMM_NEED_ALIGNMENT) diff --git a/common/hash-ptr.h b/common/hash-ptr.h new file mode 100644 index 0000000000..1099478c3b --- /dev/null +++ b/common/hash-ptr.h @@ -0,0 +1,43 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef COMMON_HASH_PTR_H +#define COMMON_HASH_PTR_H + +#include "common/func.h" + +namespace Common { + +/** + * Partial specialization of the Hash functor to be able to use pointers as HashMap keys + */ +template<typename T> +struct Hash<T *> { + uint operator()(T * const &v) const { + uint x = static_cast<uint>(reinterpret_cast<uintptr>(v)); + return x + (x >> 3); + } +}; + +} // End of namespace Common + +#endif diff --git a/common/scummsys.h b/common/scummsys.h index 432dd74fa7..4740127d2f 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -310,26 +310,6 @@ #endif // -// Determine 64 bitness -// Reference: http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros -// -#if !defined(HAVE_CONFIG_H) - - #if defined(__x86_64__) || \ - defined(_M_X64) || \ - defined(__ppc64__) || \ - defined(__powerpc64__) || \ - defined(__LP64__) - - #if !defined(SCUMM_64BITS) - #define SCUMM_64BITS - #endif - - #endif - -#endif - -// // Some more system specific settings. // TODO/FIXME: All of these should be moved to backend specific files (such as portdefs.h) // @@ -452,11 +432,27 @@ #endif #endif - // -// Overlay color type (FIXME: shouldn't be declared here) +// Determine 64 bitness +// Reference: http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros // -typedef uint16 OverlayColor; +#if !defined(HAVE_CONFIG_H) + +#if defined(__x86_64__) || \ + defined(_M_X64) || \ + defined(__ppc64__) || \ + defined(__powerpc64__) || \ + defined(__LP64__) + +typedef uint64 uintptr; + +#else + +typedef uint32 uintptr; + +#endif + +#endif #include "common/forbidden.h" diff --git a/common/stream.h b/common/stream.h index 6932c7d2d0..fed81c9192 100644 --- a/common/stream.h +++ b/common/stream.h @@ -133,12 +133,10 @@ public: write(&value, 4); } -#ifdef HAVE_INT64 void writeUint64LE(uint64 value) { value = TO_LE_64(value); write(&value, 8); } -#endif void writeUint16BE(uint16 value) { value = TO_BE_16(value); @@ -150,12 +148,10 @@ public: write(&value, 4); } -#ifdef HAVE_INT64 void writeUint64BE(uint64 value) { value = TO_BE_64(value); write(&value, 8); } -#endif FORCEINLINE void writeSint16LE(int16 value) { writeUint16LE((uint16)value); @@ -165,11 +161,9 @@ public: writeUint32LE((uint32)value); } -#ifdef HAVE_INT64 FORCEINLINE void writeSint64LE(int64 value) { writeUint64LE((uint64)value); } -#endif FORCEINLINE void writeSint16BE(int16 value) { writeUint16BE((uint16)value); @@ -179,11 +173,9 @@ public: writeUint32BE((uint32)value); } -#ifdef HAVE_INT64 FORCEINLINE void writeSint64BE(int64 value) { writeUint64BE((uint64)value); } -#endif /** @@ -301,7 +293,6 @@ public: return FROM_LE_32(val); } -#ifdef HAVE_INT64 /** * Read an unsigned 64-bit word stored in little endian (LSB first) order * from the stream and return it. @@ -314,7 +305,6 @@ public: read(&val, 8); return FROM_LE_64(val); } -#endif /** * Read an unsigned 16-bit word stored in big endian (MSB first) order @@ -342,7 +332,6 @@ public: return FROM_BE_32(val); } -#ifdef HAVE_INT64 /** * Read an unsigned 64-bit word stored in big endian (MSB first) order * from the stream and return it. @@ -355,7 +344,6 @@ public: read(&val, 8); return FROM_BE_64(val); } -#endif /** * Read a signed 16-bit word stored in little endian (LSB first) order @@ -379,7 +367,6 @@ public: return (int32)readUint32LE(); } -#ifdef HAVE_INT64 /** * Read a signed 64-bit word stored in little endian (LSB first) order * from the stream and return it. @@ -390,7 +377,6 @@ public: FORCEINLINE int64 readSint64LE() { return (int64)readUint64LE(); } -#endif /** * Read a signed 16-bit word stored in big endian (MSB first) order @@ -414,7 +400,6 @@ public: return (int32)readUint32BE(); } -#ifdef HAVE_INT64 /** * Read a signed 64-bit word stored in big endian (MSB first) order * from the stream and return it. @@ -425,7 +410,6 @@ public: FORCEINLINE int64 readSint64BE() { return (int64)readUint64BE(); } -#endif /** * Read a 32-bit floating point value stored in little endian (LSB first) @@ -600,13 +584,11 @@ public: return (_bigEndian) ? TO_BE_32(val) : TO_LE_32(val); } -#ifdef HAVE_INT64 uint64 readUint64() { uint64 val; read(&val, 8); return (_bigEndian) ? TO_BE_64(val) : TO_LE_64(val); } -#endif FORCEINLINE int16 readSint16() { return (int16)readUint16(); @@ -616,11 +598,9 @@ public: return (int32)readUint32(); } -#ifdef HAVE_INT64 FORCEINLINE int64 readSint64() { return (int64)readUint64(); } -#endif }; /** |