Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
compiler_builtins.cpp
Go to the documentation of this file.
2
4#include <softfloat.hpp>
5
6#include <fc/uint128.hpp>
7
8namespace sysio { namespace chain { namespace webassembly {
9
11 fc::uint128 i(high, low);
12 i <<= shift;
13 *ret = (unsigned __int128)i;
14 }
15
17 // retain the signedness
18 *ret = high;
19 *ret <<= 64;
20 *ret |= low;
21 *ret >>= shift;
22 }
23
25 fc::uint128 i(high, low);
26 i <<= shift;
27 *ret = (unsigned __int128)i;
28 }
29
31 fc::uint128 i(high, low);
32 i >>= shift;
33 *ret = (unsigned __int128)i;
34 }
35
37 __int128 lhs = ha;
38 __int128 rhs = hb;
39
40 lhs <<= 64;
41 lhs |= la;
42
43 rhs <<= 64;
44 rhs |= lb;
45
46 SYS_ASSERT(rhs != 0, arithmetic_exception, "divide by zero");
47
48 lhs /= rhs;
49
50 *ret = lhs;
51 }
52
54 unsigned __int128 lhs = ha;
55 unsigned __int128 rhs = hb;
56
57 lhs <<= 64;
58 lhs |= la;
59
60 rhs <<= 64;
61 rhs |= lb;
62
63 SYS_ASSERT(rhs != 0, arithmetic_exception, "divide by zero");
64
65 lhs /= rhs;
66 *ret = lhs;
67 }
68
70 __int128 lhs = ha;
71 __int128 rhs = hb;
72
73 lhs <<= 64;
74 lhs |= la;
75
76 rhs <<= 64;
77 rhs |= lb;
78
79 lhs *= rhs;
80 *ret = lhs;
81 }
82
84 __int128 lhs = ha;
85 __int128 rhs = hb;
86
87 lhs <<= 64;
88 lhs |= la;
89
90 rhs <<= 64;
91 rhs |= lb;
92
93 SYS_ASSERT(rhs != 0, arithmetic_exception, "divide by zero");
94
95 lhs %= rhs;
96 *ret = lhs;
97 }
98
100 unsigned __int128 lhs = ha;
101 unsigned __int128 rhs = hb;
102
103 lhs <<= 64;
104 lhs |= la;
105
106 rhs <<= 64;
107 rhs |= lb;
108
109 SYS_ASSERT(rhs != 0, arithmetic_exception, "divide by zero");
110
111 lhs %= rhs;
112 *ret = lhs;
113 }
114
115 // arithmetic long double
117 float128_t a = {{ la, ha }};
118 float128_t b = {{ lb, hb }};
119 *ret = f128_add( a, b );
120 }
122 float128_t a = {{ la, ha }};
123 float128_t b = {{ lb, hb }};
124 *ret = f128_sub( a, b );
125 }
127 float128_t a = {{ la, ha }};
128 float128_t b = {{ lb, hb }};
129 *ret = f128_mul( a, b );
130 }
132 float128_t a = {{ la, ha }};
133 float128_t b = {{ lb, hb }};
134 *ret = f128_div( a, b );
135 }
137 *ret = {{ la, (ha ^ (uint64_t)1 << 63) }};
138 }
139
140 // conversion long double
148 float128_t f = {{ l, h }};
149 return from_softfloat64(f128_to_f64( f ));
150 }
152 float128_t f = {{ l, h }};
153 return from_softfloat32(f128_to_f32( f ));
154 }
156 float128_t f = {{ l, h }};
157 return f128_to_i32( f, 0, false );
158 }
160 float128_t f = {{ l, h }};
161 return f128_to_i64( f, 0, false );
162 }
164 float128_t f = {{ l, h }};
165 *ret = ___fixtfti( f );
166 }
168 float128_t f = {{ l, h }};
169 return f128_to_ui32( f, 0, false );
170 }
172 float128_t f = {{ l, h }};
173 return f128_to_ui64( f, 0, false );
174 }
181 }
184 }
191 double interface::__floatsidf( int32_t i ) const {
192 return from_softfloat64(i32_to_f64(i));
193 }
207 fc::uint128 v(h, l);
208 unsigned __int128 val = (unsigned __int128)v;
209 return ___floattidf( *(__int128*)&val );
210 }
212 fc::uint128 v(h, l);
213 return ___floatuntidf( (unsigned __int128)v );
214 }
215
216 inline static int cmptf2_impl( const interface& i, uint64_t la, uint64_t ha, uint64_t lb, uint64_t hb, int return_value_if_nan ) {
217 float128_t a = {{ la, ha }};
218 float128_t b = {{ lb, hb }};
219 if ( i.__unordtf2(la, ha, lb, hb) )
220 return return_value_if_nan;
221 if ( f128_lt( a, b ) )
222 return -1;
223 if ( f128_eq( a, b ) )
224 return 0;
225 return 1;
226 }
228 return cmptf2_impl(*this, la, ha, lb, hb, 1);
229 }
231 return cmptf2_impl(*this, la, ha, lb, hb, 1);
232 }
234 return cmptf2_impl(*this, la, ha, lb, hb, -1);
235 }
237 return cmptf2_impl(*this, la, ha, lb, hb, 0);
238 }
240 return cmptf2_impl(*this, la, ha, lb, hb, 1);
241 }
243 return cmptf2_impl(*this, la, ha, lb, hb, 0);
244 }
246 return cmptf2_impl(*this, la, ha, lb, hb, 1);
247 }
249 float128_t a = {{ la, ha }};
250 float128_t b = {{ lb, hb }};
251 if ( f128_is_nan(a) || f128_is_nan(b) )
252 return 1;
253 return 0;
254 }
255}}} // ns sysio::chain::webassembly
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
an implementation of 128 bit unsigned integer
Definition uint128.hpp:22
void __ashlti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint32_t) const
int32_t __lttf2(uint64_t, uint64_t, uint64_t, uint64_t) const
void __floatunditf(legacy_ptr< float128_t >, uint64_t) const
void __floatunsitf(legacy_ptr< float128_t >, uint32_t) const
void __subtf3(legacy_ptr< float128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __fixunssfti(legacy_ptr< uint128_t >, float) const
uint32_t __fixunstfsi(uint64_t, uint64_t) const
int32_t __fixtfsi(uint64_t, uint64_t) const
void __lshrti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint32_t) const
void __lshlti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint32_t) const
void __divtf3(legacy_ptr< float128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __floatditf(legacy_ptr< float128_t >, uint64_t) const
void __extenddftf2(legacy_ptr< float128_t >, double) const
void __fixtfti(legacy_ptr< int128_t >, uint64_t, uint64_t) const
void __umodti3(legacy_ptr< uint128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __fixunsdfti(legacy_ptr< uint128_t >, double) const
void __negtf2(legacy_ptr< float128_t >, uint64_t, uint64_t) const
void __divti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
int32_t __eqtf2(uint64_t, uint64_t, uint64_t, uint64_t) const
uint64_t __fixunstfdi(uint64_t, uint64_t) const
int32_t __cmptf2(uint64_t, uint64_t, uint64_t, uint64_t) const
double __floatuntidf(uint64_t, uint64_t) const
void __fixunstfti(legacy_ptr< uint128_t >, uint64_t, uint64_t) const
int32_t __netf2(uint64_t, uint64_t, uint64_t, uint64_t) const
double __floattidf(uint64_t, uint64_t) const
float __trunctfsf2(uint64_t, uint64_t) const
void __modti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __extendsftf2(legacy_ptr< float128_t >, float) const
void __multf3(legacy_ptr< float128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __floatsitf(legacy_ptr< float128_t >, int32_t) const
void __fixsfti(legacy_ptr< int128_t >, float) const
int64_t __fixtfdi(uint64_t, uint64_t) const
int32_t __letf2(uint64_t, uint64_t, uint64_t, uint64_t) const
int32_t __gttf2(uint64_t, uint64_t, uint64_t, uint64_t) const
double __trunctfdf2(uint64_t, uint64_t) const
void __addtf3(legacy_ptr< float128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __ashrti3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint32_t) const
void __multi3(legacy_ptr< int128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
void __fixdfti(legacy_ptr< int128_t >, double) const
int32_t __unordtf2(uint64_t, uint64_t, uint64_t, uint64_t) const
void __udivti3(legacy_ptr< uint128_t >, uint64_t, uint64_t, uint64_t, uint64_t) const
int32_t __getf2(uint64_t, uint64_t, uint64_t, uint64_t) const
__int128 ___fixdfti(uint64_t)
Definition fixdfti.c:16
unsigned __int128 ___fixunsdfti(uint64_t)
Definition fixunsdfti.c:15
double ___floatuntidf(unsigned __int128)
double ___floattidf(__int128)
Definition floattidf.c:26
unsigned __int128 ___fixunssfti(uint32_t)
Definition fixunssfti.c:19
__int128 ___fixtfti(float128_t)
Definition fixtfti.c:13
__int128 ___fixsfti(uint32_t)
Definition fixsfti.c:16
unsigned __int128 ___fixunstfti(float128_t)
Definition fixunstfti.c:18
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
float128_t f128_add(float128_t a, float128_t b)
Definition f128_add.c:43
float128_t f128_div(float128_t a, float128_t b)
Definition f128_div.c:44
bool f128_eq(float128_t a, float128_t b)
Definition f128_eq.c:44
bool f128_lt(float128_t a, float128_t b)
Definition f128_lt.c:43
float128_t f128_mul(float128_t a, float128_t b)
Definition f128_mul.c:44
float128_t f128_sub(float128_t a, float128_t b)
Definition f128_sub.c:43
float32_t f128_to_f32(float128_t a)
Definition f128_to_f32.c:44
float64_t f128_to_f64(float128_t a)
Definition f128_to_f64.c:44
int_fast32_t f128_to_i32(float128_t a, uint_fast8_t roundingMode, bool exact)
Definition f128_to_i32.c:44
int_fast64_t f128_to_i64(float128_t a, uint_fast8_t roundingMode, bool exact)
Definition f128_to_i64.c:44
uint_fast32_t f128_to_ui32(float128_t a, uint_fast8_t roundingMode, bool exact)
uint_fast64_t f128_to_ui64(float128_t a, uint_fast8_t roundingMode, bool exact)
float128_t f32_to_f128(float32_t a)
Definition f32_to_f128.c:44
float128_t f64_to_f128(float64_t a)
Definition f64_to_f128.c:44
float128_t i32_to_f128(int32_t a)
Definition i32_to_f128.c:42
float64_t i32_to_f64(int32_t a)
Definition i32_to_f64.c:43
float128_t i64_to_f128(int64_t a)
Definition i64_to_f128.c:42
float32_t to_softfloat32(float f)
float128_t ui32_to_f128(uint32_t)
bool f128_is_nan(const float128_t &f)
double from_softfloat64(float64_t d)
float64_t to_softfloat64(double d)
float from_softfloat32(float32_t f)
float128_t ui64_to_f128(uint64_t)
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
CK_ULONG d
CK_RV ret
int l