Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::varuint< N > Class Template Reference

#include <leb128.hpp>

Public Member Functions

constexpr varuint (bool v)
 
constexpr varuint (uint8_t v)
 
constexpr varuint (uint32_t v)
 
constexpr varuint (guarded_ptr< uint8_t > &code)
 
constexpr void from (bool v)
 
constexpr void from (uint8_t v)
 
constexpr void from (uint32_t v)
 
constexpr void from (guarded_ptr< uint8_t > &code)
 
size_t size () const
 
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
constexpr bool to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
constexpr uint8_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
constexpr uint32_t to ()
 
void print () const
 
constexpr varuint (bool v)
 
constexpr varuint (uint8_t v)
 
constexpr varuint (uint32_t v)
 
constexpr varuint (guarded_ptr< uint8_t > &code)
 
constexpr void from (bool v)
 
constexpr void from (uint8_t v)
 
constexpr void from (uint32_t v)
 
constexpr void from (guarded_ptr< uint8_t > &code)
 
size_t size () const
 
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
constexpr bool to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
constexpr uint8_t to ()
 
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
constexpr uint32_t to ()
 
void print () const
 

Detailed Description

template<size_t N>
class sysio::vm::varuint< N >

Definition at line 24 of file leb128.hpp.

Constructor & Destructor Documentation

