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/ix86/asm0.h"
2
/* Copyright (C) 2000 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 defines some "level 0" kernel functions for Intel ix86 */
17
/* It is intended for use with an external "asm" definition */
18
19
/*
20
ASM addll mulll bfffo divll
21
*/
22
#ifdef ASMINLINE
23
/* Written by Bruno Haible, 1996-1998.
24
addllx8/subllx8 by Bill Allombert, 2011.
25
*/
26
27
/* This file can assume the GNU C extensions.
28
(It is included only if __GNUC__ is defined.) */
29
30
/* Use local variables whenever possible. */
31
#define LOCAL_HIREMAINDER register ulong hiremainder
32
#define LOCAL_OVERFLOW register ulong overflow
33
34
#define addll(a,b) \
35
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
36
__asm__ ("addl %3,%0 ; adcl %1,%1" \
37
: "=r" (__value), "=r" (overflow) \
38
: "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \
39
: "cc"); \
40
__value; \
41
})
42
43
#define addllx(a,b) \
44
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
45
__asm__ ("subl %5,%2 ; adcl %4,%0 ; adcl %1,%1" \
46
: "=r" (__value), "=&r" (overflow), "=&r" (__temp) \
47
: "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \
48
: "cc"); \
49
__value; \
50
})
51
52
#define addllx8(a,b,c,overflow) \
53
do { long *__arg1 = a, *__arg2 = b, *__out = c; \
54
ulong __temp; \
55
__asm__ ("subl %5, %0 \n\t" \
56
"movl (%2), %0 ; adcl (%3),%0; movl %0, (%4) \n\t" \
57
"movl -4(%2), %0 ; adcl -4(%3),%0; movl %0, -4(%4) \n\t" \
58
"movl -8(%2), %0 ; adcl -8(%3),%0; movl %0, -8(%4) \n\t" \
59
"movl -12(%2), %0 ; adcl -12(%3),%0; movl %0, -12(%4) \n\t" \
60
"movl -16(%2), %0 ; adcl -16(%3),%0; movl %0, -16(%4) \n\t" \
61
"movl -20(%2), %0 ; adcl -20(%3),%0; movl %0, -20(%4) \n\t" \
62
"movl -24(%2), %0 ; adcl -24(%3),%0; movl %0, -24(%4) \n\t" \
63
"movl -28(%2), %0 ; adcl -28(%3),%0; movl %0, -28(%4) \n\t" \
64
"adcl %1, %1" \
65
: "=&r" (__temp), "=&r" (overflow) \
66
: "r" (__arg1), "r" (__arg2), "r" (__out), "g" (overflow), "0" ((ulong)0), "1" ((ulong)0) : "cc"); \
67
} while(0)
68
69
#define subll(a,b) \
70
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
71
__asm__ ("subl %3,%0 ; adcl %1,%1" \
72
: "=r" (__value), "=r" (overflow) \
73
: "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \
74
: "cc"); \
75
__value; \
76
})
77
78
#define subllx(a,b) \
79
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
80
__asm__ ("subl %5,%2 ; sbbl %4,%0 ; adcl %1,%1" \
81
: "=r" (__value), "=&r" (overflow), "=&r" (__temp) \
82
: "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \
83
: "cc"); \
84
__value; \
85
})
86
87
#define subllx8(a,b,c,overflow) \
88
do { long *__arg1 = a, *__arg2 = b, *__out = c; \
89
ulong __temp; \
90
__asm__ ("subl %5, %0 \n\t" \
91
"movl (%2), %0 ; sbbl (%3),%0; movl %0, (%4) \n\t" \
92
"movl -4(%2), %0 ; sbbl -4(%3),%0; movl %0, -4(%4) \n\t" \
93
"movl -8(%2), %0 ; sbbl -8(%3),%0; movl %0, -8(%4) \n\t" \
94
"movl -12(%2), %0 ; sbbl -12(%3),%0; movl %0, -12(%4) \n\t" \
95
"movl -16(%2), %0 ; sbbl -16(%3),%0; movl %0, -16(%4) \n\t" \
96
"movl -20(%2), %0 ; sbbl -20(%3),%0; movl %0, -20(%4) \n\t" \
97
"movl -24(%2), %0 ; sbbl -24(%3),%0; movl %0, -24(%4) \n\t" \
98
"movl -28(%2), %0 ; sbbl -28(%3),%0; movl %0, -28(%4) \n\t" \
99
"adcl %1, %1" \
100
: "=&r" (__temp), "=&r" (overflow) \
101
: "r" (__arg1), "r" (__arg2), "r" (__out), "g" (overflow), "0" ((ulong)0), "1" ((ulong)0) : "cc"); \
102
} while(0)
103
104
#define mulll(a,b) \
105
__extension__ ({ ulong __valuelo, __arg1 = (a), __arg2 = (b); \
106
__asm__ ("mull %3" \
107
: "=a" /* %eax */ (__valuelo), "=d" /* %edx */ (hiremainder) \
108
: "0" (__arg1), "rm" (__arg2)); \
109
__valuelo; \
110
})
111
112
#define addmul(a,b) \
113
__extension__ ({ ulong __valuelo, __arg1 = (a), __arg2 = (b), __temp; \
114
__asm__ ("mull %4 ; addl %5,%0 ; adcl %6,%1" \
115
: "=a" /* %eax */ (__valuelo), "=&d" /* %edx */ (hiremainder), "=r" (__temp) \
116
: "0" (__arg1), "rm" (__arg2), "g" (hiremainder), "2" ((ulong)0)); \
117
__valuelo; \
118
})
119
120
#define divll(a,b) \
121
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
122
__asm__ ("divl %4" \
123
: "=a" /* %eax */ (__value), "=d" /* %edx */ (hiremainder) \
124
: "0" /* %eax */ (__arg1), "1" /* %edx */ (hiremainder), "mr" (__arg2)); \
125
__value; \
126
})
127
128
#define bfffo(x) \
129
__extension__ ({ ulong __arg = (x); \
130
int leading_one_position; \
131
__asm__ ("bsrl %1,%0" : "=r" (leading_one_position) : "rm" (__arg)); \
132
31 - leading_one_position; \
133
})
134
135
#endif
136
137