protoverse

A metaverse protocol
git clone git://jb55.com/protoverse
Log | Files | Refs | README | LICENSE

commit cf4664d5e2f2c2e3d14e018c247754fd894c08e9
parent ec76dc8a95fe7e30c929be1f20582d79b79a067e
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 18 Jul 2021 11:59:28 -0700

some more 64bit instrs

Diffstat:
Msrc/typedefs.h | 6++++--
Msrc/wasm.c | 44+++++++++++++++++++++++++++++++++++++++++++-
Msrc/wasm.h | 1+
3 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/src/typedefs.h b/src/typedefs.h @@ -2,11 +2,13 @@ #ifndef PROTOVERSE_TYPEDEFS_H #define PROTOVERSE_TYPEDEFS_H +#include <stdint.h> + typedef unsigned char u8; typedef unsigned int u32; typedef unsigned short u16; -typedef unsigned long long u64; -typedef signed long long s64; +typedef uint64_t u64; +typedef int64_t s64; #endif /* PROTOVERSE_TYPEDEFS_H */ diff --git a/src/wasm.c b/src/wasm.c @@ -237,7 +237,7 @@ static void print_val(struct val *val) { switch (val->type) { case val_i32: printf("%d", val->i32); break; - case val_i64: printf("%llu", val->i64); break; + case val_i64: printf("%lu", val->i64); break; case val_f32: printf("%f", val->f32); break; case val_f64: printf("%f", val->f64); break; @@ -2469,6 +2469,12 @@ static INLINE int interp_local_get(struct wasm_interp *interp, int index) return stack_pushval(interp, val); } +static INLINE void make_i64_val(struct val *val, int64_t v) +{ + val->type = val_i64; + val->i64 = v; +} + static INLINE void make_i32_val(struct val *val, int v) { val->type = val_i32; @@ -2534,6 +2540,14 @@ static INLINE int interp_lt(struct wasm_interp *interp, enum valtype vt, int sig return stack_pushval(interp, &c); } +static INLINE int interp_i64_const(struct wasm_interp *interp, int64_t c) +{ + struct val val; + make_i64_val(&val, c); + return cursor_pushval(&interp->stack, &val); +} + + static INLINE int interp_i32_const(struct wasm_interp *interp, int c) { struct val val; @@ -3720,6 +3734,30 @@ static INLINE int interp_i32_and(struct wasm_interp *interp) return stack_pushval(interp, &c); } +static int interp_i64_or(struct wasm_interp *interp) +{ + struct val lhs, rhs, c; + + if (unlikely(!interp_prep_binop(interp, &lhs, &rhs, &c, val_i64))) { + return interp_error(interp, "binop prep"); + } + + c.i64 = lhs.i64 | rhs.i64; + return stack_pushval(interp, &c); +} + +static int interp_i64_shl(struct wasm_interp *interp) +{ + struct val lhs, rhs, c; + + if (unlikely(!interp_prep_binop(interp, &lhs, &rhs, &c, val_i64))) { + return interp_error(interp, "binop prep"); + } + + c.i64 = lhs.i64 << rhs.i64; + return stack_pushval(interp, &c); +} + static int interp_i32_shl(struct wasm_interp *interp) { struct val lhs, rhs, c; @@ -4048,6 +4086,10 @@ static int interp_instr(struct wasm_interp *interp, struct instr *instr) case i_i32_and: return interp_i32_and(interp); case i_i32_mul: return interp_i32_mul(interp); + case i_i64_shl: return interp_i64_shl(interp); + case i_i64_or: return interp_i64_or(interp); + + case i_i64_const: return interp_i64_const(interp, instr->i64); case i_i64_extend_i32_u: return interp_extend(interp, val_i64, val_i32, 0); case i_i64_extend_i32_s: return interp_extend(interp, val_i64, val_i32, 1); diff --git a/src/wasm.h b/src/wasm.h @@ -482,6 +482,7 @@ struct instr { double fp_double; float fp_single; unsigned int integer; + int64_t i64; unsigned char memidx; enum reftype reftype; };