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
/*
16
ASM addll mulll
17
NOASM bfffo divll
18
*/
19
#ifdef ASMINLINE
20
#define LOCAL_HIREMAINDER register ulong hiremainder
21
#define LOCAL_OVERFLOW register ulong overflow
22
23
#define addll(a, b)\
24
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
25
__asm__ ("addq %2,%3,%0\n\tcmpult %4,%2,%1" \
26
: "=&r" (__value), "=r" (overflow) \
27
: "r" (__arg1), "r" (__arg2), "0" ((ulong) 0)); \
28
__value; \
29
})
30
31
#define addllx(a, b)\
32
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
33
__asm__ ("addq %3,%4,%0\n\tcmpult %5,%3,%2\n\taddq %5,%6,%0\n\tcmpult %5,%6,%1\n\taddq %6,%7,%1\n\t" \
34
: "=&r" (__value), "=r" (overflow), "=r" (__temp) \
35
: "r" (__arg1), "r" (__arg2), "0" ((ulong) 0), "1" (overflow), "2" ((ulong) 0)); \
36
__value; \
37
})
38
39
#define subll(a, b)\
40
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
41
__asm__ ("subq %2,%3,%0\n\tcmpult %2,%4,%1" \
42
: "=&r" (__value), "=r" (overflow) \
43
: "r" (__arg1), "r" (__arg2), "0" ((ulong)0)); \
44
__value; \
45
})
46
47
#define subllx(a, b)\
48
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp1, __temp2; \
49
__asm__ ("subq %4,%5,%2\n\tcmpult %4,%8,%3\n\tsubq %8,%7,%0\n\tcmpult %8,%6,%1\n\taddq %7,%9,%1\n\t" \
50
: "=r" (__value), "=r" (overflow), "=&r" (__temp1), "=r" (__temp2) \
51
: "r" (__arg1), "r" (__arg2), "0" ((ulong)0), "1" (overflow), "2" ((ulong)0), "3" ((ulong)0)); \
52
__value; \
53
})
54
55
#define mulll(a, b) \
56
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
57
__asm__ ("umulh %2,%3,%1\n\tmulq %2,%3,%0\n\t" \
58
: "=r" (__value), "=&r" (hiremainder) \
59
: "r" (__arg1), "r" (__arg2)); \
60
__value; \
61
})
62
63
#define addmul(a, b) \
64
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
65
__asm__ ("mulq %3,%4,%0\n\tumulh %3,%4,%2\n\taddq %5,%6,%0\n\tcmpult %5,%6,%1\n\taddq %7,%6,%1\n\t" \
66
: "=&r" (__value), "=r" (hiremainder), "=r" (__temp) \
67
: "r" (__arg1), "r" (__arg2), "0" ((ulong) 0), "1" (hiremainder), "2" ((ulong) 0)); \
68
__value; \
69
})
70
#endif
71
72