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/hppa64/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
/* This file was made using idea from Bruno Haible ix86 asm inline kernel
17
* and code from Nigel Smart hppa asm kernel. mulll was inspired from
18
* longlong.h from the GNU MP package.*/
19
20
/*
21
ASM addll mulll
22
NOASM bfffo divll
23
*/
24
#ifdef ASMINLINE
25
#define LOCAL_HIREMAINDER register ulong hiremainder
26
#define LOCAL_OVERFLOW register ulong overflow
27
28
#define addll(a,b) \
29
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
30
__asm__ ("add %2,%3,%0\n\tadd,dc %%r0,%%r0,%1" \
31
: "=r" (__value), "=r" (overflow) \
32
: "r" (__arg1), "r" (__arg2) \
33
: "cc"); \
34
__value; \
35
})
36
37
#define addllx(a,b) \
38
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
39
__asm__ ("sub %4,%5,%%r0\n\tadd,dc %2,%3,%0\n\tadd,dc %%r0,%%r0,%1" \
40
: "=r" (__value), "=r" (overflow) \
41
: "r" (__arg1), "r" (__arg2), "r" (overflow), "r" ((ulong) 1)\
42
: "cc"); \
43
__value; \
44
})
45
46
#define subll(a,b) \
47
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
48
__asm__ ("sub %2,%3,%0\n\tadd,dc %%r0,%%r0,%1\n\tsubi 1,%1,%1" \
49
: "=r" (__value), "=r" (overflow) \
50
: "r" (__arg1), "r" (__arg2) \
51
: "cc"); \
52
__value; \
53
})
54
55
#define subllx(a,b) \
56
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
57
__asm__ ("sub %%r0,%4,%%r0\n\tsub,db %2,%3,%0\n\tadd,dc %%r0,%%r0,%1\n\tsubi 1,%1,%1" \
58
: "=&r" (__value), "=r" (overflow) \
59
: "r" (__arg1), "r" (__arg2), "r" (overflow)\
60
: "cc"); \
61
__value; \
62
})
63
64
/* z=a+b; c+= carry; return z */
65
#define __addllc(a,b,c) \
66
__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
67
__asm__ ("add %2,%3,%0\n\tadd,dc %4,%%r0,%1" \
68
: "=&r" (__value), "=r" (c) \
69
: "r" (__arg1), "r" (__arg2), "r" (c) \
70
: "cc"); \
71
__value; \
72
})
73
74
/* 32x32->64 multiply*/
75
#define __mulhh(a,b) \
76
__extension__ ({ unsigned int __arg1 = (a), __arg2 = (b); \
77
ulong __value; \
78
__asm__ ("xmpyu %1,%2,%0" \
79
: "=f" (__value) \
80
: "f" (__arg1), "f" (__arg2) \
81
: "cc"); \
82
__value; \
83
})
84
85
#define mulll(arg1,arg2) \
86
__extension__ ({ \
87
const ulong __x=(arg1), __y=(arg2); \
88
const ulong __xlo = LOWWORD(__x), __xhi = HIGHWORD(__x); \
89
const ulong __ylo = LOWWORD(__y), __yhi = HIGHWORD(__y); \
90
ulong __xylo,__xymid,__xyhi,__xymidhi,__xymidlo; \
91
ulong __xylh,__xyhl; \
92
__xylo = __mulhh(__xlo,__ylo); __xyhi = __mulhh(__xhi,__yhi); \
93
__xylh = __mulhh(__xlo,__yhi); __xyhl = __mulhh(__xhi,__ylo); \
94
__xymid = __xylh+__xyhl; \
95
if (__xymid<__xylh) __xyhi += (1UL << BITS_IN_HALFULONG); \
96
__xymidhi = HIGHWORD(__xymid); \
97
__xymidlo = __xymid << BITS_IN_HALFULONG; \
98
__xylo = __addllc(__xylo,__xymidlo,__xyhi); \
99
hiremainder = __xyhi + __xymidhi; \
100
__xylo; \
101
})
102
103
#define addmul(arg1,arg2) \
104
__extension__ ({ \
105
const ulong __x=(arg1), __y=(arg2); \
106
const ulong __xlo = LOWWORD(__x), __xhi = HIGHWORD(__x); \
107
const ulong __ylo = LOWWORD(__y), __yhi = HIGHWORD(__y); \
108
ulong __xylo,__xymid,__xyhi,__xymidhi,__xymidlo; \
109
ulong __xylh,__xyhl; \
110
__xylo = __mulhh(__xlo,__ylo); __xyhi = __mulhh(__xhi,__yhi); \
111
__xylh = __mulhh(__xlo,__yhi); __xyhl = __mulhh(__xhi,__ylo); \
112
__xymid = __xylh+__xyhl; \
113
if (__xymid<__xylh) __xyhi += (1UL << BITS_IN_HALFULONG); \
114
__xylo = __addllc(__xylo,hiremainder,__xyhi); \
115
__xymidhi = HIGHWORD(__xymid); \
116
__xymidlo = __xymid << BITS_IN_HALFULONG; \
117
__xylo = __addllc(__xylo,__xymidlo,__xyhi); \
118
hiremainder = __xyhi + __xymidhi; \
119
__xylo; \
120
})
121
122
#endif
123
124