Skip to content

Commit

Permalink
Use value size instead of stack allocated size for global get, set
Browse files Browse the repository at this point in the history
Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 committed Aug 29, 2023
1 parent 4096f54 commit 78a7a46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/interpreter/ByteCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,7 @@ class GlobalGet32 : public ByteCode {
void dump(size_t pos)
{
printf("global.get32 ");
DUMP_BYTECODE_OFFSET(dstOffset);
printf("index: %" PRId32,
m_index);
}
Expand All @@ -2063,6 +2064,7 @@ class GlobalGet64 : public ByteCode {
void dump(size_t pos)
{
printf("global.get64 ");
DUMP_BYTECODE_OFFSET(dstOffset);
printf("index: %" PRId32,
m_index);
}
Expand All @@ -2089,6 +2091,7 @@ class GlobalGet128 : public ByteCode {
void dump(size_t pos)
{
printf("global.get128 ");
DUMP_BYTECODE_OFFSET(dstOffset);
printf("index: %" PRId32,
m_index);
}
Expand All @@ -2115,6 +2118,7 @@ class GlobalSet32 : public ByteCode {
void dump(size_t pos)
{
printf("global.set32 ");
DUMP_BYTECODE_OFFSET(srcOffset);
printf("index: %" PRId32,
m_index);
}
Expand All @@ -2141,6 +2145,7 @@ class GlobalSet64 : public ByteCode {
void dump(size_t pos)
{
printf("global.set64 ");
DUMP_BYTECODE_OFFSET(srcOffset);
printf("index: %" PRId32,
m_index);
}
Expand All @@ -2167,6 +2172,7 @@ class GlobalSet128 : public ByteCode {
void dump(size_t pos)
{
printf("global.set128 ");
DUMP_BYTECODE_OFFSET(srcOffset);
printf("index: %" PRId32,
m_index);
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
virtual void OnGlobalGetExpr(Index index) override
{
auto valueType = m_result.m_globalTypes[index]->type();
auto sz = Walrus::valueStackAllocatedSize(valueType);
auto sz = Walrus::valueSize(valueType);
auto stackPos = computeExprResultPosition(valueType);
if (sz == 4) {
pushByteCode(Walrus::GlobalGet32(stackPos, index), WASMOpcode::GlobalGetOpcode);
Expand All @@ -1273,7 +1273,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
auto stackPos = peekVMStack();

ASSERT(peekVMStackValueType() == valueType);
auto sz = Walrus::valueStackAllocatedSize(valueType);
auto sz = Walrus::valueSize(valueType);
if (sz == 4) {
pushByteCode(Walrus::GlobalSet32(stackPos, index), WASMOpcode::GlobalSetOpcode);
} else if (sz == 8) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ inline size_t valueFunctionCopyCount(Value::Type type)
template <const size_t size>
inline void Value::readFromStack(uint8_t* ptr)
{
ASSERT(valueStackAllocatedSize(m_type) == size);
ASSERT(valueSize(m_type) == size);
if (size == 4) {
m_i32 = *reinterpret_cast<int32_t*>(ptr);
} else if (size == 8) {
Expand Down

0 comments on commit 78a7a46

Please sign in to comment.