Declare qregister[u]int, an integer the size of the machine's word

In almost all platforms, sizeof(qregisterint) == sizeof(void*) ==
sizeof(qptrdiff). It's different for architectures that have a pointer
with a size different from the machine word. This allows us to declare
variables of the most optimal size, even if the pointers are too wide or
too narrow.

The only currently-known architectures to match that case are the ILP32
builds on x86-64 (a.k.a "x32") and IA-64 (option -milp32, only available
on HP-UXi), which have 64-bit registers but 32-bit pointers.

Change-Id: I0f126b70ea9ea326bd3143797287e4b98210d36d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Thiago Macieira 2013-10-19 17:00:39 -04:00 committed by The Qt Project
parent 1cc0a18d79
commit 07e831d7ff
2 changed files with 23 additions and 0 deletions

View File

@ -437,6 +437,8 @@ template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qin
template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
typedef QIntegerForSizeof<void*>::Unsigned quintptr;
typedef QIntegerForSizeof<void*>::Signed qptrdiff;
typedef qptrdiff qintptr;

View File

@ -196,6 +196,7 @@
# define Q_PROCESSOR_X86 6
# define Q_PROCESSOR_X86_64
# define Q_BYTE_ORDER Q_LITTLE_ENDIAN
# define Q_PROCESSOR_WORDSIZE 8
/*
Itanium (IA-64) family, no revisions or variants
@ -204,6 +205,7 @@
*/
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
# define Q_PROCESSOR_IA64
# define Q_PROCESSOR_WORDSIZE 8
// Q_BYTE_ORDER not defined, use endianness auto-detection
/*
@ -324,4 +326,23 @@
# endif
#endif
/*
Define Q_PROCESSOR_WORDSIZE to be the size of the machine's word (usually,
the size of the register). On some architectures where a pointer could be
smaller than the register, the macro is defined above.
Try our best to define it to a literal, so it can be used in the preprocessor,
but fall back to sizeof(void*) on practically every 32-bit build.
*/
#ifndef Q_PROCESSOR_WORDSIZE
# ifdef __SIZEOF_POINTER__
/* GCC & friends define this */
# define Q_PROCESSOR_WORDSIZE __SIZEOF_POINTER__
# elif defined(_LP64) || defined(__LP64__) || defined(WIN64) || defined(_WIN64)
# define Q_PROCESSOR_WORDSIZE 8
# else
# define Q_PROCESSOR_WORDSIZE sizeof(void*)
# endif
#endif
#endif // QPROCESSORDETECTION_H