codegen_test.cc revision 20dfc797dc631bf8d655dcf123f46f13332d3074
1d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray/*
2d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
3d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
4d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * you may not use this file except in compliance with the License.
6d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * You may obtain a copy of the License at
7d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
8d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray *
10d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * See the License for the specific language governing permissions and
14d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray * limitations under the License.
15d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray */
16d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
17d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "builder.h"
18d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "code_generator.h"
19d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "common_compiler_test.h"
203ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray#include "dex_file.h"
21d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "dex_instruction.h"
22d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "instruction_set.h"
23d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "nodes.h"
243ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray#include "optimizing_unit_test.h"
25d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
26d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#include "gtest/gtest.h"
27d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
28d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffraynamespace art {
29d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
30787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffrayclass InternalCodeAllocator : public CodeAllocator {
31d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray public:
32787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  InternalCodeAllocator() { }
33d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
34d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  virtual uint8_t* Allocate(size_t size) {
35787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray    size_ = size;
36d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    memory_.reset(new uint8_t[size]);
37d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    return memory_.get();
38d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  }
39d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
40787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  size_t GetSize() const { return size_; }
41787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  uint8_t* GetMemory() const { return memory_.get(); }
42d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
43d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray private:
44787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  size_t size_;
45700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers  std::unique_ptr<uint8_t[]> memory_;
46d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
47787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(InternalCodeAllocator);
48d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray};
49d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
5049c105d624e4bf8e56b85caaecfeb80864bd3f59Nicolas Geoffray#if defined(__i386__) || defined(__arm__) || defined(__x86_64__)
519cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffraystatic void Run(const InternalCodeAllocator& allocator, bool has_result, int32_t expected) {
529cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  typedef int32_t (*fptr)();
539cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  CommonCompilerTest::MakeExecutable(allocator.GetMemory(), allocator.GetSize());
5420dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison  fptr f = reinterpret_cast<fptr>(allocator.GetMemory());
5520dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison#if defined(__arm__)
5620dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison  // For thumb we need the bottom bit set.
5720dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison  f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(f) + 1);
5820dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison#endif
5920dfc797dc631bf8d655dcf123f46f13332d3074Dave Allison  int32_t result = f();
609cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  if (has_result) {
619cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray    CHECK_EQ(result, expected);
629cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  }
639cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray}
6449c105d624e4bf8e56b85caaecfeb80864bd3f59Nicolas Geoffray#endif
659cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
66bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffraystatic void TestCode(const uint16_t* data, bool has_result = false, int32_t expected = 0) {
67d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  ArenaPool pool;
68d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  ArenaAllocator arena(&pool);
69d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  HGraphBuilder builder(&arena);
703ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const DexFile::CodeItem* item = reinterpret_cast<const DexFile::CodeItem*>(data);
713ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  HGraph* graph = builder.BuildGraph(*item);
72d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray  ASSERT_NE(graph, nullptr);
73787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  InternalCodeAllocator allocator;
749cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
75787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  CodeGenerator* codegen = CodeGenerator::Create(&arena, graph, kX86);
7686dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray  codegen->CompileBaseline(&allocator);
77d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#if defined(__i386__)
789cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  Run(allocator, has_result, expected);
79d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#endif
809cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
81787c3076635cf117eb646c5a89a9014b2072fb44Nicolas Geoffray  codegen = CodeGenerator::Create(&arena, graph, kArm);
8286dbb9a12119273039ce272b41c809fa548b37b6Nicolas Geoffray  codegen->CompileBaseline(&allocator);
83d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray#if defined(__arm__)
849cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  Run(allocator, has_result, expected);
859cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#endif
869cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray
879cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  codegen = CodeGenerator::Create(&arena, graph, kX86_64);
889cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  codegen->CompileBaseline(&allocator);
899cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray#if defined(__x86_64__)
909cf35523764d829ae0470dae2d5dd99be469c841Nicolas Geoffray  Run(allocator, has_result, expected);
9139d57e2de8ec7420f2395a28cd7bd51e658d57b8Nicolas Geoffray#endif
92d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
93d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
94d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas GeoffrayTEST(CodegenTest, ReturnVoid) {
953ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(Instruction::RETURN_VOID);
963ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data);
97d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
98d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
99bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, CFG1) {
1003ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
101d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO | 0x100,
1023ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::RETURN_VOID);
103d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1043ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data);
105d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
106d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
107bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, CFG2) {
1083ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
109d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO | 0x100,
110d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO | 0x100,
1113ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::RETURN_VOID);
112d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1133ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data);
114d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
115d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
116bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, CFG3) {
1173ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM(
118d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO | 0x200,
119d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::RETURN_VOID,
1203ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::GOTO | 0xFF00);
121d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1223ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data1);
123d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1243ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM(
125d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO_16, 3,
126d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::RETURN_VOID,
1273ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::GOTO_16, 0xFFFF);
128d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1293ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data2);
130d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1313ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data3[] = ZERO_REGISTER_CODE_ITEM(
132d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO_32, 4, 0,
133d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::RETURN_VOID,
1343ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::GOTO_32, 0xFFFF, 0xFFFF);
135d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1363ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data3);
137d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
138d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
139bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, CFG4) {
1403ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  const uint16_t data[] = ZERO_REGISTER_CODE_ITEM(
141d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::RETURN_VOID,
142d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray    Instruction::GOTO | 0x100,
1433ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray    Instruction::GOTO | 0xFE00);
144d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
1453ff386aafefd5282bb76c8a50506a70a4321e698Nicolas Geoffray  TestCode(data);
146d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}
147d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray
148bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, CFG5) {
149bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
150bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
151bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::IF_EQ, 3,
152bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::GOTO | 0x100,
153bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN_VOID);
154bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
155bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data);
156bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
157bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
158bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, IntConstant) {
159bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
160bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
161bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN_VOID);
162bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
163bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data);
164bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
165bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
166bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, Return1) {
167bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
168bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
169bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 0);
170bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
171bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data, true, 0);
172bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
173bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
174bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, Return2) {
175bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
176bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
177bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 1 << 8,
178bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 1 << 8);
179bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
180bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data, true, 0);
181bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
182bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
183bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, Return3) {
184bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
185bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
186bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 1 << 8 | 1 << 12,
187bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 1 << 8);
188bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
189bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data, true, 1);
190bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
191bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
192bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, ReturnIf1) {
193bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
194bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
195bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 1 << 8 | 1 << 12,
196bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::IF_EQ, 3,
197bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 0 << 8,
198bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 1 << 8);
199bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
200bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data, true, 1);
201bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
202bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
203bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas GeoffrayTEST(CodegenTest, ReturnIf2) {
204bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
205bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 0 | 0,
206bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::CONST_4 | 1 << 8 | 1 << 12,
207bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::IF_EQ | 0 << 4 | 1 << 8, 3,
208bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 0 << 8,
209bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray    Instruction::RETURN | 1 << 8);
210bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
211bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray  TestCode(data, true, 0);
212bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray}
213bab4ed7057799a4fadc6283108ab56f389d117d4Nicolas Geoffray
214d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas GeoffrayTEST(CodegenTest, ReturnAdd1) {
215d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
216d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 3 << 12 | 0,
217d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 4 << 12 | 1 << 8,
218d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::ADD_INT, 1 << 8 | 0,
219d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::RETURN);
220d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
221d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  TestCode(data, true, 7);
222d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray}
223d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
224d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas GeoffrayTEST(CodegenTest, ReturnAdd2) {
225d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  const uint16_t data[] = TWO_REGISTERS_CODE_ITEM(
226d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 3 << 12 | 0,
227d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 4 << 12 | 1 << 8,
228d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::ADD_INT_2ADDR | 1 << 12,
229d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::RETURN);
230d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
231d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  TestCode(data, true, 7);
232d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray}
233d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
234d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas GeoffrayTEST(CodegenTest, ReturnAdd3) {
235d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
236d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 4 << 12 | 0 << 8,
237d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::ADD_INT_LIT8, 3 << 8 | 0,
238d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::RETURN);
239d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
240d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  TestCode(data, true, 7);
241d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray}
242d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
243d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas GeoffrayTEST(CodegenTest, ReturnAdd4) {
244d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  const uint16_t data[] = ONE_REGISTER_CODE_ITEM(
245d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::CONST_4 | 4 << 12 | 0 << 8,
246d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::ADD_INT_LIT16, 3,
247d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray    Instruction::RETURN);
248d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
249d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray  TestCode(data, true, 7);
250d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray}
251d8ee737fdbf380c5bb90c9270c8d1087ac23e76cNicolas Geoffray
252d4dd255db1d110ceb5551f6d95ff31fb57420994Nicolas Geoffray}  // namespace art
253