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

Side by Side 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, 8 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 unified diff | Download patch
« no previous file with comments | « src/wasm/switch-logic.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/wasm/switch-logic.h"
6
7 namespace v8 {
8 namespace internal {
9 namespace wasm {
10
11 CaseNode* CreateBst(ZoneVector<CaseNode*>* nodes, size_t begin, size_t end) {
12 if (end < begin) {
13 return nullptr;
14 } else if (end == begin) {
15 return nodes->at(begin);
16 } else {
17 size_t root_index = (begin + end) / 2;
18 CaseNode* root = nodes->at(root_index);
19 if (root_index != 0) {
20 root->left_ = CreateBst(nodes, begin, root_index - 1);
21 }
22 root->right_ = CreateBst(nodes, root_index + 1, end);
23 return root;
24 }
25 }
26
27 CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
28 const int max_distance = 2;
29 const int min_size = 4;
30 std::sort(cases->begin(), cases->end());
31 ZoneVector<size_t> table_breaks(zone);
32 for (size_t i = 1; i < cases->size(); i++) {
33 if (cases->at(i) - cases->at(i - 1) > max_distance) {
34 table_breaks.push_back(i);
35 }
36 }
37 table_breaks.push_back(cases->size());
38 ZoneVector<CaseNode*> nodes(zone);
39 size_t curr_pos = 0;
40 for (size_t i = 0; i < table_breaks.size(); i++) {
41 size_t break_pos = table_breaks[i];
42 if (break_pos - curr_pos >= min_size) {
43 int begin = cases->at(curr_pos);
44 int end = cases->at(break_pos - 1);
45 nodes.push_back(new (zone) CaseNode(begin, end));
46 curr_pos = break_pos;
47 } else {
48 for (; curr_pos < break_pos; curr_pos++) {
49 nodes.push_back(new (zone)
50 CaseNode(cases->at(curr_pos), cases->at(curr_pos)));
51 }
52 }
53 }
54 return CreateBst(&nodes, 0, nodes.size() - 1);
55 }
56 } // namespace wasm
57 } // namespace internal
58 } // namespace v8
OLDNEW
« 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