3#include <sysio/vm/exceptions.hpp>
9namespace sysio {
namespace vm {
10inline constexpr uint32_t inv_float_eps = 0x4B000000;
11inline constexpr uint64_t inv_double_eps = 0x4330000000000000;
20inline float _sysio_f32_add(
float a,
float b ) {
24inline float _sysio_f32_sub(
float a,
float b ) {
28inline float _sysio_f32_div(
float a,
float b ) {
32inline float _sysio_f32_mul(
float a,
float b ) {
36inline float _sysio_f32_min(
float af,
float bf ) {
48 return ::f32_lt(
a,b) ? af : bf;
51inline float _sysio_f32_max(
float af,
float bf ) {
63 return ::f32_lt(
a, b ) ? bf : af;
66inline float _sysio_f32_copysign(
float af,
float bf ) {
70 a.v =
a.v | ((b.
v >> 31) << 31);
74inline float _sysio_f32_abs(
float af ) {
80inline float _sysio_f32_neg(
float af ) {
88inline float _sysio_f32_sqrt(
float a ) {
93inline float _sysio_f32_ceil(
float af ) {
95 int e = (int)(
a.v >> 23 & 0xFF) - 0X7F;
116inline float _sysio_f32_floor(
float af ) {
118 int e = (int)(
a.v >> 23 & 0xFF) - 0X7F;
138inline float _sysio_f32_trunc(
float af ) {
140 int e = (int)(
a.v >> 23 & 0xff) - 0x7f + 9;
153inline float _sysio_f32_nearest(
float af ) {
155 int e =
a.v>>23 & 0xff;
165 return s ? -0.0f : 0.0f;
173inline bool _sysio_f32_gt(
float af,
float bf ) {
183inline bool _sysio_f32_ge(
float af,
float bf ) {
193inline double _sysio_f64_add(
double a,
double b ) {
198inline double _sysio_f64_sub(
double a,
double b ) {
203inline double _sysio_f64_div(
double a,
double b ) {
208inline double _sysio_f64_mul(
double a,
double b ) {
213inline double _sysio_f64_min(
double af,
double bf ) {
222 return ::f64_lt(
a, b ) ? af : bf;
225inline double _sysio_f64_max(
double af,
double bf ) {
234 return ::f64_lt(
a, b ) ? bf : af;
237inline double _sysio_f64_copysign(
double af,
double bf ) {
241 a.v =
a.v | ((b.
v >> 63) << 63);
245inline double _sysio_f64_abs(
double af ) {
251inline double _sysio_f64_neg(
double af ) {
259inline double _sysio_f64_sqrt(
double a ) {
264inline double _sysio_f64_ceil(
double af ) {
267 int e =
a.
v >> 52 & 0x7ff;
269 if (e >= 0x3ff+52 ||
::f64_eq(
a, { 0 } ))
278 return a.v >> 63 ? -0.0 : 1.0;
288inline double _sysio_f64_floor(
double af ) {
291 int e =
a.
v >> 52 & 0x7FF;
293 if (
a.v == 0x8000000000000000) {
296 if (e >= 0x3FF+52 ||
a.v == 0) {
304 return a.v>>63 ? -1.0 : 0.0;
314inline double _sysio_f64_trunc(
double af ) {
316 int e = (int)(
a.v >> 52 & 0x7ff) - 0x3ff + 12;
329inline double _sysio_f64_nearest(
double af ) {
331 int e = (
a.v >> 52 & 0x7FF);
341 return s ? -0.0 : 0.0;
349inline bool _sysio_f64_gt(
double af,
double bf ) {
359inline bool _sysio_f64_ge(
double af,
double bf ) {
369inline double _sysio_f32_promote(
float a ) {
373inline float _sysio_f64_demote(
double a ) {
377inline int32_t _sysio_f32_trunc_i32s(
float af ) {
379 SYS_VM_ASSERT(!(_sysio_f32_ge(af, 2147483648.0f) || _sysio_f32_lt(af, -2147483648.0f)), wasm_interpreter_exception,
"Error, f32.convert_s/i32 overflow" );
381 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f32.convert_s/i32 unrepresentable");
385inline int32_t _sysio_f64_trunc_i32s(
double af ) {
387 SYS_VM_ASSERT(!(_sysio_f64_ge(af, 2147483648.0) || _sysio_f64_lt(af, -2147483648.0)), wasm_interpreter_exception,
"Error, f64.convert_s/i32 overflow");
388 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f64.convert_s/i32 unrepresentable");
392inline uint32_t _sysio_f32_trunc_i32u(
float af ) {
394 SYS_VM_ASSERT(!(_sysio_f32_ge(af, 4294967296.0f) || _sysio_f32_le(af, -1.0f)),wasm_interpreter_exception,
"Error, f32.convert_u/i32 overflow");
395 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f32.convert_u/i32 unrepresentable");
399inline uint32_t _sysio_f64_trunc_i32u(
double af ) {
401 SYS_VM_ASSERT(!(_sysio_f64_ge(af, 4294967296.0) || _sysio_f64_le(af, -1.0)), wasm_interpreter_exception,
"Error, f64.convert_u/i32 overflow");
402 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f64.convert_u/i32 unrepresentable");
406inline int64_t _sysio_f32_trunc_i64s(
float af ) {
408 SYS_VM_ASSERT(!(_sysio_f32_ge(af, 9223372036854775808.0f) || _sysio_f32_lt(af, -9223372036854775808.0f)), wasm_interpreter_exception,
"Error, f32.convert_s/i64 overflow");
409 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f32.convert_s/i64 unrepresentable");
413inline int64_t _sysio_f64_trunc_i64s(
double af ) {
415 SYS_VM_ASSERT(!(_sysio_f64_ge(af, 9223372036854775808.0) || _sysio_f64_lt(af, -9223372036854775808.0)), wasm_interpreter_exception,
"Error, f64.convert_s/i64 overflow");
416 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f64.convert_s/i64 unrepresentable");
421inline uint64_t _sysio_f32_trunc_i64u(
float af ) {
423 SYS_VM_ASSERT(!(_sysio_f32_ge(af, 18446744073709551616.0f) || _sysio_f32_le(af, -1.0f)), wasm_interpreter_exception,
"Error, f32.convert_u/i64 overflow");
424 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f32.convert_u/i64 unrepresentable");
428inline uint64_t _sysio_f64_trunc_i64u(
double af ) {
430 SYS_VM_ASSERT(!(_sysio_f64_ge(af, 18446744073709551616.0) || _sysio_f64_le(af, -1.0)), wasm_interpreter_exception,
"Error, f64.convert_u/i64 overflow");
431 SYS_VM_ASSERT(!is_nan(
a), wasm_interpreter_exception,
"Error, f64.convert_u/i64 unrepresentable");
435inline float _sysio_i32_to_f32(
int32_t a ) {
439inline float _sysio_i64_to_f32(
int64_t a ) {
443inline float _sysio_ui32_to_f32(
uint32_t a ) {
447inline float _sysio_ui64_to_f32(
uint64_t a ) {
451inline double _sysio_i32_to_f64(
int32_t a ) {
455inline double _sysio_i64_to_f64(
int64_t a ) {
459inline double _sysio_ui32_to_f64(
uint32_t a ) {
463inline double _sysio_ui64_to_f64(
uint64_t a ) {
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
float32_t f32_add(float32_t a, float32_t b)
float32_t f32_div(float32_t a, float32_t b)
bool f32_eq(float32_t a, float32_t b)
bool f32_le(float32_t a, float32_t b)
bool f32_lt(float32_t a, float32_t b)
float32_t f32_mul(float32_t a, float32_t b)
float32_t f32_sqrt(float32_t a)
float32_t f32_sub(float32_t a, float32_t b)
float64_t f32_to_f64(float32_t a)
int_fast32_t f32_to_i32(float32_t a, uint_fast8_t roundingMode, bool exact)
int_fast64_t f32_to_i64(float32_t a, uint_fast8_t roundingMode, bool exact)
uint_fast32_t f32_to_ui32(float32_t a, uint_fast8_t roundingMode, bool exact)
uint_fast64_t f32_to_ui64(float32_t a, uint_fast8_t roundingMode, bool exact)
float64_t f64_add(float64_t a, float64_t b)
float64_t f64_div(float64_t a, float64_t b)
bool f64_eq(float64_t a, float64_t b)
bool f64_le(float64_t a, float64_t b)
bool f64_lt(float64_t a, float64_t b)
float64_t f64_mul(float64_t a, float64_t b)
float64_t f64_sqrt(float64_t a)
float64_t f64_sub(float64_t a, float64_t b)
float32_t f64_to_f32(float64_t a)
int_fast32_t f64_to_i32(float64_t a, uint_fast8_t roundingMode, bool exact)
int_fast64_t f64_to_i64(float64_t a, uint_fast8_t roundingMode, bool exact)
uint_fast32_t f64_to_ui32(float64_t a, uint_fast8_t roundingMode, bool exact)
uint_fast64_t f64_to_ui64(float64_t a, uint_fast8_t roundingMode, bool exact)
float32_t i32_to_f32(int32_t a)
float64_t i32_to_f64(int32_t a)
float32_t i64_to_f32(int64_t a)
float64_t i64_to_f64(int64_t a)
float64_t ui64_to_f64(uint64_t)
float32_t ui32_to_f32(uint32_t)
float32_t ui64_to_f32(uint64_t)
float64_t ui32_to_f64(uint32_t)
float32_t to_softfloat32(float f)
bool f64_is_nan(const float64_t f)
double from_softfloat64(float64_t d)
bool f64_sign_bit(float64_t f)
bool f32_sign_bit(float32_t f)
float64_t to_softfloat64(double d)
float from_softfloat32(float32_t f)
bool f32_is_nan(const float32_t f)
unsigned __int64 uint64_t
#define SYS_VM_ASSERT(expr, exc_type, msg)