hwint.h revision 169689
152284Sobrien/* HOST_WIDE_INT definitions for the GNU compiler. 2169689Skan Copyright (C) 1998, 2002, 2004 Free Software Foundation, Inc. 352284Sobrien 490075Sobrien This file is part of GCC. 552284Sobrien 652284Sobrien Provide definitions for macros which depend on HOST_BITS_PER_INT 790075Sobrien and HOST_BITS_PER_LONG. */ 852284Sobrien 990075Sobrien#ifndef GCC_HWINT_H 1090075Sobrien#define GCC_HWINT_H 1152284Sobrien 1290075Sobrien/* This describes the machine the compiler is hosted on. */ 1390075Sobrien#define HOST_BITS_PER_CHAR CHAR_BIT 1490075Sobrien#define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT) 1590075Sobrien#define HOST_BITS_PER_INT (CHAR_BIT * SIZEOF_INT) 1690075Sobrien#define HOST_BITS_PER_LONG (CHAR_BIT * SIZEOF_LONG) 1752284Sobrien 18169689Skan/* The string that should be inserted into a printf style format to 19169689Skan indicate a "long long" operand. */ 20169689Skan#ifndef HOST_LONG_LONG_FORMAT 21169689Skan#define HOST_LONG_LONG_FORMAT "ll" 22169689Skan#endif 23169689Skan 24132718Skan/* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but 25132718Skan GCC_VERSION >= 3000, assume this is the second or later stage of a 26132718Skan bootstrap, we do have long long, and it's 64 bits. (This is 27132718Skan required by C99; we do have some ports that violate that assumption 28132718Skan but they're all cross-compile-only.) Just in case, force a 29132718Skan constraint violation if that assumption is incorrect. */ 30132718Skan#if !defined HAVE_LONG_LONG 31132718Skan# if GCC_VERSION >= 3000 32132718Skan# define HAVE_LONG_LONG 1 33132718Skan# define SIZEOF_LONG_LONG 8 34132718Skanextern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; 35132718Skan# endif 36132718Skan#endif 37132718Skan 3890075Sobrien#ifdef HAVE_LONG_LONG 3990075Sobrien# define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG) 40132718Skan#endif 4196263Sobrien#ifdef HAVE___INT64 42132718Skan# define HOST_BITS_PER___INT64 (CHAR_BIT * SIZEOF___INT64) 4390075Sobrien#endif 4490075Sobrien 45132718Skan/* Set HOST_WIDE_INT. This should be the widest efficient host 46132718Skan integer type. It can be 32 or 64 bits, except that if we are 47132718Skan targeting a machine with 64-bit size_t then it has to be 64 bits. 4852284Sobrien 49132718Skan With a sane ABI, 'long' is the largest efficient host integer type. 50132718Skan Thus, we use that unless we have to use 'long long' or '__int64' 51132718Skan because we're targeting a 64-bit machine from a 32-bit host. */ 5290075Sobrien 53132718Skan#if HOST_BITS_PER_LONG >= 64 || !defined NEED_64BIT_HOST_WIDE_INT 54132718Skan# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG 55132718Skan# define HOST_WIDE_INT long 56132718Skan#else 57132718Skan# if HOST_BITS_PER_LONGLONG >= 64 5890075Sobrien# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG 5990075Sobrien# define HOST_WIDE_INT long long 6090075Sobrien# else 61132718Skan# if HOST_BITS_PER___INT64 >= 64 62132718Skan# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER___INT64 63132718Skan# define HOST_WIDE_INT __int64 64132718Skan# else 65132718Skan #error "Unable to find a suitable type for HOST_WIDE_INT" 6690075Sobrien# endif 6790075Sobrien# endif 6890075Sobrien#endif 6990075Sobrien 70132718Skan/* Various printf format strings for HOST_WIDE_INT. */ 7152284Sobrien 72132718Skan#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG 73132718Skan# define HOST_WIDE_INT_PRINT "l" 74132718Skan# define HOST_WIDE_INT_PRINT_C "L" 75132718Skan /* 'long' might be 32 or 64 bits, and the number of leading zeroes 76132718Skan must be tweaked accordingly. */ 77132718Skan# if HOST_BITS_PER_WIDE_INT == 64 78132718Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%016lx" 7952284Sobrien# else 80132718Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%08lx" 8152284Sobrien# endif 82132718Skan#else 83169689Skan# define HOST_WIDE_INT_PRINT HOST_LONG_LONG_FORMAT 84132718Skan# define HOST_WIDE_INT_PRINT_C "LL" 85132718Skan /* We can assume that 'long long' is at least 64 bits. */ 86169689Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX \ 87169689Skan "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x" 88132718Skan#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */ 8952284Sobrien 90132718Skan#define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d" 91132718Skan#define HOST_WIDE_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC HOST_WIDE_INT_PRINT_C 92132718Skan#define HOST_WIDE_INT_PRINT_UNSIGNED "%" HOST_WIDE_INT_PRINT "u" 93132718Skan#define HOST_WIDE_INT_PRINT_HEX "0x%" HOST_WIDE_INT_PRINT "x" 9452284Sobrien 95132718Skan/* Set HOST_WIDEST_INT. This is a 64-bit type unless the compiler 96132718Skan in use has no 64-bit type at all; in that case it's 32 bits. */ 9752284Sobrien 98132718Skan#if HOST_BITS_PER_WIDE_INT >= 64 \ 99132718Skan || (HOST_BITS_PER_LONGLONG < 64 && HOST_BITS_PER___INT64 < 64) 100132718Skan# define HOST_WIDEST_INT HOST_WIDE_INT 101132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_WIDE_INT 102132718Skan# define HOST_WIDEST_INT_PRINT_DEC HOST_WIDE_INT_PRINT_DEC 103132718Skan# define HOST_WIDEST_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC_C 104132718Skan# define HOST_WIDEST_INT_PRINT_UNSIGNED HOST_WIDE_INT_PRINT_UNSIGNED 105132718Skan# define HOST_WIDEST_INT_PRINT_HEX HOST_WIDE_INT_PRINT_HEX 106132718Skan# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX HOST_WIDE_INT_PRINT_DOUBLE_HEX 107132718Skan#else 108132718Skan# if HOST_BITS_PER_LONGLONG >= 64 109132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG 110132718Skan# define HOST_WIDEST_INT long long 11152284Sobrien# else 112132718Skan# if HOST_BITS_PER___INT64 >= 64 113132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER___INT64 114132718Skan# define HOST_WIDEST_INT __int64 11552284Sobrien# else 116132718Skan #error "This line should be impossible to reach" 11752284Sobrien# endif 11852284Sobrien# endif 119169689Skan# define HOST_WIDEST_INT_PRINT_DEC "%" HOST_LONG_LONG_FORMAT "d" 120169689Skan# define HOST_WIDEST_INT_PRINT_DEC_C "%" HOST_LONG_LONG_FORMAT "dLL" 121169689Skan# define HOST_WIDEST_INT_PRINT_UNSIGNED "%" HOST_LONG_LONG_FORMAT "u" 122169689Skan# define HOST_WIDEST_INT_PRINT_HEX "0x%" HOST_LONG_LONG_FORMAT "x" 123169689Skan# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX \ 124169689Skan "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x" 125132718Skan#endif 12652284Sobrien 127169689Skan/* Define HOST_WIDEST_FAST_INT to the widest integer type supported 128169689Skan efficiently in hardware. (That is, the widest integer type that fits 129169689Skan in a hardware register.) Normally this is "long" but on some hosts it 130169689Skan should be "long long" or "__int64". This is no convenient way to 131169689Skan autodect this, so such systems must set a flag in config.host; see there 132169689Skan for details. */ 133169689Skan 134169689Skan#ifdef USE_LONG_LONG_FOR_WIDEST_FAST_INT 135169689Skan# ifdef HAVE_LONG_LONG 136169689Skan# define HOST_WIDEST_FAST_INT long long 137169689Skan# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONGLONG 138169689Skan# elif defined (HAVE___INT64) 139169689Skan# define HOST_WIDEST_FAST_INT __int64 140169689Skan# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER___INT64 141169689Skan# else 142169689Skan# error "Your host said it wantted to use long long or __int64 but neither" 143169689Skan# error "exist" 144169689Skan# endif 145169689Skan#else 146169689Skan# define HOST_WIDEST_FAST_INT long 147169689Skan# define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER_LONG 148169689Skan#endif 149169689Skan 15090075Sobrien#endif /* ! GCC_HWINT_H */ 151