| 1 | // This provides C99-like standard integer types.  It is based on boost.org | 
|---|
| 2 | // code which has been modified for inclusion in the SC Toolkit. | 
|---|
| 3 |  | 
|---|
| 4 | //  (C) Copyright boost.org 1999. Permission to copy, use, modify, sell | 
|---|
| 5 | //  and distribute this software is granted provided this copyright | 
|---|
| 6 | //  notice appears in all copies. This software is provided "as is" without | 
|---|
| 7 | //  express or implied warranty, and with no claim as to its suitability for | 
|---|
| 8 | //  any purpose. | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef util_misc_scint_h | 
|---|
| 11 | #define util_misc_scint_h | 
|---|
| 12 |  | 
|---|
| 13 | #include <scconfig.h> | 
|---|
| 14 |  | 
|---|
| 15 | #ifdef HAVE_STDINT_H | 
|---|
| 16 |  | 
|---|
| 17 | #include <stdint.h> | 
|---|
| 18 |  | 
|---|
| 19 | namespace sc { | 
|---|
| 20 |  | 
|---|
| 21 | typedef int8_t         sc_int8_t; | 
|---|
| 22 | typedef int_least8_t   sc_int_least8_t; | 
|---|
| 23 | typedef int_fast8_t    sc_int_fast8_t; | 
|---|
| 24 | typedef uint8_t        sc_uint8_t; | 
|---|
| 25 | typedef uint_least8_t  sc_uint_least8_t; | 
|---|
| 26 | typedef uint_fast8_t   sc_uint_fast8_t; | 
|---|
| 27 |  | 
|---|
| 28 | typedef int16_t        sc_int16_t; | 
|---|
| 29 | typedef int_least16_t  sc_int_least16_t; | 
|---|
| 30 | typedef int_fast16_t   sc_int_fast16_t; | 
|---|
| 31 | typedef uint16_t       sc_uint16_t; | 
|---|
| 32 | typedef uint_least16_t sc_uint_least16_t; | 
|---|
| 33 | typedef uint_fast16_t  sc_uint_fast16_t; | 
|---|
| 34 |  | 
|---|
| 35 | typedef int32_t        sc_int32_t; | 
|---|
| 36 | typedef int_least32_t  sc_int_least32_t; | 
|---|
| 37 | typedef int_fast32_t   sc_int_fast32_t; | 
|---|
| 38 | typedef uint32_t       sc_uint32_t; | 
|---|
| 39 | typedef uint_least32_t sc_uint_least32_t; | 
|---|
| 40 | typedef uint_fast32_t  sc_uint_fast32_t; | 
|---|
| 41 |  | 
|---|
| 42 | typedef intmax_t       sc_intmax_t; | 
|---|
| 43 | typedef uintmax_t      sc_uintmax_t; | 
|---|
| 44 | typedef int64_t        sc_int64_t; | 
|---|
| 45 | typedef int_least64_t  sc_int_least64_t; | 
|---|
| 46 | typedef int_fast64_t   sc_int_fast64_t; | 
|---|
| 47 | typedef uint64_t       sc_uint64_t; | 
|---|
| 48 | typedef uint_least64_t sc_uint_least64_t; | 
|---|
| 49 | typedef uint_fast64_t  sc_uint_fast64_t; | 
|---|
| 50 |  | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | #else | 
|---|
| 54 |  | 
|---|
| 55 | //  This is not a complete implementation of the 1999 C Standard stdint.h | 
|---|
| 56 | //  header; it doesn't supply various macros which are not advisable for use in | 
|---|
| 57 | //  C++ programs. | 
|---|
| 58 |  | 
|---|
| 59 | #include <limits.h> // implementation artifact; not part of interface | 
|---|
| 60 |  | 
|---|
| 61 | namespace sc { | 
|---|
| 62 |  | 
|---|
| 63 | //  These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit | 
|---|
| 64 | //  platforms.  For other systems, they will have to be hand tailored. | 
|---|
| 65 | //  Because the fast types are assumed to be the same as the undecorated types, | 
|---|
| 66 | //  it may be possible to hand tailor a more efficient implementation. | 
|---|
| 67 |  | 
|---|
| 68 | //  8-bit types  -------------------------------------------------------------// | 
|---|
| 69 |  | 
|---|
| 70 | # if UCHAR_MAX == 0xff | 
|---|
| 71 | typedef signed char     sc_int8_t; | 
|---|
| 72 | typedef signed char     sc_int_least8_t; | 
|---|
| 73 | typedef signed char     sc_int_fast8_t; | 
|---|
| 74 | typedef unsigned char   sc_uint8_t; | 
|---|
| 75 | typedef unsigned char   sc_uint_least8_t; | 
|---|
| 76 | typedef unsigned char   sc_uint_fast8_t; | 
|---|
| 77 | # else | 
|---|
| 78 | #    error defaults not correct; you must hand modify scint.h | 
|---|
| 79 | # endif | 
|---|
| 80 |  | 
|---|
| 81 | //  16-bit types  ------------------------------------------------------------// | 
|---|
| 82 |  | 
|---|
| 83 | # if USHRT_MAX == 0xffff | 
|---|
| 84 | typedef short           sc_int16_t; | 
|---|
| 85 | typedef short           sc_int_least16_t; | 
|---|
| 86 | typedef short           sc_int_fast16_t; | 
|---|
| 87 | typedef unsigned short  sc_uint16_t; | 
|---|
| 88 | typedef unsigned short  sc_uint_least16_t; | 
|---|
| 89 | typedef unsigned short  sc_uint_fast16_t; | 
|---|
| 90 | # else | 
|---|
| 91 | #    error defaults not correct; you must hand modify scint.h | 
|---|
| 92 | # endif | 
|---|
| 93 |  | 
|---|
| 94 | //  32-bit types  ------------------------------------------------------------// | 
|---|
| 95 |  | 
|---|
| 96 | # if UINT_MAX == 0xffffffff | 
|---|
| 97 | typedef int             sc_int32_t; | 
|---|
| 98 | typedef int             sc_int_least32_t; | 
|---|
| 99 | typedef int             sc_int_fast32_t; | 
|---|
| 100 | typedef unsigned int    sc_uint32_t; | 
|---|
| 101 | typedef unsigned int    sc_uint_least32_t; | 
|---|
| 102 | typedef unsigned int    sc_uint_fast32_t; | 
|---|
| 103 | # elif ULONG_MAX == 0xffffffff | 
|---|
| 104 | typedef long            sc_int32_t; | 
|---|
| 105 | typedef long            sc_int_least32_t; | 
|---|
| 106 | typedef long            sc_int_fast32_t; | 
|---|
| 107 | typedef unsigned long   sc_uint32_t; | 
|---|
| 108 | typedef unsigned long   sc_uint_least32_t; | 
|---|
| 109 | typedef unsigned long   sc_uint_fast32_t; | 
|---|
| 110 | # else | 
|---|
| 111 | #    error defaults not correct; you must hand modify scint.h | 
|---|
| 112 | # endif | 
|---|
| 113 |  | 
|---|
| 114 | //  64-bit types + intmax_t and uintmax_t  -----------------------------------// | 
|---|
| 115 |  | 
|---|
| 116 | #if defined(ULONGLONG_MAX) && !defined(ULLONG_MAX) | 
|---|
| 117 | #    define ULLONG_MAX ULONGLONG_MAX | 
|---|
| 118 | #endif | 
|---|
| 119 |  | 
|---|
| 120 | # ifdef ULLONG_MAX | 
|---|
| 121 | //#    if ULLONG_MAX == 18446744073709551615 // 2**64 - 1 | 
|---|
| 122 | #    if ULONGLONG_MAX == (0xffffffffffffffffuLL) // uLL reqd for xlC | 
|---|
| 123 | typedef long long            sc_intmax_t; | 
|---|
| 124 | typedef unsigned long long   sc_uintmax_t; | 
|---|
| 125 | typedef long long            sc_int64_t; | 
|---|
| 126 | typedef long long            sc_int_least64_t; | 
|---|
| 127 | typedef long long            sc_int_fast64_t; | 
|---|
| 128 | typedef unsigned long long   sc_uint64_t; | 
|---|
| 129 | typedef unsigned long long   sc_uint_least64_t; | 
|---|
| 130 | typedef unsigned long long   sc_uint_fast64_t; | 
|---|
| 131 | #    else | 
|---|
| 132 | #       error defaults not correct; you must hand modify scint.h | 
|---|
| 133 | #    endif | 
|---|
| 134 | # elif ULONG_MAX != 0xffffffff | 
|---|
| 135 |  | 
|---|
| 136 | #    if ULONG_MAX == 18446744073709551615 // 2**64 - 1 | 
|---|
| 137 | typedef long                 sc_intmax_t; | 
|---|
| 138 | typedef unsigned long        sc_uintmax_t; | 
|---|
| 139 | typedef long                 sc_int64_t; | 
|---|
| 140 | typedef long                 sc_int_least64_t; | 
|---|
| 141 | typedef long                 sc_int_fast64_t; | 
|---|
| 142 | typedef unsigned long        sc_uint64_t; | 
|---|
| 143 | typedef unsigned long        sc_uint_least64_t; | 
|---|
| 144 | typedef unsigned long        sc_uint_fast64_t; | 
|---|
| 145 | #    else | 
|---|
| 146 | #       error defaults not correct; you must hand modify scint.h | 
|---|
| 147 | #    endif | 
|---|
| 148 | # else // assume no 64-bit integers | 
|---|
| 149 | #    error 64 bit integer types are required | 
|---|
| 150 | typedef sc_int32_t              sc_intmax_t; | 
|---|
| 151 | typedef sc_uint32_t             sc_uintmax_t; | 
|---|
| 152 | # endif | 
|---|
| 153 |  | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | #endif | 
|---|
| 157 |  | 
|---|
| 158 | #endif | 
|---|