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
ASM addll mulll bfffo
16
NOASM divll
17
*/
18
#ifdef ASMINLINE
19
#define LOCAL_HIREMAINDER register ulong hiremainder
20
#define LOCAL_OVERFLOW register ulong overflow
21
22
#define addll(a, b)\
23
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
24
__asm__ ("addc %0,%2,%3\n\txor %1,%2,%2\n\taddze %1,%4\n\t" \
25
: "=&r" (__value), "=r" (overflow) \
26
: "r" (__arg1), "r" (__arg2), "1" ((ulong) 0)); \
27
__value; \
28
})
29
30
#define addllx(a, b)\
31
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
32
__asm__ ("addc %0,%3,%4\n\tli %1,0\n\taddze %1,%4\n\taddc %0,%2,%5\n\taddze %1,%4\n\t" \
33
: "=&r" (__value), "=r" (overflow) \
34
: "r" (__arg1), "r" (__arg2), "1" (overflow), "0" ((ulong) 0)); \
35
__value; \
36
})
37
38
#define bfffo(a) \
39
__extension__ ({ ulong __a = (a), __value; \
40
__asm__ ("cntlzw %0, %1" : "=r" (__value) : "r" (__a)); \
41
__value; \
42
})
43
44
#define subll(a, b)\
45
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
46
__asm__ ("subfc %0,%3,%2\n\tli %1,0\n\taddme %1,%4\n\tneg %1,%4" \
47
: "=&r" (__value), "=r" (overflow) \
48
: "r" (__arg1), "r" (__arg2), "1" ((ulong)0)); \
49
__value; \
50
})
51
52
#define subllx(a, b)\
53
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
54
__asm__ ("subfc %0,%5,%2\n\tli %1,0\n\taddme %1,%5\n\tsubfc %0,%3,%4\n\taddme %1,%5\n\tneg %1,%5" \
55
: "=r" (__value), "=r" (overflow) \
56
: "r" (__arg1), "r" (__arg2), "0" ((ulong)0), "1" (overflow)); \
57
__value; \
58
})
59
60
#define mulll(a, b) \
61
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
62
__asm__ ("mulhwu %1,%2,%3\n\tmullw %0,%2,%3\n\t" \
63
: "=r" (__value), "=&r" (hiremainder) \
64
: "r" (__arg1), "r" (__arg2)); \
65
__value; \
66
})
67
68
#define addmul(a, b) \
69
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \
70
__asm__ ("mullw %0,%3,%4\n\tmulhwu %2,%3,%4\n\taddc %0,%5,%6\n\taddze %1,%7\n\t" \
71
: "=&r" (__value), "=r" (hiremainder), "=r" (__temp) \
72
: "r" (__arg1), "r" (__arg2), "0" ((ulong) 0), "1" (hiremainder), "2" ((ulong) 0)); \
73
__value; \
74
})
75
#endif
76
77