Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: src/wasm/switch-logic.cc

Issue 1664993002: Fix asm-wasm.js test. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/switch-logic.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/switch-logic.cc
diff --git a/src/wasm/switch-logic.cc b/src/wasm/switch-logic.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1b77875dc37df00456d1cc066c2ae64f325962cd
--- /dev/null
+++ b/src/wasm/switch-logic.cc
@@ -0,0 +1,58 @@
+// Copyright 2015 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/wasm/switch-logic.h"
+
+namespace v8 {
+namespace internal {
+namespace wasm {
+
+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;
+ }
+}
+
+CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
+ const int max_distance = 2;
+ const int min_size = 4;
+ 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
« no previous file with comments | « src/wasm/switch-logic.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698