Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28495 views
License: GPL3
ubuntu2004
1
#line 2 "../src/kernel/none/addll.h"
2
/* Copyright (C) 2003 The PARI group.
3
4
This file is part of the PARI/GP package.
5
6
PARI/GP is free software; you can redistribute it and/or modify it under the
7
terms of the GNU General Public License as published by the Free Software
8
Foundation; either version 2 of the License, or (at your option) any later
9
version. It is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY WHATSOEVER.
11
12
Check the License for details. You should have received a copy of it, along
13
with the package; see the file 'COPYING'. If not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
15
16
/* This file originally adapted from gmp-3.1.1 (from T. Granlund), files
17
* longlong.h and gmp-impl.h
18
19
Copyright (C) 2000 Free Software Foundation, Inc. */
20
21
#undef LOCAL_OVERFLOW
22
#define LOCAL_OVERFLOW
23
extern ulong overflow;
24
25
#if !defined(INLINE)
26
extern long addll(ulong x, ulong y);
27
extern long addllx(ulong x, ulong y);
28
extern long subll(ulong x, ulong y);
29
extern long subllx(ulong x, ulong y);
30
#else
31
32
#if defined(__GNUC__) && !defined(DISABLE_INLINE)
33
#undef LOCAL_OVERFLOW
34
#define LOCAL_OVERFLOW register ulong overflow
35
36
#define addll(a, b) \
37
__extension__ ({ \
38
ulong __arg1 = (a), __arg2 = (b), __value = __arg1 + __arg2; \
39
overflow = (__value < __arg1); \
40
__value; \
41
})
42
43
#define addllx(a, b) \
44
__extension__ ({ \
45
ulong __arg1 = (a), __arg2 = (b), __value, __tmp = __arg1 + overflow;\
46
overflow = (__tmp < __arg1); \
47
__value = __tmp + __arg2; \
48
overflow |= (__value < __tmp); \
49
__value; \
50
})
51
52
#define subll(a, b) \
53
__extension__ ({ \
54
ulong __arg1 = (a), __arg2 = (b); \
55
overflow = (__arg2 > __arg1); \
56
__arg1 - __arg2; \
57
})
58
59
#define subllx(a, b) \
60
__extension__ ({ \
61
ulong __arg1 = (a), __arg2 = (b), __value, __tmp = __arg1 - overflow;\
62
overflow = (__arg1 < overflow); \
63
__value = __tmp - __arg2; \
64
overflow |= (__arg2 > __tmp); \
65
__value; \
66
})
67
68
#else /* __GNUC__ */
69
70
INLINE long
71
addll(ulong x, ulong y)
72
{
73
const ulong z = x+y;
74
overflow=(z<x);
75
return (long) z;
76
}
77
78
INLINE long
79
addllx(ulong x, ulong y)
80
{
81
const ulong z = x+y+overflow;
82
overflow = (z<x || (z==x && overflow));
83
return (long) z;
84
}
85
86
INLINE long
87
subll(ulong x, ulong y)
88
{
89
const ulong z = x-y;
90
overflow = (z>x);
91
return (long) z;
92
}
93
94
INLINE long
95
subllx(ulong x, ulong y)
96
{
97
const ulong z = x-y-overflow;
98
overflow = (z>x || (z==x && overflow));
99
return (long) z;
100
}
101
102
#endif /* __GNUC__ */
103
104
#endif
105
106