[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: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52054}
This commit is contained in:
Clemens Hammacher 2018-03-20 10:31:22 +01:00 committed by Commit Bot
parent f15ea68d98
commit 48f1fc71cf
2 changed files with 36 additions and 9 deletions

View File

@ -902,18 +902,15 @@ class LiftoffCompiler {
void GetGlobal(Decoder* decoder, Value* result,
const GlobalIndexOperand<validate>& operand) {
const auto* global = &env_->module->globals[operand.index];
if (global->type != kWasmI32 && global->type != kWasmI64)
return unsupported(decoder, "non-int global");
if (!CheckSupportedType(decoder, kTypes_ilfd, global->type, "global"))
return;
LiftoffRegList pinned;
Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp();
__ LoadFromContext(addr, offsetof(WasmContext, globals_start),
kPointerSize);
LiftoffRegister value =
pinned.set(__ GetUnusedRegister(reg_class_for(global->type), pinned));
LoadType type =
global->type == kWasmI32 ? LoadType::kI32Load : LoadType::kI64Load;
if (type.size() > kPointerSize)
return unsupported(decoder, "global > kPointerSize");
LoadType type = LoadType::ForValueType(global->type);
__ Load(value, addr, no_reg, global->offset, type, pinned);
__ PushRegister(global->type, value);
}
@ -921,14 +918,14 @@ class LiftoffCompiler {
void SetGlobal(Decoder* decoder, const Value& value,
const GlobalIndexOperand<validate>& operand) {
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;
Register addr = pinned.set(__ GetUnusedRegister(kGpReg)).gp();
__ LoadFromContext(addr, offsetof(WasmContext, globals_start),
kPointerSize);
LiftoffRegister reg = pinned.set(__ PopToRegister(pinned));
StoreType type =
global->type == kWasmI32 ? StoreType::kI32Store : StoreType::kI64Store;
StoreType type = StoreType::ForValueType(global->type);
__ Store(addr, no_reg, global->offset, reg, type, pinned);
}

View File

@ -611,6 +611,21 @@ class LoadType {
constexpr ValueType value_type() const { return kValueType[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:
const LoadTypeValue val_;
@ -663,6 +678,21 @@ class StoreType {
constexpr ValueType value_type() const { return kValueType[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:
const StoreTypeValue val_;