A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cairo-wideint-private.h
Go to the documentation of this file.
1// NOLINTBEGIN
2// clang-format off
3
4/* cairo - a vector graphics library with display and print output
5 *
6 * Copyright © 2004 Keith Packard
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * The original code as contributed to the cairo library under
22 * the dual license MPL+LGPL. We used the LGPL relicensing clause to
23 * get a GPL version of this code which now lives here. This header is
24 * unmodified other than the licensing clause.
25 *
26 * The Original Code is the cairo graphics library.
27 *
28 * The Initial Developer of the Original Code is Keith Packard
29 *
30 * Contributor(s):
31 * Keith R. Packard <keithp@keithp.com>
32 *
33 */
34
35#ifndef CAIRO_WIDEINT_H
36#define CAIRO_WIDEINT_H
37
38/**
39 * \file
40 * \ingroup highprec
41 * \c cairo_x function declarations, which provide the fallback
42 * high precision arithmetic implementation.
43 */
44
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)
70typedef __int8 int8_t;
71typedef unsigned __int8 uint8_t;
72typedef __int16 int16_t;
73typedef unsigned __int16 uint16_t;
74typedef __int32 int32_t;
75typedef unsigned __int32 uint32_t;
76typedef __int64 int64_t;
77typedef 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
95extern "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
111extern const char * cairo_impl64;
112
113typedef struct _cairo_uint64 {
115} cairo_uint64_t, cairo_int64_t;
116
117cairo_uint64_t cairo_I _cairo_uint32_to_uint64 (uint32_t i);
118#define _cairo_uint64_to_uint32(a) ((a).lo)
119cairo_uint64_t cairo_I _cairo_uint64_add (cairo_uint64_t a, cairo_uint64_t b);
120cairo_uint64_t cairo_I _cairo_uint64_sub (cairo_uint64_t a, cairo_uint64_t b);
121cairo_uint64_t cairo_I _cairo_uint64_mul (cairo_uint64_t a, cairo_uint64_t b);
123cairo_uint64_t cairo_I _cairo_uint64_lsl (cairo_uint64_t a, int shift);
124cairo_uint64_t cairo_I _cairo_uint64_rsl (cairo_uint64_t a, int shift);
125cairo_uint64_t cairo_I _cairo_uint64_rsa (cairo_uint64_t a, int shift);
126int cairo_I _cairo_uint64_lt (cairo_uint64_t a, cairo_uint64_t b);
127int cairo_I _cairo_uint64_eq (cairo_uint64_t a, cairo_uint64_t b);
128cairo_uint64_t cairo_I _cairo_uint64_negate (cairo_uint64_t a);
129#define _cairo_uint64_negative(a) (((int32_t)((a).hi)) < 0)
130cairo_uint64_t cairo_I _cairo_uint64_not (cairo_uint64_t a);
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)
141int cairo_I _cairo_int64_lt (cairo_uint64_t a, cairo_uint64_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
152extern const char * cairo_impl64;
153
154typedef uint64_t cairo_uint64_t;
155typedef 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
210typedef struct _cairo_uquorem64 {
211 cairo_uint64_t quo;
212 cairo_uint64_t rem;
214
215typedef struct _cairo_quorem64 {
219
221_cairo_uint64_divrem (cairo_uint64_t num, cairo_uint64_t den);
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
234extern const char * cairo_impl128;
235
236typedef struct cairo_uint128 {
237 cairo_uint64_t lo, hi;
238} cairo_uint128_t, cairo_int128_t;
239
240cairo_uint128_t cairo_I _cairo_uint32_to_uint128 (uint32_t i);
241cairo_uint128_t cairo_I _cairo_uint64_to_uint128 (cairo_uint64_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))
244cairo_uint128_t cairo_I _cairo_uint128_add (cairo_uint128_t a, cairo_uint128_t b);
245cairo_uint128_t cairo_I _cairo_uint128_sub (cairo_uint128_t a, cairo_uint128_t b);
246cairo_uint128_t cairo_I _cairo_uint128_mul (cairo_uint128_t a, cairo_uint128_t b);
247cairo_uint128_t cairo_I _cairo_uint64x64_128_mul (cairo_uint64_t a, cairo_uint64_t b);
248cairo_uint128_t cairo_I _cairo_uint128_lsl (cairo_uint128_t a, int shift);
249cairo_uint128_t cairo_I _cairo_uint128_rsl (cairo_uint128_t a, int shift);
250cairo_uint128_t cairo_I _cairo_uint128_rsa (cairo_uint128_t a, int shift);
251int cairo_I _cairo_uint128_lt (cairo_uint128_t a, cairo_uint128_t b);
252int cairo_I _cairo_uint128_eq (cairo_uint128_t a, cairo_uint128_t b);
253cairo_uint128_t cairo_I _cairo_uint128_negate (cairo_uint128_t a);
254#define _cairo_uint128_negative(a) (_cairo_uint64_negative (a.hi))
255cairo_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
279extern const char * cairo_impl128;
280
281typedef uint128_t cairo_uint128_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
323typedef struct _cairo_uquorem128 {
324 cairo_uint128_t quo;
325 cairo_uint128_t rem;
327
328typedef 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
cairo_uint64_t cairo_I _cairo_uint64_rsl(cairo_uint64_t a, int shift)
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)
int cairo_I _cairo_uint64_eq(cairo_uint64_t a, cairo_uint64_t b)
cairo_uint128_t cairo_I _cairo_uint128_negate(cairo_uint128_t a)
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)
cairo_uint128_t cairo_I _cairo_uint128_not(cairo_uint128_t a)
cairo_int128_t cairo_I _cairo_int64_to_int128(cairo_int64_t i)
cairo_int64_t cairo_I _cairo_int32x32_64_mul(int32_t a, int32_t b)
cairo_uint64_t cairo_I _cairo_uint64_add(cairo_uint64_t a, cairo_uint64_t b)
int cairo_I _cairo_uint64_lt(cairo_uint64_t a, cairo_uint64_t b)
cairo_uquorem64_t cairo_I _cairo_uint64_divrem(cairo_uint64_t num, cairo_uint64_t den)
const char * cairo_impl64
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)
cairo_uint128_t cairo_I _cairo_uint128_mul(cairo_uint128_t a, cairo_uint128_t b)
const char * cairo_impl128
cairo_int128_t cairo_I _cairo_int64x64_128_mul(cairo_int64_t a, cairo_int64_t b)
cairo_uint64_t cairo_I _cairo_uint32x32_64_mul(uint32_t a, uint32_t b)
int cairo_I _cairo_int64_lt(cairo_uint64_t a, cairo_uint64_t b)
cairo_uint128_t cairo_I _cairo_uint32_to_uint128(uint32_t i)
cairo_uint128_t cairo_I _cairo_uint64x64_128_mul(cairo_uint64_t a, cairo_uint64_t b)
cairo_uint64_t cairo_I _cairo_uint32_to_uint64(uint32_t i)
cairo_uint128_t cairo_I _cairo_uint128_sub(cairo_uint128_t a, cairo_uint128_t b)
cairo_uint128_t cairo_I _cairo_uint128_lsl(cairo_uint128_t a, int shift)
cairo_uint64_t cairo_I _cairo_uint64_lsl(cairo_uint64_t a, int shift)
#define cairo_I
cairo_int64_t cairo_I _cairo_int32_to_int64(int32_t i)
cairo_uint128_t cairo_I _cairo_uint128_rsl(cairo_uint128_t a, int shift)
cairo_uint64_t cairo_I _cairo_uint64_sub(cairo_uint64_t a, cairo_uint64_t b)
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)
cairo_uint64_t cairo_I _cairo_uint64_rsa(cairo_uint64_t a, int shift)
cairo_uint64_t cairo_I _cairo_uint64_negate(cairo_uint64_t a)
cairo_int128_t cairo_I _cairo_int32_to_int128(int32_t i)
cairo_uint64_t cairo_I _cairo_uint64_mul(cairo_uint64_t a, cairo_uint64_t b)
cairo_uint128_t cairo_I _cairo_uint64_to_uint128(cairo_uint64_t i)
cairo_uint64_t cairo_I _cairo_uint64_not(cairo_uint64_t a)
__uint128_t uint128_t
Use uint128_t for int64x64_t implementation.
__int128_t int128_t
Use uint128_t for int64x64_t implementation.