A Discrete-Event Network Simulator
API
cairo-wideint-private.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /* cairo - a vector graphics library with display and print output
3  *
4  * Copyright © 2004 Keith Packard
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * The original code as contributed to the cairo library under
20  * the dual license MPL+LGPL. We used the LGPL relicensing clause to
21  * get a GPL version of this code which now lives here. This header is
22  * unmodified other than the licensing clause.
23  *
24  * The Original Code is the cairo graphics library.
25  *
26  * The Initial Developer of the Original Code is Keith Packard
27  *
28  * Contributor(s):
29  * Keith R. Packard <keithp@keithp.com>
30  *
31  */
32 
33 #ifndef CAIRO_WIDEINT_H
34 #define CAIRO_WIDEINT_H
35 
43 // Adapt to ns-3 environment
44 #include "ns3/core-config.h"
45 #define cairo_private
46 #define HAVE_UINT64_T 1
47 // Implementation tags added below and in cairo-wideint.c:
48 // extern const char * cairo_impl64;
49 // extern const char * cairo_impl128;
50 
51 
52 /*for compatibility with MacOS and Cygwin*/
53 #ifndef HAVE_STDINT_H
54 #ifdef __APPLE__
55 #define HAVE_STDINT_H 1
56 #elif defined(WIN32)
57 #define HAVE_STDINT_H 1
58 #endif
59 #endif
60 
61 #if HAVE_STDINT_H
62 # include <stdint.h>
63 #elif HAVE_INTTYPES_H
64 # include <inttypes.h>
65 #elif HAVE_SYS_INT_TYPES_H
66 # include <sys/int_types.h>
67 #elif defined(_MSC_VER)
68 typedef __int8 int8_t;
69 typedef unsigned __int8 uint8_t;
70 typedef __int16 int16_t;
71 typedef unsigned __int16 uint16_t;
72 typedef __int32 int32_t;
73 typedef unsigned __int32 uint32_t;
74 typedef __int64 int64_t;
75 typedef unsigned __int64 uint64_t;
76 # ifndef HAVE_UINT64_T
77 # define HAVE_UINT64_T 1
78 # endif
79 # ifndef INT16_MIN
80 # define INT16_MIN (-32767-1)
81 # endif
82 # ifndef INT16_MAX
83 # define INT16_MAX (32767)
84 # endif
85 # ifndef UINT16_MAX
86 # define UINT16_MAX (65535)
87 # endif
88 #else
89 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
90 #endif
91 
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95 
96 /*
97  * 64-bit datatypes. Two separate implementations, one using
98  * built-in 64-bit signed/unsigned types another implemented
99  * as a pair of 32-bit ints
100  */
101 
102 #define I cairo_private
103 
104 #if !HAVE_UINT64_T
105 
106 extern const char * cairo_impl64;
107 
108 typedef struct _cairo_uint64 {
109  uint32_t lo, hi;
111 
113 #define _cairo_uint64_to_uint32(a) ((a).lo)
117 cairo_uint64_t I _cairo_uint32x32_64_mul (uint32_t a, uint32_t b);
124 #define _cairo_uint64_negative(a) (((int32_t)((a).hi)) < 0)
126 
127 #define _cairo_uint64_to_int64(i) (i)
128 #define _cairo_int64_to_uint64(i) (i)
129 
131 #define _cairo_int64_to_int32(a) ((int32_t) _cairo_uint64_to_uint32 (a))
132 #define _cairo_int64_add(a,b) _cairo_uint64_add (a,b)
133 #define _cairo_int64_sub(a,b) _cairo_uint64_sub (a,b)
134 #define _cairo_int64_mul(a,b) _cairo_uint64_mul (a,b)
135 cairo_int64_t I _cairo_int32x32_64_mul (int32_t a, int32_t b);
137 #define _cairo_int64_eq(a,b) _cairo_uint64_eq (a,b)
138 #define _cairo_int64_lsl(a,b) _cairo_uint64_lsl (a,b)
139 #define _cairo_int64_rsl(a,b) _cairo_uint64_rsl (a,b)
140 #define _cairo_int64_rsa(a,b) _cairo_uint64_rsa (a,b)
141 #define _cairo_int64_negate(a) _cairo_uint64_negate (a)
142 #define _cairo_int64_negative(a) (((int32_t)((a).hi)) < 0)
143 #define _cairo_int64_not(a) _cairo_uint64_not (a)
144 
145 #else
146 
147 extern const char * cairo_impl64;
148 
149 typedef uint64_t cairo_uint64_t;
150 typedef int64_t cairo_int64_t;
151 
152 #define _cairo_uint32_to_uint64(i) ((uint64_t)(i))
153 #define _cairo_uint64_to_uint32(i) ((uint32_t)(i))
154 #define _cairo_uint64_add(a,b) ((a) + (b))
155 #define _cairo_uint64_sub(a,b) ((a) - (b))
156 #define _cairo_uint64_mul(a,b) ((a) * (b))
157 #define _cairo_uint32x32_64_mul(a,b) ((uint64_t)(a) * (b))
158 #define _cairo_uint64_lsl(a,b) ((a) << (b))
159 #define _cairo_uint64_rsl(a,b) ((uint64_t)(a) >> (b))
160 #define _cairo_uint64_rsa(a,b) ((uint64_t)((int64_t)(a) >> (b)))
161 #define _cairo_uint64_lt(a,b) ((a) < (b))
162 #define _cairo_uint64_eq(a,b) ((a) == (b))
163 #define _cairo_uint64_negate(a) ((uint64_t) -((int64_t)(a)))
164 #define _cairo_uint64_negative(a) ((int64_t)(a) < 0)
165 #define _cairo_uint64_not(a) (~(a))
166 
167 #define _cairo_uint64_to_int64(i) ((int64_t)(i))
168 #define _cairo_int64_to_uint64(i) ((uint64_t)(i))
169 
170 #define _cairo_int32_to_int64(i) ((int64_t)(i))
171 #define _cairo_int64_to_int32(i) ((int32_t)(i))
172 #define _cairo_int64_add(a,b) ((a) + (b))
173 #define _cairo_int64_sub(a,b) ((a) - (b))
174 #define _cairo_int64_mul(a,b) ((a) * (b))
175 #define _cairo_int32x32_64_mul(a,b) ((int64_t)(a) * (b))
176 #define _cairo_int64_lt(a,b) ((a) < (b))
177 #define _cairo_int64_eq(a,b) ((a) == (b))
178 #define _cairo_int64_lsl(a,b) ((a) << (b))
179 #define _cairo_int64_rsl(a,b) ((int64_t)((uint64_t)(a) >> (b)))
180 #define _cairo_int64_rsa(a,b) ((int64_t)(a) >> (b))
181 #define _cairo_int64_negate(a) (-(a))
182 #define _cairo_int64_negative(a) ((a) < 0)
183 #define _cairo_int64_not(a) (~(a))
184 
185 #endif
186 
187 /*
188  * 64-bit comparisons derived from lt or eq
189  */
190 #define _cairo_uint64_le(a,b) (!_cairo_uint64_gt (a,b))
191 #define _cairo_uint64_ne(a,b) (!_cairo_uint64_eq (a,b))
192 #define _cairo_uint64_ge(a,b) (!_cairo_uint64_lt (a,b))
193 #define _cairo_uint64_gt(a,b) _cairo_uint64_lt (b,a)
194 
195 #define _cairo_int64_le(a,b) (!_cairo_int64_gt (a,b))
196 #define _cairo_int64_ne(a,b) (!_cairo_int64_eq (a,b))
197 #define _cairo_int64_ge(a,b) (!_cairo_int64_lt (a,b))
198 #define _cairo_int64_gt(a,b) _cairo_int64_lt (b,a)
199 
200 /*
201  * As the C implementation always computes both, create
202  * a function which returns both for the 'native' type as well
203  */
204 
205 typedef struct _cairo_uquorem64 {
209 
210 typedef struct _cairo_quorem64 {
214 
217 
220 
221 /*
222  * 128-bit datatypes. Again, provide two implementations in
223  * case the machine has a native 128-bit datatype. GCC supports int128_t
224  * on ia64
225  */
226 
227 #if !HAVE_UINT128_T
228 
229 extern const char * cairo_impl128;
230 
231 typedef struct cairo_uint128 {
233 } cairo_uint128_t, cairo_int128_t;
234 
235 cairo_uint128_t I _cairo_uint32_to_uint128 (uint32_t i);
236 cairo_uint128_t I _cairo_uint64_to_uint128 (cairo_uint64_t i);
237 #define _cairo_uint128_to_uint64(a) ((a).lo)
238 #define _cairo_uint128_to_uint32(a) _cairo_uint64_to_uint32 (_cairo_uint128_to_uint64 (a))
239 cairo_uint128_t I _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b);
240 cairo_uint128_t I _cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b);
241 cairo_uint128_t I _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b);
243 cairo_uint128_t I _cairo_uint128_lsl (cairo_uint128_t a, int shift);
244 cairo_uint128_t I _cairo_uint128_rsl (cairo_uint128_t a, int shift);
245 cairo_uint128_t I _cairo_uint128_rsa (cairo_uint128_t a, int shift);
246 int I _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b);
247 int I _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b);
248 cairo_uint128_t I _cairo_uint128_negate (cairo_uint128_t a);
249 #define _cairo_uint128_negative(a) (_cairo_uint64_negative (a.hi))
250 cairo_uint128_t I _cairo_uint128_not (cairo_uint128_t a);
251 
252 #define _cairo_uint128_to_int128(i) (i)
253 #define _cairo_int128_to_uint128(i) (i)
254 
257 #define _cairo_int128_to_int64(a) ((cairo_int64_t)(a).lo)
258 #define _cairo_int128_to_int32(a) _cairo_int64_to_int32 (_cairo_int128_to_int64 (a))
259 #define _cairo_int128_add(a,b) _cairo_uint128_add (a,b)
260 #define _cairo_int128_sub(a,b) _cairo_uint128_sub (a,b)
261 #define _cairo_int128_mul(a,b) _cairo_uint128_mul (a,b)
263 #define _cairo_int128_lsl(a,b) _cairo_uint128_lsl (a,b)
264 #define _cairo_int128_rsl(a,b) _cairo_uint128_rsl (a,b)
265 #define _cairo_int128_rsa(a,b) _cairo_uint128_rsa (a,b)
267 #define _cairo_int128_eq(a,b) _cairo_uint128_eq (a,b)
268 #define _cairo_int128_negate(a) _cairo_uint128_negate (a)
269 #define _cairo_int128_negative(a) (_cairo_uint128_negative (a))
270 #define _cairo_int128_not(a) _cairo_uint128_not (a)
271 
272 #else /* !HAVE_UINT128_T */
273 
274 extern const char * cairo_impl128;
275 
276 typedef uint128_t cairo_uint128_t;
277 typedef int128_t cairo_int128_t;
278 
279 #define _cairo_uint32_to_uint128(i) ((uint128_t)(i))
280 #define _cairo_uint64_to_uint128(i) ((uint128_t)(i))
281 #define _cairo_uint128_to_uint64(i) ((uint64_t)(i))
282 #define _cairo_uint128_to_uint32(i) ((uint32_t)(i))
283 #define _cairo_uint128_add(a,b) ((a) + (b))
284 #define _cairo_uint128_sub(a,b) ((a) - (b))
285 #define _cairo_uint128_mul(a,b) ((a) * (b))
286 #define _cairo_uint64x64_128_mul(a,b) ((uint128_t)(a) * (b))
287 #define _cairo_uint128_lsl(a,b) ((a) << (b))
288 #define _cairo_uint128_rsl(a,b) ((uint128_t)(a) >> (b))
289 #define _cairo_uint128_rsa(a,b) ((uint128_t)((int128_t)(a) >> (b)))
290 #define _cairo_uint128_lt(a,b) ((a) < (b))
291 #define _cairo_uint128_eq(a,b) ((a) == (b))
292 #define _cairo_uint128_negate(a) ((uint128_t) -((int128_t)(a)))
293 #define _cairo_uint128_negative(a) ((int128_t)(a) < 0)
294 #define _cairo_uint128_not(a) (~(a))
295 
296 #define _cairo_uint128_to_int128(i) ((int128_t)(i))
297 #define _cairo_int128_to_uint128(i) ((uint128_t)(i))
298 
299 #define _cairo_int32_to_int128(i) ((int128_t)(i))
300 #define _cairo_int64_to_int128(i) ((int128_t)(i))
301 #define _cairo_int128_to_int64(i) ((int64_t)(i))
302 #define _cairo_int128_to_int32(i) ((int32_t)(i))
303 #define _cairo_int128_add(a,b) ((a) + (b))
304 #define _cairo_int128_sub(a,b) ((a) - (b))
305 #define _cairo_int128_mul(a,b) ((a) * (b))
306 #define _cairo_int64x64_128_mul(a,b) ((int128_t)(a) * (b))
307 #define _cairo_int128_lt(a,b) ((a) < (b))
308 #define _cairo_int128_eq(a,b) ((a) == (b))
309 #define _cairo_int128_lsl(a,b) ((a) << (b))
310 #define _cairo_int128_rsl(a,b) ((int128_t)((uint128_t)(a) >> (b)))
311 #define _cairo_int128_rsa(a,b) ((int128_t)(a) >> (b))
312 #define _cairo_int128_negate(a) (-(a))
313 #define _cairo_int128_negative(a) ((a) < 0)
314 #define _cairo_int128_not(a) (~(a))
315 
316 #endif /* HAVE_UINT128_T */
317 
318 typedef struct _cairo_uquorem128 {
319  cairo_uint128_t quo;
320  cairo_uint128_t rem;
322 
323 typedef struct _cairo_quorem128 {
327 
329 _cairo_uint128_divrem (cairo_uint128_t num, cairo_uint128_t den);
330 
333 
335 _cairo_uint_96by64_32x64_divrem (cairo_uint128_t num,
336  cairo_uint64_t den);
337 
340  cairo_int64_t den);
341 
342 #define _cairo_uint128_le(a,b) (!_cairo_uint128_gt (a,b))
343 #define _cairo_uint128_ne(a,b) (!_cairo_uint128_eq (a,b))
344 #define _cairo_uint128_ge(a,b) (!_cairo_uint128_lt (a,b))
345 #define _cairo_uint128_gt(a,b) _cairo_uint128_lt (b,a)
346 
347 #define _cairo_int128_le(a,b) (!_cairo_int128_gt (a,b))
348 #define _cairo_int128_ne(a,b) (!_cairo_int128_eq (a,b))
349 #define _cairo_int128_ge(a,b) (!_cairo_int128_lt (a,b))
350 #define _cairo_int128_gt(a,b) _cairo_int128_lt (b,a)
351 
352 #undef I
353 
354 #ifdef __cplusplus
355 };
356 #endif
357 
358 
359 #endif /* CAIRO_WIDEINT_H */
cairo_uint128_t I _cairo_uint64_to_uint128(cairo_uint64_t i)
cairo_quorem64_t I _cairo_int_96by64_32x64_divrem(cairo_int128_t num, cairo_int64_t den)
#define I
#define _cairo_uint64_rsa(a, b)
const char * cairo_impl128
cairo_uint128_t I _cairo_uint128_negate(cairo_uint128_t a)
int I _cairo_uint128_eq(cairo_uint128_t a, cairo_uint128_t b)
#define _cairo_uint32x32_64_mul(a, b)
__int128_t int128_t
Definition: int64x64-128.h:30
#define _cairo_uint64_not(a)
int64_t cairo_int64_t
cairo_uquorem128_t I _cairo_uint128_divrem(cairo_uint128_t num, cairo_uint128_t den)
cairo_uquorem64_t I _cairo_uint_96by64_32x64_divrem(cairo_uint128_t num, cairo_uint64_t den)
_cairo_uint_96by64_32x64_divrem:
cairo_quorem128_t I _cairo_int128_divrem(cairo_int128_t num, cairo_int128_t den)
int I _cairo_int128_lt(cairo_int128_t a, cairo_int128_t b)
cairo_uint128_t I _cairo_uint128_rsa(cairo_uint128_t a, int shift)
cairo_int128_t I _cairo_int64x64_128_mul(cairo_int64_t a, cairo_int64_t b)
int I _cairo_uint128_lt(cairo_uint128_t a, cairo_uint128_t b)
#define _cairo_uint64_lsl(a, b)
cairo_quorem64_t I _cairo_int64_divrem(cairo_int64_t num, cairo_int64_t den)
__uint128_t uint128_t
Definition: int64x64-128.h:29
cairo_uint128_t I _cairo_uint128_rsl(cairo_uint128_t a, int shift)
cairo_int128_t I _cairo_int32_to_int128(int32_t i)
cairo_uint128_t I _cairo_uint32_to_uint128(uint32_t i)
cairo_uint128_t I _cairo_uint64x64_128_mul(cairo_uint64_t a, cairo_uint64_t b)
cairo_uquorem64_t I _cairo_uint64_divrem(cairo_uint64_t num, cairo_uint64_t den)
Definition: cairo-wideint.c:49
#define _cairo_uint64_mul(a, b)
cairo_uint128_t I _cairo_uint128_sub(cairo_uint128_t a, cairo_uint128_t b)
#define _cairo_uint64_rsl(a, b)
#define _cairo_uint32_to_uint64(i)
#define _cairo_int32x32_64_mul(a, b)
cairo_uint128_t I _cairo_uint128_lsl(cairo_uint128_t a, int shift)
uint64_t cairo_uint64_t
#define _cairo_uint64_add(a, b)
const char * cairo_impl64
Definition: cairo-wideint.c:44
cairo_uint128_t I _cairo_uint128_not(cairo_uint128_t a)
#define _cairo_uint64_negate(a)
#define _cairo_uint64_lt(a, b)
cairo_int128_t I _cairo_int64_to_int128(cairo_int64_t i)
cairo_uint128_t I _cairo_uint128_mul(cairo_uint128_t a, cairo_uint128_t b)
cairo_uint128_t I _cairo_uint128_add(cairo_uint128_t a, cairo_uint128_t b)
#define _cairo_int32_to_int64(i)
#define _cairo_uint64_sub(a, b)
#define _cairo_int64_lt(a, b)
#define _cairo_uint64_eq(a, b)