Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#include <algorithm>
2#include <cmath>
3#include <cstdlib>
4#include <cstring>
5#include <fstream>
6#include <iterator>
7#include <string>
8#include <vector>
9#include <sysio/vm/allocator.hpp>
10#include <sysio/vm/stack_elem.hpp>
11#include <sysio/vm/utils.hpp>
12
14 union {
16 float f;
19 uint32_t to_ui() const { return _data.ui; }
20 float to_f() const { return _data.f; }
21};
22
24 union {
26 double f;
29 uint64_t to_ui() const { return _data.ui; }
30 double to_f() const { return _data.f; }
31};
32
33// C++20: using std::bit_cast;
34template<typename T, typename U>
35T bit_cast(const U& u) {
36 static_assert(sizeof(T) == sizeof(U), "bitcast requires identical sizes.");
37 T result;
38 std::memcpy(&result, &u, sizeof(T));
39 return result;
40}
41
42
43inline bool check_nan(const std::optional<sysio::vm::operand_stack_elem>& v) {
44 return visit(sysio::vm::overloaded{[](sysio::vm::i32_const_t){ return false; },
45 [](sysio::vm::i64_const_t){ return false; },
46 [](sysio::vm::f32_const_t f) { return std::isnan(f.data.f); },
47 [](sysio::vm::f64_const_t f) { return std::isnan(f.data.f); }}, *v);
48}
49
51 static sysio::vm::wasm_allocator alloc;
52 return &alloc;
53}
54
55#ifdef __x86_64__
56#define BACKEND_TEST_CASE(name, tags) \
57 TEMPLATE_TEST_CASE(name, tags, sysio::vm::interpreter, sysio::vm::jit)
58#else
59#define BACKEND_TEST_CASE(name, tags) \
60 TEMPLATE_TEST_CASE(name, tags, sysio::vm::interpreter)
61#endif
#define T(meth, val, expected)
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
float to_f() const
Definition utils.hpp:20
type_converter32(uint32_t n)
Definition utils.hpp:18
uint32_t ui
Definition utils.hpp:15
union type_converter32::@70 _data
uint32_t to_ui() const
Definition utils.hpp:19
type_converter64(uint64_t n)
Definition utils.hpp:28
double to_f() const
Definition utils.hpp:30
uint64_t ui
Definition utils.hpp:25
union type_converter64::@71 _data
uint64_t to_ui() const
Definition utils.hpp:29
bool check_nan(const std::optional< sysio::vm::operand_stack_elem > &v)
Definition utils.hpp:43
sysio::vm::wasm_allocator * get_wasm_allocator()
Definition utils.hpp:50
T bit_cast(const U &u)
Definition utils.hpp:35
Definition dtoa.c:306