Commit 0796d1da authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Clean up jump table offset computation

Instead of computing the jump table slot, and subtracting the start of
the jump table, we can just compute the offset directly. This method is
then used to compute jump table slots.

R=titzer@chromium.org

Change-Id: I634e5ee71a0d2e9d0d2db0ea373f833df91fba8e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1709419Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62849}
parent fc8e9b82
......@@ -1129,11 +1129,16 @@ WasmCode* NativeModule::Lookup(Address pc) const {
return candidate;
}
uint32_t NativeModule::GetJumpTableOffset(uint32_t func_index) const {
uint32_t slot_idx = func_index - module_->num_imported_functions;
DCHECK_GT(module_->num_declared_functions, slot_idx);
return JumpTableAssembler::JumpSlotIndexToOffset(slot_idx);
}
Address NativeModule::GetCallTargetForFunction(uint32_t func_index) const {
// Return the jump table slot for that function index.
DCHECK_NOT_NULL(jump_table_);
uint32_t slot_idx = func_index - module_->num_imported_functions;
uint32_t slot_offset = JumpTableAssembler::JumpSlotIndexToOffset(slot_idx);
uint32_t slot_offset = GetJumpTableOffset(func_index);
DCHECK_LT(slot_offset, jump_table_->instructions().size());
return jump_table_->instruction_start() + slot_offset;
}
......
......@@ -402,10 +402,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
return jump_table_ ? jump_table_->instruction_start() : kNullAddress;
}
ptrdiff_t jump_table_offset(uint32_t func_index) const {
DCHECK_GE(func_index, num_imported_functions());
return GetCallTargetForFunction(func_index) - jump_table_start();
}
uint32_t GetJumpTableOffset(uint32_t func_index) const;
bool is_jump_table_slot(Address address) const {
return jump_table_->contains(address);
......
......@@ -2180,10 +2180,10 @@ Handle<WasmExportedFunction> WasmExportedFunction::New(
int num_imported_functions = instance->module()->num_imported_functions;
int jump_table_offset = -1;
if (func_index >= num_imported_functions) {
ptrdiff_t jump_table_diff =
instance->module_object().native_module()->jump_table_offset(
uint32_t jump_table_diff =
instance->module_object().native_module()->GetJumpTableOffset(
func_index);
DCHECK(jump_table_diff >= 0 && jump_table_diff <= INT_MAX);
DCHECK_GE(kMaxInt, jump_table_diff);
jump_table_offset = static_cast<int>(jump_table_diff);
}
Handle<WasmExportedFunctionData> function_data =
......
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