TRYHELP_GOODBYE macro added.
[skeinsum.git] / brg_types.h
1 /*\r
2  ---------------------------------------------------------------------------\r
3  Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.\r
4 \r
5  LICENSE TERMS\r
6 \r
7  The free distribution and use of this software in both source and binary\r
8  form is allowed (with or without changes) provided that:\r
9 \r
10    1. distributions of this source code include the above copyright\r
11       notice, this list of conditions and the following disclaimer;\r
12 \r
13    2. distributions in binary form include the above copyright\r
14       notice, this list of conditions and the following disclaimer\r
15       in the documentation and/or other associated materials;\r
16 \r
17    3. the copyright holder's name is not used to endorse products\r
18       built using this software without specific written permission.\r
19 \r
20  ALTERNATIVELY, provided that this notice is retained in full, this product\r
21  may be distributed under the terms of the GNU General Public License (GPL),\r
22  in which case the provisions of the GPL apply INSTEAD OF those given above.\r
23 \r
24  DISCLAIMER\r
25 \r
26  This software is provided 'as is' with no explicit or implied warranties\r
27  in respect of its properties, including, but not limited to, correctness\r
28  and/or fitness for purpose.\r
29  ---------------------------------------------------------------------------\r
30  Issue 09/09/2006\r
31 \r
32  The unsigned integer types defined here are of the form uint_<nn>t where\r
33  <nn> is the length of the type; for example, the unsigned 32-bit type is\r
34  'uint_32t'.  These are NOT the same as the 'C99 integer types' that are\r
35  defined in the inttypes.h and stdint.h headers since attempts to use these\r
36  types have shown that support for them is still highly variable.  However,\r
37  since the latter are of the form uint<nn>_t, a regular expression search\r
38  and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t')\r
39  can be used to convert the types used here to the C99 standard types.\r
40 */\r
41 \r
42 #ifndef BRG_TYPES_H\r
43 #define BRG_TYPES_H\r
44 \r
45 #if defined(__cplusplus)\r
46 extern "C" {\r
47 #endif\r
48 \r
49 #include <limits.h>\r
50 \r
51 #ifndef BRG_UI8\r
52 #  define BRG_UI8\r
53 #  if UCHAR_MAX == 255u\r
54      typedef unsigned char uint_8t;\r
55 #  else\r
56 #    error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h\r
57 #  endif\r
58 #endif\r
59 \r
60 #ifndef BRG_UI16\r
61 #  define BRG_UI16\r
62 #  if USHRT_MAX == 65535u\r
63      typedef unsigned short uint_16t;\r
64 #  else\r
65 #    error Please define uint_16t as a 16-bit unsigned short type in brg_types.h\r
66 #  endif\r
67 #endif\r
68 \r
69 #ifndef BRG_UI32\r
70 #  define BRG_UI32\r
71 #  if UINT_MAX == 4294967295u\r
72 #    define li_32(h) 0x##h##u\r
73      typedef unsigned int uint_32t;\r
74 #  elif ULONG_MAX == 4294967295u\r
75 #    define li_32(h) 0x##h##ul\r
76      typedef unsigned long uint_32t;\r
77 #  elif defined( _CRAY )\r
78 #    error This code needs 32-bit data types, which Cray machines do not provide\r
79 #  else\r
80 #    error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h\r
81 #  endif\r
82 #endif\r
83 \r
84 #ifndef BRG_UI64\r
85 #  if defined( __BORLANDC__ ) && !defined( __MSDOS__ )\r
86 #    define BRG_UI64\r
87 #    define li_64(h) 0x##h##ui64\r
88      typedef unsigned __int64 uint_64t;\r
89 #  elif defined( _MSC_VER ) && ( _MSC_VER < 1300 )    /* 1300 == VC++ 7.0 */\r
90 #    define BRG_UI64\r
91 #    define li_64(h) 0x##h##ui64\r
92      typedef unsigned __int64 uint_64t;\r
93 #  elif defined( __sun ) && defined(ULONG_MAX) && ULONG_MAX == 0xfffffffful\r
94 #    define BRG_UI64\r
95 #    define li_64(h) 0x##h##ull\r
96      typedef unsigned long long uint_64t;\r
97 #  elif defined( UINT_MAX ) && UINT_MAX > 4294967295u\r
98 #    if UINT_MAX == 18446744073709551615u\r
99 #      define BRG_UI64\r
100 #      define li_64(h) 0x##h##u\r
101        typedef unsigned int uint_64t;\r
102 #    endif\r
103 #  elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u\r
104 #    if ULONG_MAX == 18446744073709551615ul\r
105 #      define BRG_UI64\r
106 #      define li_64(h) 0x##h##ul\r
107        typedef unsigned long uint_64t;\r
108 #    endif\r
109 #  elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u\r
110 #    if ULLONG_MAX == 18446744073709551615ull\r
111 #      define BRG_UI64\r
112 #      define li_64(h) 0x##h##ull\r
113        typedef unsigned long long uint_64t;\r
114 #    endif\r
115 #  elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u\r
116 #    if ULONG_LONG_MAX == 18446744073709551615ull\r
117 #      define BRG_UI64\r
118 #      define li_64(h) 0x##h##ull\r
119        typedef unsigned long long uint_64t;\r
120 #    endif\r
121 #  elif defined(__GNUC__)  /* DLW: avoid mingw problem with -ansi */\r
122 #      define BRG_UI64\r
123 #      define li_64(h) 0x##h##ull\r
124        typedef unsigned long long uint_64t;\r
125 #  endif\r
126 #endif\r
127 \r
128 #if defined( NEED_UINT_64T ) && !defined( BRG_UI64 )\r
129 #  error Please define uint_64t as an unsigned 64 bit type in brg_types.h\r
130 #endif\r
131 \r
132 #ifndef RETURN_VALUES\r
133 #  define RETURN_VALUES\r
134 #  if defined( DLL_EXPORT )\r
135 #    if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
136 #      define VOID_RETURN    __declspec( dllexport ) void __stdcall\r
137 #      define INT_RETURN     __declspec( dllexport ) int  __stdcall\r
138 #    elif defined( __GNUC__ )\r
139 #      define VOID_RETURN    __declspec( __dllexport__ ) void\r
140 #      define INT_RETURN     __declspec( __dllexport__ ) int\r
141 #    else\r
142 #      error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
143 #    endif\r
144 #  elif defined( DLL_IMPORT )\r
145 #    if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )\r
146 #      define VOID_RETURN    __declspec( dllimport ) void __stdcall\r
147 #      define INT_RETURN     __declspec( dllimport ) int  __stdcall\r
148 #    elif defined( __GNUC__ )\r
149 #      define VOID_RETURN    __declspec( __dllimport__ ) void\r
150 #      define INT_RETURN     __declspec( __dllimport__ ) int\r
151 #    else\r
152 #      error Use of the DLL is only available on the Microsoft, Intel and GCC compilers\r
153 #    endif\r
154 #  elif defined( __WATCOMC__ )\r
155 #    define VOID_RETURN  void __cdecl\r
156 #    define INT_RETURN   int  __cdecl\r
157 #  else\r
158 #    define VOID_RETURN  void\r
159 #    define INT_RETURN   int\r
160 #  endif\r
161 #endif\r
162 \r
163 /*  These defines are used to declare buffers in a way that allows\r
164     faster operations on longer variables to be used.  In all these\r
165     defines 'size' must be a power of 2 and >= 8\r
166 \r
167     dec_unit_type(size,x)       declares a variable 'x' of length \r
168                                 'size' bits\r
169 \r
170     dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize' \r
171                                 bytes defined as an array of variables\r
172                                 each of 'size' bits (bsize must be a \r
173                                 multiple of size / 8)\r
174 \r
175     ptr_cast(x,size)            casts a pointer to a pointer to a \r
176                                 varaiable of length 'size' bits\r
177 */\r
178 \r
179 #define ui_type(size)               uint_##size##t\r
180 #define dec_unit_type(size,x)       typedef ui_type(size) x\r
181 #define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)]\r
182 #define ptr_cast(x,size)            ((ui_type(size)*)(x))\r
183 \r
184 #if defined(__cplusplus)\r
185 }\r
186 #endif\r
187 \r
188 #endif\r