Commit 7079d41a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] [cleanup] Replace if cascade by switch

Local refactoring to replace if cascade by switch. For readability and
performance.

R=ahaas@chromium.org

Change-Id: I064d51c7c8232fefcde223b086eb7b9caf44f94c
Reviewed-on: https://chromium-review.googlesource.com/485480
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44798}
parent 461e47a8
...@@ -657,66 +657,55 @@ class V8_EXPORT_PRIVATE WasmOpcodes { ...@@ -657,66 +657,55 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
} }
static ValueType ValueTypeFor(MachineType type) { static ValueType ValueTypeFor(MachineType type) {
if (type == MachineType::Int8()) { switch (type.representation()) {
return kWasmI32; case MachineRepresentation::kWord8:
} else if (type == MachineType::Uint8()) { case MachineRepresentation::kWord16:
return kWasmI32; case MachineRepresentation::kWord32:
} else if (type == MachineType::Int16()) { return kWasmI32;
return kWasmI32; case MachineRepresentation::kWord64:
} else if (type == MachineType::Uint16()) { return kWasmI64;
return kWasmI32; case MachineRepresentation::kFloat32:
} else if (type == MachineType::Int32()) { return kWasmF32;
return kWasmI32; case MachineRepresentation::kFloat64:
} else if (type == MachineType::Uint32()) { return kWasmF64;
return kWasmI32; case MachineRepresentation::kSimd128:
} else if (type == MachineType::Int64()) { return kWasmS128;
return kWasmI64; case MachineRepresentation::kSimd1x4:
} else if (type == MachineType::Uint64()) { return kWasmS1x4;
return kWasmI64; case MachineRepresentation::kSimd1x8:
} else if (type == MachineType::Float32()) { return kWasmS1x8;
return kWasmF32; case MachineRepresentation::kSimd1x16:
} else if (type == MachineType::Float64()) { return kWasmS1x16;
return kWasmF64; default:
} else if (type == MachineType::Simd128()) { UNREACHABLE();
return kWasmS128; return kWasmI32;
} else if (type == MachineType::Simd1x4()) {
return kWasmS1x4;
} else if (type == MachineType::Simd1x8()) {
return kWasmS1x8;
} else if (type == MachineType::Simd1x16()) {
return kWasmS1x16;
} else {
UNREACHABLE();
return kWasmI32;
} }
} }
// TODO(wasm): This method is only used for testing. Move to an approriate
// header.
static WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) { static WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
if (type == MachineType::Int8()) { switch (type.representation()) {
return store ? kExprI32StoreMem8 : kExprI32LoadMem8S; case MachineRepresentation::kWord8:
} else if (type == MachineType::Uint8()) { return store ? kExprI32StoreMem8
return store ? kExprI32StoreMem8 : kExprI32LoadMem8U; : type.IsSigned() ? kExprI32LoadMem8S : kExprI32LoadMem8U;
} else if (type == MachineType::Int16()) { case MachineRepresentation::kWord16:
return store ? kExprI32StoreMem16 : kExprI32LoadMem16S; return store
} else if (type == MachineType::Uint16()) { ? kExprI32StoreMem16
return store ? kExprI32StoreMem16 : kExprI32LoadMem16U; : type.IsSigned() ? kExprI32LoadMem16S : kExprI32LoadMem16U;
} else if (type == MachineType::Int32()) { case MachineRepresentation::kWord32:
return store ? kExprI32StoreMem : kExprI32LoadMem; return store ? kExprI32StoreMem : kExprI32LoadMem;
} else if (type == MachineType::Uint32()) { case MachineRepresentation::kWord64:
return store ? kExprI32StoreMem : kExprI32LoadMem; return store ? kExprI64StoreMem : kExprI64LoadMem;
} else if (type == MachineType::Int64()) { case MachineRepresentation::kFloat32:
return store ? kExprI64StoreMem : kExprI64LoadMem; return store ? kExprF32StoreMem : kExprF32LoadMem;
} else if (type == MachineType::Uint64()) { case MachineRepresentation::kFloat64:
return store ? kExprI64StoreMem : kExprI64LoadMem; return store ? kExprF64StoreMem : kExprF64LoadMem;
} else if (type == MachineType::Float32()) { case MachineRepresentation::kSimd128:
return store ? kExprF32StoreMem : kExprF32LoadMem; return store ? kExprS128StoreMem : kExprS128LoadMem;
} else if (type == MachineType::Float64()) { default:
return store ? kExprF64StoreMem : kExprF64LoadMem; UNREACHABLE();
} else if (type == MachineType::Simd128()) { return kExprNop;
return store ? kExprS128StoreMem : kExprS128LoadMem;
} else {
UNREACHABLE();
return kExprNop;
} }
} }
......
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