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

Side by Side Diff: test/unittests/wasm/switch-logic-unittest.cc

Issue 1838973002: optimized switch implementation (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 | « test/unittests/unittests.gyp ('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 2016 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 #include "test/unittests/test-utils.h"
7
8 namespace v8 {
9 namespace internal {
10 namespace wasm {
11 class SwitchLogicTest : public TestWithZone {};
12
13 void CheckNodeValues(CaseNode* node, int begin, int end) {
14 CHECK_EQ(node->begin, begin);
15 CHECK_EQ(node->end, end);
16 }
17
18 TEST_F(SwitchLogicTest, Single_Table_Test) {
19 ZoneVector<int> values(zone());
20 values.push_back(14);
21 values.push_back(12);
22 values.push_back(15);
23 values.push_back(19);
24 values.push_back(18);
25 values.push_back(16);
26 CaseNode* root = OrderCases(&values, zone());
27 CHECK_NULL(root->left);
28 CHECK_NULL(root->right);
29 CheckNodeValues(root, 12, 19);
30 }
31
32 TEST_F(SwitchLogicTest, Balanced_Tree_Test) {
33 ZoneVector<int> values(zone());
34 values.push_back(5);
35 values.push_back(1);
36 values.push_back(6);
37 values.push_back(9);
38 values.push_back(-4);
39 CaseNode* root = OrderCases(&values, zone());
40 CheckNodeValues(root, 5, 5);
41 CheckNodeValues(root->left, -4, -4);
42 CHECK_NULL(root->left->left);
43 CheckNodeValues(root->left->right, 1, 1);
44 CHECK_NULL(root->left->right->left);
45 CHECK_NULL(root->left->right->right);
46 CheckNodeValues(root->right, 6, 6);
47 CHECK_NULL(root->right->left);
48 CheckNodeValues(root->right->right, 9, 9);
49 CHECK_NULL(root->right->right->left);
50 CHECK_NULL(root->right->right->right);
51 }
52
53 TEST_F(SwitchLogicTest, Hybrid_Test) {
54 ZoneVector<int> values(zone());
55 values.push_back(1);
56 values.push_back(2);
57 values.push_back(3);
58 values.push_back(4);
59 values.push_back(7);
60 values.push_back(10);
61 values.push_back(11);
62 values.push_back(12);
63 values.push_back(13);
64 values.push_back(16);
65 CaseNode* root = OrderCases(&values, zone());
66 CheckNodeValues(root, 7, 7);
67 CheckNodeValues(root->left, 1, 4);
68 CheckNodeValues(root->right, 10, 13);
69 CheckNodeValues(root->right->right, 16, 16);
70 }
71
72 TEST_F(SwitchLogicTest, Single_Case) {
73 ZoneVector<int> values(zone());
74 values.push_back(3);
75 CaseNode* root = OrderCases(&values, zone());
76 CheckNodeValues(root, 3, 3);
77 CHECK_NULL(root->left);
78 CHECK_NULL(root->right);
79 }
80
81 TEST_F(SwitchLogicTest, Empty_Case) {
82 ZoneVector<int> values(zone());
83 CaseNode* root = OrderCases(&values, zone());
84 CHECK_NULL(root);
85 }
86
87 } // namespace wasm
88 } // namespace internal
89 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/unittests.gyp ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698