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