Commit 48f1fc71 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[Liftoff] Support globals of all standard types

This adds support to get or set globals of all the standard types (i32,
i64, f32, f64).

R=titzer@chromium.org

Bug: v8:6600
Change-Id: Ie8d14d3d964e2abe3f19945a0e80b0e8462e9485
Reviewed-on: https://chromium-review.googlesource.com/969262
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52054}
parent f15ea68d
...@@ -902,18 +902,15 @@ class LiftoffCompiler { ...@@ -902,18 +902,15 @@ class LiftoffCompiler {
void GetGlobal(Decoder* decoder, Value* result, void GetGlobal(Decoder* decoder, Value* result,
const GlobalIndexOperand<validate>& operand) { const GlobalIndexOperand<validate>& operand) {
const auto* global = &env_->module->globals[operand.index]; const auto* global = &env_->module->globals[operand.index];
if (global->type != kWasmI32 && global->type != kWasmI64) if (!CheckSupportedType(decoder, kTypes_ilfd, global->type, "global"))
return unsupported(decoder, "non-int global"); return;
LiftoffRegList pinned; LiftoffRegList pinned;
Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp(); Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp();
__ LoadFromContext(addr, offsetof(WasmContext, globals_start), __ LoadFromContext(addr, offsetof(WasmContext, globals_start),
kPointerSize); kPointerSize);
LiftoffRegister value = LiftoffRegister value =
pinned.set(__ GetUnusedRegister(reg_class_for(global->type), pinned)); pinned.set(__ GetUnusedRegister(reg_class_for(global->type), pinned));
LoadType type = LoadType type = LoadType::ForValueType(global->type);
global->type == kWasmI32 ? LoadType::kI32Load : LoadType::kI64Load;
if (type.size() > kPointerSize)
return unsupported(decoder, "global > kPointerSize");
__ Load(value, addr, no_reg, global->offset, type, pinned); __ Load(value, addr, no_reg, global->offset, type, pinned);
__ PushRegister(global->type, value); __ PushRegister(global->type, value);
} }
...@@ -921,14 +918,14 @@ class LiftoffCompiler { ...@@ -921,14 +918,14 @@ class LiftoffCompiler {
void SetGlobal(Decoder* decoder, const Value& value, void SetGlobal(Decoder* decoder, const Value& value,
const GlobalIndexOperand<validate>& operand) { const GlobalIndexOperand<validate>& operand) {
auto* global = &env_->module->globals[operand.index]; auto* global = &env_->module->globals[operand.index];
if (global->type != kWasmI32) return unsupported(decoder, "non-i32 global"); if (!CheckSupportedType(decoder, kTypes_ilfd, global->type, "global"))
return;
LiftoffRegList pinned; LiftoffRegList pinned;
Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp(); Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp();
__ LoadFromContext(addr, offsetof(WasmContext, globals_start), __ LoadFromContext(addr, offsetof(WasmContext, globals_start),
kPointerSize); kPointerSize);
LiftoffRegister reg = pinned.set(__ PopToRegister(pinned)); LiftoffRegister reg = pinned.set(__ PopToRegister(pinned));
StoreType type = StoreType type = StoreType::ForValueType(global->type);
global->type == kWasmI32 ? StoreType::kI32Store : StoreType::kI64Store;
__ Store(addr, no_reg, global->offset, reg, type, pinned); __ Store(addr, no_reg, global->offset, reg, type, pinned);
} }
......
...@@ -611,6 +611,21 @@ class LoadType { ...@@ -611,6 +611,21 @@ class LoadType {
constexpr ValueType value_type() const { return kValueType[val_]; } constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr MachineType mem_type() const { return kMemType[val_]; } constexpr MachineType mem_type() const { return kMemType[val_]; }
static LoadType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Load;
case kWasmI64:
return kI64Load;
case kWasmF32:
return kF32Load;
case kWasmF64:
return kF64Load;
default:
UNREACHABLE();
}
}
private: private:
const LoadTypeValue val_; const LoadTypeValue val_;
...@@ -663,6 +678,21 @@ class StoreType { ...@@ -663,6 +678,21 @@ class StoreType {
constexpr ValueType value_type() const { return kValueType[val_]; } constexpr ValueType value_type() const { return kValueType[val_]; }
constexpr ValueType mem_rep() const { return kMemRep[val_]; } constexpr ValueType mem_rep() const { return kMemRep[val_]; }
static StoreType ForValueType(ValueType type) {
switch (type) {
case kWasmI32:
return kI32Store;
case kWasmI64:
return kI64Store;
case kWasmF32:
return kF32Store;
case kWasmF64:
return kF64Store;
default:
UNREACHABLE();
}
}
private: private:
const StoreTypeValue val_; const StoreTypeValue val_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment