Commit 28c83375 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Remove dead switch logic helper code.

R=clemensh@chromium.org

Change-Id: I325b10268a9ed9548fd28ecc3e5e2b0959afcdc4
Reviewed-on: https://chromium-review.googlesource.com/c/1350125Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57819}
parent 9ac65ceb
......@@ -1649,8 +1649,6 @@ v8_source_set("v8_base") {
"src/asmjs/asm-scanner.h",
"src/asmjs/asm-types.cc",
"src/asmjs/asm-types.h",
"src/asmjs/switch-logic.cc",
"src/asmjs/switch-logic.h",
"src/assembler-arch-inl.h",
"src/assembler-arch.h",
"src/assembler-inl.h",
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "src/asmjs/switch-logic.h"
namespace v8 {
namespace internal {
namespace wasm {
namespace {
CaseNode* CreateBst(ZoneVector<CaseNode*>* nodes, size_t begin, size_t end) {
if (end < begin) {
return nullptr;
} else if (end == begin) {
return nodes->at(begin);
} else {
size_t root_index = (begin + end) / 2;
CaseNode* root = nodes->at(root_index);
if (root_index != 0) {
root->left = CreateBst(nodes, begin, root_index - 1);
}
root->right = CreateBst(nodes, root_index + 1, end);
return root;
}
}
} // namespace
CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
const int max_distance = 2;
const int min_size = 4;
if (cases->empty()) {
return nullptr;
}
std::sort(cases->begin(), cases->end());
ZoneVector<size_t> table_breaks(zone);
for (size_t i = 1; i < cases->size(); ++i) {
if (cases->at(i) - cases->at(i - 1) > max_distance) {
table_breaks.push_back(i);
}
}
table_breaks.push_back(cases->size());
ZoneVector<CaseNode*> nodes(zone);
size_t curr_pos = 0;
for (size_t i = 0; i < table_breaks.size(); ++i) {
size_t break_pos = table_breaks[i];
if (break_pos - curr_pos >= min_size) {
int begin = cases->at(curr_pos);
int end = cases->at(break_pos - 1);
nodes.push_back(new (zone) CaseNode(begin, end));
curr_pos = break_pos;
} else {
for (; curr_pos < break_pos; curr_pos++) {
nodes.push_back(new (zone)
CaseNode(cases->at(curr_pos), cases->at(curr_pos)));
}
}
}
return CreateBst(&nodes, 0, nodes.size() - 1);
}
} // namespace wasm
} // namespace internal
} // namespace v8
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_ASMJS_SWITCH_LOGIC_H_
#define V8_ASMJS_SWITCH_LOGIC_H_
#include "src/globals.h"
#include "src/zone/zone-containers.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
namespace wasm {
struct CaseNode : public ZoneObject {
const int begin;
const int end;
CaseNode* left;
CaseNode* right;
CaseNode(int begin, int end) : begin(begin), end(end) {
left = nullptr;
right = nullptr;
}
};
V8_EXPORT_PRIVATE CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_ASMJS_SWITCH_LOGIC_H_
......@@ -54,7 +54,6 @@ v8_source_set("unittests_sources") {
"api/v8-object-unittest.cc",
"asmjs/asm-scanner-unittest.cc",
"asmjs/asm-types-unittest.cc",
"asmjs/switch-logic-unittest.cc",
"background-compile-task-unittest.cc",
"base/address-region-unittest.cc",
"base/atomic-utils-unittest.cc",
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/asmjs/switch-logic.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace wasm {
class SwitchLogicTest : public TestWithZone {};
void CheckNodeValues(CaseNode* node, int begin, int end) {
CHECK_EQ(node->begin, begin);
CHECK_EQ(node->end, end);
}
TEST_F(SwitchLogicTest, Single_Table_Test) {
ZoneVector<int> values(zone());
values.push_back(14);
values.push_back(12);
values.push_back(15);
values.push_back(19);
values.push_back(18);
values.push_back(16);
CaseNode* root = OrderCases(&values, zone());
CHECK_NULL(root->left);
CHECK_NULL(root->right);
CheckNodeValues(root, 12, 19);
}
TEST_F(SwitchLogicTest, Balanced_Tree_Test) {
ZoneVector<int> values(zone());
values.push_back(5);
values.push_back(1);
values.push_back(6);
values.push_back(9);
values.push_back(-4);
CaseNode* root = OrderCases(&values, zone());
CheckNodeValues(root, 5, 5);
CheckNodeValues(root->left, -4, -4);
CHECK_NULL(root->left->left);
CheckNodeValues(root->left->right, 1, 1);
CHECK_NULL(root->left->right->left);
CHECK_NULL(root->left->right->right);
CheckNodeValues(root->right, 6, 6);
CHECK_NULL(root->right->left);
CheckNodeValues(root->right->right, 9, 9);
CHECK_NULL(root->right->right->left);
CHECK_NULL(root->right->right->right);
}
TEST_F(SwitchLogicTest, Hybrid_Test) {
ZoneVector<int> values(zone());
values.push_back(1);
values.push_back(2);
values.push_back(3);
values.push_back(4);
values.push_back(7);
values.push_back(10);
values.push_back(11);
values.push_back(12);
values.push_back(13);
values.push_back(16);
CaseNode* root = OrderCases(&values, zone());
CheckNodeValues(root, 7, 7);
CheckNodeValues(root->left, 1, 4);
CheckNodeValues(root->right, 10, 13);
CheckNodeValues(root->right->right, 16, 16);
}
TEST_F(SwitchLogicTest, Single_Case) {
ZoneVector<int> values(zone());
values.push_back(3);
CaseNode* root = OrderCases(&values, zone());
CheckNodeValues(root, 3, 3);
CHECK_NULL(root->left);
CHECK_NULL(root->right);
}
TEST_F(SwitchLogicTest, Empty_Case) {
ZoneVector<int> values(zone());
CaseNode* root = OrderCases(&values, zone());
CHECK_NULL(root);
}
} // namespace wasm
} // namespace internal
} // namespace v8
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