hwint.h revision 132718
152284Sobrien/* HOST_WIDE_INT definitions for the GNU compiler. 2117395Skan Copyright (C) 1998, 2002 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 18132718Skan/* If HAVE_LONG_LONG and SIZEOF_LONG_LONG aren't defined, but 19132718Skan GCC_VERSION >= 3000, assume this is the second or later stage of a 20132718Skan bootstrap, we do have long long, and it's 64 bits. (This is 21132718Skan required by C99; we do have some ports that violate that assumption 22132718Skan but they're all cross-compile-only.) Just in case, force a 23132718Skan constraint violation if that assumption is incorrect. */ 24132718Skan#if !defined HAVE_LONG_LONG 25132718Skan# if GCC_VERSION >= 3000 26132718Skan# define HAVE_LONG_LONG 1 27132718Skan# define SIZEOF_LONG_LONG 8 28132718Skanextern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; 29132718Skan# endif 30132718Skan#endif 31132718Skan 3290075Sobrien#ifdef HAVE_LONG_LONG 3390075Sobrien# define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG) 34132718Skan#endif 3596263Sobrien#ifdef HAVE___INT64 36132718Skan# define HOST_BITS_PER___INT64 (CHAR_BIT * SIZEOF___INT64) 3790075Sobrien#endif 3890075Sobrien 39132718Skan/* Set HOST_WIDE_INT. This should be the widest efficient host 40132718Skan integer type. It can be 32 or 64 bits, except that if we are 41132718Skan targeting a machine with 64-bit size_t then it has to be 64 bits. 4252284Sobrien 43132718Skan With a sane ABI, 'long' is the largest efficient host integer type. 44132718Skan Thus, we use that unless we have to use 'long long' or '__int64' 45132718Skan because we're targeting a 64-bit machine from a 32-bit host. */ 4690075Sobrien 47132718Skan#if HOST_BITS_PER_LONG >= 64 || !defined NEED_64BIT_HOST_WIDE_INT 48132718Skan# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG 49132718Skan# define HOST_WIDE_INT long 50132718Skan#else 51132718Skan# if HOST_BITS_PER_LONGLONG >= 64 5290075Sobrien# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONGLONG 5390075Sobrien# define HOST_WIDE_INT long long 5490075Sobrien# else 55132718Skan# if HOST_BITS_PER___INT64 >= 64 56132718Skan# define HOST_BITS_PER_WIDE_INT HOST_BITS_PER___INT64 57132718Skan# define HOST_WIDE_INT __int64 58132718Skan# else 59132718Skan #error "Unable to find a suitable type for HOST_WIDE_INT" 6090075Sobrien# endif 6190075Sobrien# endif 6290075Sobrien#endif 6390075Sobrien 64132718Skan/* Various printf format strings for HOST_WIDE_INT. */ 6552284Sobrien 66132718Skan#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG 67132718Skan# define HOST_WIDE_INT_PRINT "l" 68132718Skan# define HOST_WIDE_INT_PRINT_C "L" 69132718Skan /* 'long' might be 32 or 64 bits, and the number of leading zeroes 70132718Skan must be tweaked accordingly. */ 71132718Skan# if HOST_BITS_PER_WIDE_INT == 64 72132718Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%016lx" 7352284Sobrien# else 74132718Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%lx%08lx" 7552284Sobrien# endif 76132718Skan#else 77132718Skan# define HOST_WIDE_INT_PRINT "ll" 78132718Skan# define HOST_WIDE_INT_PRINT_C "LL" 79132718Skan /* We can assume that 'long long' is at least 64 bits. */ 80132718Skan# define HOST_WIDE_INT_PRINT_DOUBLE_HEX "0x%llx%016llx" 81132718Skan#endif /* HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG */ 8252284Sobrien 83132718Skan#define HOST_WIDE_INT_PRINT_DEC "%" HOST_WIDE_INT_PRINT "d" 84132718Skan#define HOST_WIDE_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC HOST_WIDE_INT_PRINT_C 85132718Skan#define HOST_WIDE_INT_PRINT_UNSIGNED "%" HOST_WIDE_INT_PRINT "u" 86132718Skan#define HOST_WIDE_INT_PRINT_HEX "0x%" HOST_WIDE_INT_PRINT "x" 8752284Sobrien 88132718Skan/* Set HOST_WIDEST_INT. This is a 64-bit type unless the compiler 89132718Skan in use has no 64-bit type at all; in that case it's 32 bits. */ 9052284Sobrien 91132718Skan#if HOST_BITS_PER_WIDE_INT >= 64 \ 92132718Skan || (HOST_BITS_PER_LONGLONG < 64 && HOST_BITS_PER___INT64 < 64) 93132718Skan# define HOST_WIDEST_INT HOST_WIDE_INT 94132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_WIDE_INT 95132718Skan# define HOST_WIDEST_INT_PRINT_DEC HOST_WIDE_INT_PRINT_DEC 96132718Skan# define HOST_WIDEST_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC_C 97132718Skan# define HOST_WIDEST_INT_PRINT_UNSIGNED HOST_WIDE_INT_PRINT_UNSIGNED 98132718Skan# define HOST_WIDEST_INT_PRINT_HEX HOST_WIDE_INT_PRINT_HEX 99132718Skan# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX HOST_WIDE_INT_PRINT_DOUBLE_HEX 100132718Skan#else 101132718Skan# if HOST_BITS_PER_LONGLONG >= 64 102132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG 103132718Skan# define HOST_WIDEST_INT long long 10452284Sobrien# else 105132718Skan# if HOST_BITS_PER___INT64 >= 64 106132718Skan# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER___INT64 107132718Skan# define HOST_WIDEST_INT __int64 10852284Sobrien# else 109132718Skan #error "This line should be impossible to reach" 11052284Sobrien# endif 11152284Sobrien# endif 112132718Skan# define HOST_WIDEST_INT_PRINT_DEC "%lld" 113132718Skan# define HOST_WIDEST_INT_PRINT_DEC_C "%lldLL" 114132718Skan# define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu" 115132718Skan# define HOST_WIDEST_INT_PRINT_HEX "0x%llx" 116132718Skan# define HOST_WIDEST_INT_PRINT_DOUBLE_HEX "0x%llx%016llx" 117132718Skan#endif 11852284Sobrien 11990075Sobrien#endif /* ! GCC_HWINT_H */ 120