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/x86-64/asm0.h"
2
/* Copyright (C) 2004 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
/*
17
ASM addll mulll bfffo divll
18
*/
19
/* Written by Bill Allombert from the ix86 version by Bruno Haible. Basically
20
* change insl to insq*/
21
#ifdef ASMINLINE
22
#define LOCAL_HIREMAINDER register ulong hiremainder
23
#define LOCAL_OVERFLOW register ulong overflow
24
25
#define addll(a,b) \
26
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
27
__asm__ ("addq %3,%0 ; adcq %1,%1" \
28
: "=r" (__value), "=r" (overflow) \
29
: "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \
30
: "cc"); \
31
__value; \
32
})
33
34
#define addllx(a,b) \
35
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
36
__asm__ ("subq %5,%2 ; adcq %4,%0 ; adcq %1,%1" \
37
: "=r" (__value), "=&r" (overflow), "=&r" (__temp) \
38
: "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \
39
: "cc"); \
40
__value; \
41
})
42
43
#define addllx8(a,b,c,overflow) \
44
do { long *__arg1 = a, *__arg2 = b, *__out = c; \
45
ulong __temp; \
46
__asm__ ("subq %5, %0 \n\t" \
47
"movq (%2), %0 ; adcq (%3),%0; movq %0, (%4) \n\t" \
48
"movq -8(%2), %0 ; adcq -8(%3),%0; movq %0, -8(%4) \n\t" \
49
"movq -16(%2), %0 ; adcq -16(%3),%0; movq %0, -16(%4) \n\t" \
50
"movq -24(%2), %0 ; adcq -24(%3),%0; movq %0, -24(%4) \n\t" \
51
"movq -32(%2), %0 ; adcq -32(%3),%0; movq %0, -32(%4) \n\t" \
52
"movq -40(%2), %0 ; adcq -40(%3),%0; movq %0, -40(%4) \n\t" \
53
"movq -48(%2), %0 ; adcq -48(%3),%0; movq %0, -48(%4) \n\t" \
54
"movq -56(%2), %0 ; adcq -56(%3),%0; movq %0, -56(%4) \n\t" \
55
"adcq %1, %1" \
56
: "=&r" (__temp), "=&r" (overflow) \
57
: "r" (__arg1), "r" (__arg2), "r" (__out), "g" (overflow), "0" ((ulong)0), "1" ((ulong)0) \
58
: "cc"); \
59
} while(0)
60
61
#define subll(a,b) \
62
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
63
__asm__ ("subq %3,%0 ; adcq %1,%1" \
64
: "=r" (__value), "=r" (overflow) \
65
: "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \
66
: "cc"); \
67
__value; \
68
})
69
70
#define subllx(a,b) \
71
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
72
__asm__ ("subq %5,%2 ; sbbq %4,%0 ; adcq %1,%1" \
73
: "=r" (__value), "=&r" (overflow), "=&r" (__temp) \
74
: "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \
75
: "cc"); \
76
__value; \
77
})
78
79
#define subllx8(a,b,c,overflow) \
80
do { long *__arg1 = a, *__arg2 = b, *__out = c; \
81
ulong __temp; \
82
__asm__ ("subq %5, %0 \n\t" \
83
"movq (%2), %0 ; sbbq (%3),%0; movq %0, (%4) \n\t" \
84
"movq -8(%2), %0 ; sbbq -8(%3),%0; movq %0, -8(%4) \n\t" \
85
"movq -16(%2), %0 ; sbbq -16(%3),%0; movq %0, -16(%4) \n\t" \
86
"movq -24(%2), %0 ; sbbq -24(%3),%0; movq %0, -24(%4) \n\t" \
87
"movq -32(%2), %0 ; sbbq -32(%3),%0; movq %0, -32(%4) \n\t" \
88
"movq -40(%2), %0 ; sbbq -40(%3),%0; movq %0, -40(%4) \n\t" \
89
"movq -48(%2), %0 ; sbbq -48(%3),%0; movq %0, -48(%4) \n\t" \
90
"movq -56(%2), %0 ; sbbq -56(%3),%0; movq %0, -56(%4) \n\t" \
91
"adcq %1, %1" \
92
: "=&r" (__temp), "=&r" (overflow) \
93
: "r" (__arg1), "r" (__arg2), "r" (__out), "g" (overflow), "0" ((ulong)0), "1" ((ulong)0) \
94
: "cc"); \
95
} while(0)
96
97
#define mulll(a,b) \
98
__extension__ ({ ulong __valuelo, __arg1 = (a), __arg2 = (b); \
99
__asm__ ("mulq %3" \
100
: "=a" /* %eax */ (__valuelo), "=d" /* %edx */ (hiremainder) \
101
: "0" (__arg1), "rm" (__arg2)); \
102
__valuelo; \
103
})
104
105
#define addmul(a,b) \
106
__extension__ ({ ulong __valuelo, __arg1 = (a), __arg2 = (b), __temp; \
107
__asm__ ("mulq %4 ; addq %5,%0 ; adcq %6,%1" \
108
: "=a" /* %eax */ (__valuelo), "=&d" /* %edx */ (hiremainder), "=r" (__temp) \
109
: "0" (__arg1), "rm" (__arg2), "g" (hiremainder), "2" ((ulong)0)); \
110
__valuelo; \
111
})
112
113
#define divll(a,b) \
114
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
115
__asm__ ("divq %4" \
116
: "=a" /* %eax */ (__value), "=d" /* %edx */ (hiremainder) \
117
: "0" /* %eax */ (__arg1), "1" /* %edx */ (hiremainder), "mr" (__arg2)); \
118
__value; \
119
})
120
121
#define bfffo(x) \
122
__extension__ ({ ulong __arg = (x); \
123
long leading_one_position; \
124
__asm__ ("bsrq %1,%0" : "=r" (leading_one_position) : "rm" (__arg)); \
125
63 - leading_one_position; \
126
})
127
#endif
128
129