Merge branch 'master' into sim-target-tree
[kugel-rb.git] / tools / ucl / src / ucl_ptr.h
blob86221b9ac145d83641941c6f060a1eef23b21fdc
1 /* ucl_ptr.h -- low-level pointer constructs
3 This file is part of the UCL data compression library.
5 Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The UCL library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The UCL library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the UCL library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
28 /* WARNING: this file should *not* be used by applications. It is
29 part of the implementation of the library and is subject
30 to change.
34 #ifndef __UCL_PTR_H
35 #define __UCL_PTR_H
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
42 /* This is the lowest part of the UCL library.
43 * It deals with pointer representations at bit level.
47 /***********************************************************************
48 // Includes
49 ************************************************************************/
51 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
52 # include <dos.h>
53 # if 1 && defined(__WATCOMC__)
54 # include <i86.h>
55 __UCL_EXTERN_C unsigned char _HShift;
56 # define __UCL_HShift _HShift
57 # elif 1 && defined(_MSC_VER)
58 __UCL_EXTERN_C unsigned short __near _AHSHIFT;
59 # define __UCL_HShift ((unsigned) &_AHSHIFT)
60 # elif defined(__UCL_WIN16)
61 # define __UCL_HShift 3
62 # else
63 # define __UCL_HShift 12
64 # endif
65 # if !defined(_FP_SEG) && defined(FP_SEG)
66 # define _FP_SEG FP_SEG
67 # endif
68 # if !defined(_FP_OFF) && defined(FP_OFF)
69 # define _FP_OFF FP_OFF
70 # endif
71 #endif
74 /***********************************************************************
75 // Integral types
76 ************************************************************************/
78 /* ptrdiff_t */
79 #if !defined(ucl_ptrdiff_t)
80 #if (UINT_MAX >= UCL_0xffffffffL)
81 typedef ptrdiff_t ucl_ptrdiff_t;
82 #else
83 typedef long ucl_ptrdiff_t;
84 #endif
85 #endif
88 /* Unsigned type that has *exactly* the same number of bits as a ucl_voidp */
89 #if !defined(__UCL_HAVE_PTR_T)
90 # if defined(ucl_ptr_t)
91 # define __UCL_HAVE_PTR_T
92 # endif
93 #endif
94 #if !defined(__UCL_HAVE_PTR_T)
95 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_LONG)
96 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG)
97 typedef unsigned long ucl_ptr_t;
98 typedef long ucl_sptr_t;
99 # define __UCL_HAVE_PTR_T
100 # endif
101 # endif
102 #endif
103 #if !defined(__UCL_HAVE_PTR_T)
104 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED)
105 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED)
106 typedef unsigned int ucl_ptr_t;
107 typedef int ucl_sptr_t;
108 # define __UCL_HAVE_PTR_T
109 # endif
110 # endif
111 #endif
112 #if !defined(__UCL_HAVE_PTR_T)
113 # if defined(SIZEOF_CHAR_P) && defined(SIZEOF_UNSIGNED_SHORT)
114 # if (SIZEOF_CHAR_P == SIZEOF_UNSIGNED_SHORT)
115 typedef unsigned short ucl_ptr_t;
116 typedef short ucl_sptr_t;
117 # define __UCL_HAVE_PTR_T
118 # endif
119 # endif
120 #endif
121 #if !defined(__UCL_HAVE_PTR_T)
122 # if defined(UCL_HAVE_CONFIG_H) || defined(SIZEOF_CHAR_P)
123 # error "no suitable type for ucl_ptr_t"
124 # else
125 typedef unsigned long ucl_ptr_t;
126 typedef long ucl_sptr_t;
127 # define __UCL_HAVE_PTR_T
128 # endif
129 #endif
132 /***********************************************************************
134 ************************************************************************/
136 /* Always use the safe (=integral) version for pointer-comparisions.
137 * The compiler should optimize away the additional casts anyway.
139 * Note that this only works if the representation and ordering
140 * of the pointer and the integral is the same (at bit level).
142 * Most 16-bit compilers have their own view about pointers -
143 * fortunately they don't care about comparing pointers
144 * that are pointing to Nirvana.
147 #if defined(__UCL_DOS16) || defined(__UCL_WIN16)
148 #define PTR(a) ((ucl_bytep) (a))
149 /* only need the low bits of the pointer -> offset is ok */
150 #define PTR_ALIGNED_4(a) ((_FP_OFF(a) & 3) == 0)
151 #define PTR_ALIGNED2_4(a,b) (((_FP_OFF(a) | _FP_OFF(b)) & 3) == 0)
152 #else
153 #define PTR(a) ((ucl_ptr_t) (a))
154 #define PTR_LINEAR(a) PTR(a)
155 #define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0)
156 #define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0)
157 #define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0)
158 #define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0)
159 #endif
161 #define PTR_LT(a,b) (PTR(a) < PTR(b))
162 #define PTR_GE(a,b) (PTR(a) >= PTR(b))
163 #define PTR_DIFF(a,b) ((ucl_ptrdiff_t) (PTR(a) - PTR(b)))
166 UCL_EXTERN(ucl_ptr_t)
167 __ucl_ptr_linear(const ucl_voidp ptr);
170 typedef union
172 char a_char;
173 unsigned char a_uchar;
174 short a_short;
175 unsigned short a_ushort;
176 int a_int;
177 unsigned int a_uint;
178 long a_long;
179 unsigned long a_ulong;
180 ucl_int a_ucl_int;
181 ucl_uint a_ucl_uint;
182 ucl_int32 a_ucl_int32;
183 ucl_uint32 a_ucl_uint32;
184 ptrdiff_t a_ptrdiff_t;
185 ucl_ptrdiff_t a_ucl_ptrdiff_t;
186 ucl_ptr_t a_ucl_ptr_t;
187 ucl_voidp a_ucl_voidp;
188 void * a_void_p;
189 ucl_bytep a_ucl_bytep;
190 ucl_bytepp a_ucl_bytepp;
191 ucl_uintp a_ucl_uintp;
192 ucl_uint * a_ucl_uint_p;
193 ucl_uint32p a_ucl_uint32p;
194 ucl_uint32 * a_ucl_uint32_p;
195 unsigned char * a_uchar_p;
196 char * a_char_p;
198 ucl_align_t;
202 #ifdef __cplusplus
203 } /* extern "C" */
204 #endif
206 #endif /* already included */
209 vi:ts=4:et