◆ varuint() [1/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( bool v)
inlineexplicitconstexpr

Definition at line 28 of file leb128.hpp.

28{ from(v); }
constexpr void from(bool v)
Definition leb128.hpp:33
Here is the call graph for this function:

◆ varuint() [2/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( uint8_t v)
inlineexplicitconstexpr

Definition at line 29 of file leb128.hpp.

29{ from(v); }
Here is the call graph for this function:

◆ varuint() [3/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( uint32_t v)
inlineexplicitconstexpr

Definition at line 30 of file leb128.hpp.

30{ from(v); }
Here is the call graph for this function:

◆ varuint() [4/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 31 of file leb128.hpp.

31{ from(code); }
Here is the call graph for this function:

◆ varuint() [5/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( bool v)
inlineexplicitconstexpr

Definition at line 28 of file leb128.hpp.

28{ from(v); }
Here is the call graph for this function:

◆ varuint() [6/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( uint8_t v)
inlineexplicitconstexpr

Definition at line 29 of file leb128.hpp.

29{ from(v); }
Here is the call graph for this function:

◆ varuint() [7/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( uint32_t v)
inlineexplicitconstexpr

Definition at line 30 of file leb128.hpp.

30{ from(v); }
Here is the call graph for this function:

◆ varuint() [8/8]

template<size_t N>
sysio::vm::varuint< N >::varuint ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 31 of file leb128.hpp.

31{ from(code); }
Here is the call graph for this function:

Member Function Documentation

◆ from() [1/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( bool v)
inlineconstexpr

Definition at line 33 of file leb128.hpp.

33{ storage[0] = v; }
Here is the caller graph for this function:

◆ from() [2/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( bool v)
inlineconstexpr

Definition at line 33 of file leb128.hpp.

33{ storage[0] = v; }

◆ from() [3/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 56 of file leb128.hpp.

56 {
57 uint8_t cnt = 0;
58 for (;; cnt++) {
59 SYS_VM_ASSERT( cnt < bytes_needed<N>(), wasm_interpreter_exception, "incorrect leb128 encoding" );
60 SYS_VM_ASSERT( code.offset()+cnt < code.bounds(), wasm_interpreter_exception, "pointer out of bounds" );
61 storage[cnt] = code[cnt];
62 if ((storage[cnt] & 0x80) == 0) {
63 if( static_cast<size_t>(cnt + 1) == bytes_needed<N>() ) {
64 uint8_t mask = static_cast<uint8_t>(~(uint32_t)0 << uint32_t(N - 7*(bytes_needed<N>()-1))) & 0x7F;
65 SYS_VM_ASSERT((mask & storage[cnt]) == 0, wasm_parse_exception, "unused bits of unsigned leb128 must be 0");
66 }
67 break;
68 }
69 }
70 code += cnt+1;
71 bytes_used = cnt+1;
72 }
size_t constexpr bytes_needed()
Definition leb128.hpp:14
const int N
Definition quantize.cpp:54
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
Here is the call graph for this function:

◆ from() [4/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( guarded_ptr< uint8_t > & code)
inlineconstexpr

Definition at line 56 of file leb128.hpp.

56 {
57 uint8_t cnt = 0;
58 for (;; cnt++) {
59 SYS_VM_ASSERT( cnt < bytes_needed<N>(), wasm_interpreter_exception, "incorrect leb128 encoding" );
60 SYS_VM_ASSERT( code.offset()+cnt < code.bounds(), wasm_interpreter_exception, "pointer out of bounds" );
61 storage[cnt] = code[cnt];
62 if ((storage[cnt] & 0x80) == 0) {
63 if( static_cast<size_t>(cnt + 1) == bytes_needed<N>() ) {
64 uint8_t mask = static_cast<uint8_t>(~(uint32_t)0 << uint32_t(N - 7*(bytes_needed<N>()-1))) & 0x7F;
65 SYS_VM_ASSERT((mask & storage[cnt]) == 0, wasm_parse_exception, "unused bits of unsigned leb128 must be 0");
66 }
67 break;
68 }
69 }
70 code += cnt+1;
71 bytes_used = cnt+1;
72 }
Here is the call graph for this function:

◆ from() [5/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( uint32_t v)
inlineconstexpr

Definition at line 37 of file leb128.hpp.

37 {
38 bytes_used = 0;
39
40#ifdef __clang__
41#pragma unroll
42#elif defined(__GNUC__)
43#pragma GCC unroll 5
44#endif
45 for (; bytes_used < bytes_needed<N>(); bytes_used++) {
46 storage[bytes_used] = v & 0x7f;
47 v >>= 7;
48 if (v!= 0)
49 storage[bytes_used] |= 0x80;
50 else
51 break;
52 }
53 bytes_used++;
54 }

◆ from() [6/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( uint32_t v)
inlineconstexpr

Definition at line 37 of file leb128.hpp.

37 {
38 bytes_used = 0;
39
40#ifdef __clang__
41#pragma unroll
42#elif defined(__GNUC__)
43#pragma GCC unroll 5
44#endif
45 for (; bytes_used < bytes_needed<N>(); bytes_used++) {
46 storage[bytes_used] = v & 0x7f;
47 v >>= 7;
48 if (v!= 0)
49 storage[bytes_used] |= 0x80;
50 else
51 break;
52 }
53 bytes_used++;
54 }

◆ from() [7/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( uint8_t v)
inlineconstexpr

Definition at line 34 of file leb128.hpp.

34 {
35 storage[0] = v & 0x7f;
36 }

◆ from() [8/8]

template<size_t N>
void sysio::vm::varuint< N >::from ( uint8_t v)
inlineconstexpr

Definition at line 34 of file leb128.hpp.

34 {
35 storage[0] = v & 0x7f;
36 }

◆ print() [1/2]

template<size_t N>
void sysio::vm::varuint< N >::print ( ) const
inline

Definition at line 98 of file leb128.hpp.

98 {
99 for (int i=0; i < bytes_used; i++) {
100 std::cout << std::hex << "0x" << (int)storage[i] << ' ';
101 }
102 std::cout << std::endl;
103 }

◆ print() [2/2]

template<size_t N>
void sysio::vm::varuint< N >::print ( ) const
inline

Definition at line 98 of file leb128.hpp.

98 {
99 for (int i=0; i < bytes_used; i++) {
100 std::cout << std::hex << "0x" << (int)storage[i] << ' ';
101 }
102 std::cout << std::endl;
103 }

◆ size() [1/2]

template<size_t N>
size_t sysio::vm::varuint< N >::size ( ) const
inline

Definition at line 74 of file leb128.hpp.

74{ return bytes_used; }

◆ size() [2/2]

template<size_t N>
size_t sysio::vm::varuint< N >::size ( ) const
inline

Definition at line 74 of file leb128.hpp.

74{ return bytes_used; }

◆ to() [1/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
bool sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 77 of file leb128.hpp.

77{ return storage[0]; }
Here is the caller graph for this function:

◆ to() [2/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
uint8_t sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 80 of file leb128.hpp.

80{ return storage[0] & 0x7f; }

◆ to() [3/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
uint32_t sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 83 of file leb128.hpp.

83 {
84 uint32_t ret = 0;
85
86#ifdef __clang__
87#pragma unroll
88#elif defined(__GNUC__)
89#pragma GCC unroll 5
90#endif
91 for (int i=bytes_used-1; i >= 0; i--) {
92 ret <<= 7;
93 ret |= storage[i] & 0x7f;
94 }
95 return ret;
96 }
CK_RV ret

◆ to() [4/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 1, int>>
bool sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 77 of file leb128.hpp.

77{ return storage[0]; }

◆ to() [5/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 7, int>>
uint8_t sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 80 of file leb128.hpp.

80{ return storage[0] & 0x7f; }

◆ to() [6/6]

template<size_t N>
template<size_t M = N, typename = typename std::enable_if_t<M == 32, int>>
uint32_t sysio::vm::varuint< N >::to ( )
inlineconstexpr

Definition at line 83 of file leb128.hpp.

83 {
84 uint32_t ret = 0;
85
86#ifdef __clang__
87#pragma unroll
88#elif defined(__GNUC__)
89#pragma GCC unroll 5
90#endif
91 for (int i=bytes_used-1; i >= 0; i--) {
92 ret <<= 7;
93 ret |= storage[i] & 0x7f;
94 }
95 return ret;
96 }

The documentation for this class was generated from the following files: