refactor: mem instructions

master
Sean McBride 3 years ago
parent 13b123866f
commit 332b492761

@ -1,11 +1,7 @@
#include <assert.h>
#include <assert.h>
#include <math.h>
#include "wasm_module_instance.h"
extern thread_local struct wasm_module_instance current_wasm_module_instance;
INLINE uint32_t
instruction_memory_size()
{
@ -16,37 +12,37 @@ instruction_memory_size()
INLINE float
get_f32(uint32_t offset)
{
return wasm_memory_get_float(current_wasm_module_instance.memory, offset);
return wasm_memory_get_f32(current_wasm_module_instance.memory, offset);
}
INLINE double
get_f64(uint32_t offset)
{
return wasm_memory_get_double(current_wasm_module_instance.memory, offset);
return wasm_memory_get_f64(current_wasm_module_instance.memory, offset);
}
INLINE int8_t
get_i8(uint32_t offset)
{
return wasm_memory_get_int8(current_wasm_module_instance.memory, offset);
return wasm_memory_get_i8(current_wasm_module_instance.memory, offset);
}
INLINE int16_t
get_i16(uint32_t offset)
{
return wasm_memory_get_int16(current_wasm_module_instance.memory, offset);
return wasm_memory_get_i16(current_wasm_module_instance.memory, offset);
}
INLINE int32_t
get_i32(uint32_t offset)
{
return wasm_memory_get_int32(current_wasm_module_instance.memory, offset);
return wasm_memory_get_i32(current_wasm_module_instance.memory, offset);
}
INLINE int64_t
get_i64(uint32_t offset)
{
return wasm_memory_get_int64(current_wasm_module_instance.memory, offset);
return wasm_memory_get_i64(current_wasm_module_instance.memory, offset);
}
INLINE int32_t
@ -65,37 +61,37 @@ get_global_i64(uint32_t offset)
INLINE void
set_f32(uint32_t offset, float v)
{
wasm_memory_set_float(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_f32(current_wasm_module_instance.memory, offset, v);
}
INLINE void
set_f64(uint32_t offset, double v)
{
wasm_memory_set_double(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_f64(current_wasm_module_instance.memory, offset, v);
}
INLINE void
set_i8(uint32_t offset, int8_t v)
{
wasm_memory_set_int8(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_i8(current_wasm_module_instance.memory, offset, v);
}
INLINE void
set_i16(uint32_t offset, int16_t v)
{
wasm_memory_set_int16(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_i16(current_wasm_module_instance.memory, offset, v);
}
INLINE void
set_i32(uint32_t offset, int32_t v)
{
wasm_memory_set_int32(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_i32(current_wasm_module_instance.memory, offset, v);
}
INLINE void
set_i64(uint32_t offset, int64_t v)
{
wasm_memory_set_int64(current_wasm_module_instance.memory, offset, v);
wasm_memory_set_i64(current_wasm_module_instance.memory, offset, v);
}
INLINE void

@ -121,7 +121,7 @@ wasm_memory_get_char(struct wasm_memory *self, uint32_t offset)
* @return float at the offset
*/
static inline float
wasm_memory_get_float(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_f32(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(float) <= self->size);
return *(float *)&self->data[offset];
@ -133,7 +133,7 @@ wasm_memory_get_float(struct wasm_memory *self, uint32_t offset)
* @return double at the offset
*/
static inline double
wasm_memory_get_double(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_f64(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(double) <= self->size);
return *(double *)&self->data[offset];
@ -145,7 +145,7 @@ wasm_memory_get_double(struct wasm_memory *self, uint32_t offset)
* @return int8_t at the offset
*/
static inline int8_t
wasm_memory_get_int8(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_i8(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(int8_t) <= self->size);
return (int8_t)self->data[offset];
@ -157,7 +157,7 @@ wasm_memory_get_int8(struct wasm_memory *self, uint32_t offset)
* @return int16_t at the offset
*/
static inline int16_t
wasm_memory_get_int16(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_i16(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(int16_t) <= self->size);
return *(int16_t *)&self->data[offset];
@ -169,7 +169,7 @@ wasm_memory_get_int16(struct wasm_memory *self, uint32_t offset)
* @return int32_t at the offset
*/
static inline int32_t
wasm_memory_get_int32(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_i32(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(int32_t) <= self->size);
return *(int32_t *)&self->data[offset];
@ -181,7 +181,7 @@ wasm_memory_get_int32(struct wasm_memory *self, uint32_t offset)
* @return int32_t at the offset
*/
static inline int64_t
wasm_memory_get_int64(struct wasm_memory *self, uint32_t offset)
wasm_memory_get_i64(struct wasm_memory *self, uint32_t offset)
{
assert(offset + sizeof(int64_t) <= self->size);
return *(int64_t *)&self->data[offset];
@ -211,27 +211,27 @@ wasm_memory_get_string(struct wasm_memory *self, uint32_t offset, uint32_t size)
}
/**
* Write a double to WebAssembly linear memory
* Write a float to WebAssembly linear memory
* @param offset an offset into the WebAssembly linear memory
* @return double at the offset
* @return float at the offset
*/
static inline void
wasm_memory_set_double(struct wasm_memory *self, uint32_t offset, double value)
wasm_memory_set_f32(struct wasm_memory *self, uint32_t offset, float value)
{
assert(offset + sizeof(double) <= self->size);
*(double *)&self->data[offset] = value;
assert(offset + sizeof(float) <= self->size);
*(float *)&self->data[offset] = value;
}
/**
* Write a float to WebAssembly linear memory
* Write a double to WebAssembly linear memory
* @param offset an offset into the WebAssembly linear memory
* @return float at the offset
* @return double at the offset
*/
static inline void
wasm_memory_set_float(struct wasm_memory *self, uint32_t offset, float value)
wasm_memory_set_f64(struct wasm_memory *self, uint32_t offset, double value)
{
assert(offset + sizeof(float) <= self->size);
*(float *)&self->data[offset] = value;
assert(offset + sizeof(double) <= self->size);
*(double *)&self->data[offset] = value;
}
/**
@ -240,7 +240,7 @@ wasm_memory_set_float(struct wasm_memory *self, uint32_t offset, float value)
* @return int8_t at the offset
*/
static inline void
wasm_memory_set_int8(struct wasm_memory *self, uint32_t offset, int8_t value)
wasm_memory_set_i8(struct wasm_memory *self, uint32_t offset, int8_t value)
{
assert(offset + sizeof(int8_t) <= self->size);
self->data[offset] = value;
@ -252,7 +252,7 @@ wasm_memory_set_int8(struct wasm_memory *self, uint32_t offset, int8_t value)
* @return int16_t at the offset
*/
static inline void
wasm_memory_set_int16(struct wasm_memory *self, uint32_t offset, int16_t value)
wasm_memory_set_i16(struct wasm_memory *self, uint32_t offset, int16_t value)
{
assert(offset + sizeof(int16_t) <= self->size);
*(int16_t *)&self->data[offset] = value;
@ -264,7 +264,7 @@ wasm_memory_set_int16(struct wasm_memory *self, uint32_t offset, int16_t value)
* @return int32_t at the offset
*/
static inline void
wasm_memory_set_int32(struct wasm_memory *self, uint32_t offset, int32_t value)
wasm_memory_set_i32(struct wasm_memory *self, uint32_t offset, int32_t value)
{
assert(offset + sizeof(int32_t) <= self->size);
*(int32_t *)&self->data[offset] = value;
@ -276,7 +276,7 @@ wasm_memory_set_int32(struct wasm_memory *self, uint32_t offset, int32_t value)
* @return int64_t at the offset
*/
static inline void
wasm_memory_set_int64(struct wasm_memory *self, uint64_t offset, int64_t value)
wasm_memory_set_i64(struct wasm_memory *self, uint64_t offset, int64_t value)
{
assert(offset + sizeof(int64_t) <= self->size);
*(int32_t *)&self->data[offset] = value;

Loading…
Cancel
Save