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
/* Copyright (C) 2000 The PARI group.
2
3
This file is part of the PARI/GP package.
4
5
PARI/GP is free software; you can redistribute it and/or modify it under the
6
terms of the GNU General Public License as published by the Free Software
7
Foundation; either version 2 of the License, or (at your option) any later
8
version. It is distributed in the hope that it will be useful, but WITHOUT
9
ANY WARRANTY WHATSOEVER.
10
11
Check the License for details. You should have received a copy of it, along
12
with the package; see the file 'COPYING'. If not, write to the Free Software
13
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
14
15
/* This file is a slight adaptation of source code extracted from gmp-3.1.1
16
(from T. Granlund), files longlong.h and gmp-impl.h
17
18
Copyright (C) 2000 Free Software Foundation, Inc.
19
20
* FIXME: This file is unused until somebody implements
21
* invert_word(x) = return floor( 2^(2*BIL)/x ) */
22
23
extern ulong invert_word(ulong);
24
25
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
26
do { \
27
ulong __x; \
28
__x = (al) - (bl); \
29
(sh) = (ah) - (bh) - (__x > (al)); \
30
(sl) = __x; \
31
} while (0)
32
33
#ifdef __GNUC__
34
35
#define divll(x, y) \
36
__extension__ ({ \
37
register ulong _di, _x = (x), _y = (y), _q, _ql, _r; \
38
register ulong _xh, _xl, _k, __hire; \
39
\
40
if (_y & 0x8000000000000000UL) \
41
{ _k = 0; __hire = hiremainder; } \
42
else \
43
{ \
44
_k = bfffo(_y); \
45
__hire = (hiremainder << _k) | (_x >> (64 - _k)); \
46
_x <<= _k; _y <<= _k; \
47
} \
48
_di = invert_word(_y); \
49
_ql = mulll (__hire, _di); \
50
_q = __hire + hiremainder; \
51
_xl = mulll(_q, _y); _xh = hiremainder; \
52
sub_ddmmss (_xh, _r, __hire, _x, _xh, _xl); \
53
if (_xh != 0) \
54
{ \
55
sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; \
56
if (_xh != 0) \
57
{ sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; } \
58
} \
59
if (_r >= _y) \
60
{ _r -= _y; _q += 1; } \
61
hiremainder = _r >> _k; \
62
_q; \
63
})
64
65
#else /* __GNUC__ */
66
67
static ulong
68
divll(ulong x, ulong y)
69
{
70
register ulong _di, _x = (x), _y = (y), _q, _ql, _r;
71
register ulong _xh, _xl, _k, __hire;
72
73
if (_y & 0x8000000000000000UL)
74
{ _k = 0; __hire = hiremainder; }
75
else
76
{
77
_k = bfffo(_y);
78
__hire = (hiremainder << _k) | (_x >> (64 - _k));
79
_x <<= _k; _y <<= _k;
80
}
81
_di = invert_word(_y);
82
_ql = mulll (__hire, _di);
83
_q = __hire + hiremainder;
84
_xl = mulll(_q, _y); _xh = hiremainder;
85
sub_ddmmss (_xh, _r, __hire, _x, _xh, _xl);
86
if (_xh != 0)
87
{
88
sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1;
89
if (_xh != 0)
90
{ sub_ddmmss (_xh, _r, _xh, _r, 0, _y); _q += 1; }
91
}
92
if (_r >= _y)
93
{ _r -= _y; _q += 1; }
94
hiremainder = _r >> _k;
95
return _q;
96
}
97
98
#endif /* __GNUC__ */
99
100