assembler_thumb2_test.cc revision ddb7df25af45d7cd19ed1138e537973735cc78a5
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "assembler_thumb2.h"
18
19#include "base/stl_util.h"
20#include "utils/assembler_test.h"
21
22namespace art {
23
24class AssemblerThumb2Test : public AssemblerTest<arm::Thumb2Assembler,
25                                                 arm::Register, arm::SRegister,
26                                                 uint32_t> {
27 protected:
28  std::string GetArchitectureString() OVERRIDE {
29    return "arm";
30  }
31
32  std::string GetAssemblerParameters() OVERRIDE {
33    return " -mthumb -mfpu=neon";
34  }
35
36  std::string GetDisassembleParameters() OVERRIDE {
37    return " -D -bbinary -marm --no-show-raw-insn";
38  }
39
40  void SetUpHelpers() OVERRIDE {
41    if (registers_.size() == 0) {
42      registers_.insert(end(registers_),
43                        {  // NOLINT(whitespace/braces)
44                          new arm::Register(arm::R0),
45                          new arm::Register(arm::R1),
46                          new arm::Register(arm::R2),
47                          new arm::Register(arm::R3),
48                          new arm::Register(arm::R4),
49                          new arm::Register(arm::R5),
50                          new arm::Register(arm::R6),
51                          new arm::Register(arm::R7),
52                          new arm::Register(arm::R8),
53                          new arm::Register(arm::R9),
54                          new arm::Register(arm::R10),
55                          new arm::Register(arm::R11),
56                          new arm::Register(arm::R12),
57                          new arm::Register(arm::R13),
58                          new arm::Register(arm::R14),
59                          new arm::Register(arm::R15)
60                        });
61    }
62  }
63
64  void TearDown() OVERRIDE {
65    AssemblerTest::TearDown();
66    STLDeleteElements(&registers_);
67  }
68
69  std::vector<arm::Register*> GetRegisters() OVERRIDE {
70    return registers_;
71  }
72
73  uint32_t CreateImmediate(int64_t imm_value) OVERRIDE {
74    return imm_value;
75  }
76
77 private:
78  std::vector<arm::Register*> registers_;
79};
80
81
82TEST_F(AssemblerThumb2Test, Toolchain) {
83  EXPECT_TRUE(CheckTools());
84}
85
86
87TEST_F(AssemblerThumb2Test, Sbfx) {
88  GetAssembler()->sbfx(arm::R0, arm::R1, 0, 1);
89  GetAssembler()->sbfx(arm::R0, arm::R1, 0, 8);
90  GetAssembler()->sbfx(arm::R0, arm::R1, 0, 16);
91  GetAssembler()->sbfx(arm::R0, arm::R1, 0, 32);
92
93  GetAssembler()->sbfx(arm::R0, arm::R1, 8, 1);
94  GetAssembler()->sbfx(arm::R0, arm::R1, 8, 8);
95  GetAssembler()->sbfx(arm::R0, arm::R1, 8, 16);
96  GetAssembler()->sbfx(arm::R0, arm::R1, 8, 24);
97
98  GetAssembler()->sbfx(arm::R0, arm::R1, 16, 1);
99  GetAssembler()->sbfx(arm::R0, arm::R1, 16, 8);
100  GetAssembler()->sbfx(arm::R0, arm::R1, 16, 16);
101
102  GetAssembler()->sbfx(arm::R0, arm::R1, 31, 1);
103
104  const char* expected =
105      "sbfx r0, r1, #0, #1\n"
106      "sbfx r0, r1, #0, #8\n"
107      "sbfx r0, r1, #0, #16\n"
108      "sbfx r0, r1, #0, #32\n"
109
110      "sbfx r0, r1, #8, #1\n"
111      "sbfx r0, r1, #8, #8\n"
112      "sbfx r0, r1, #8, #16\n"
113      "sbfx r0, r1, #8, #24\n"
114
115      "sbfx r0, r1, #16, #1\n"
116      "sbfx r0, r1, #16, #8\n"
117      "sbfx r0, r1, #16, #16\n"
118
119      "sbfx r0, r1, #31, #1\n";
120  DriverStr(expected, "sbfx");
121}
122
123TEST_F(AssemblerThumb2Test, Ubfx) {
124  GetAssembler()->ubfx(arm::R0, arm::R1, 0, 1);
125  GetAssembler()->ubfx(arm::R0, arm::R1, 0, 8);
126  GetAssembler()->ubfx(arm::R0, arm::R1, 0, 16);
127  GetAssembler()->ubfx(arm::R0, arm::R1, 0, 32);
128
129  GetAssembler()->ubfx(arm::R0, arm::R1, 8, 1);
130  GetAssembler()->ubfx(arm::R0, arm::R1, 8, 8);
131  GetAssembler()->ubfx(arm::R0, arm::R1, 8, 16);
132  GetAssembler()->ubfx(arm::R0, arm::R1, 8, 24);
133
134  GetAssembler()->ubfx(arm::R0, arm::R1, 16, 1);
135  GetAssembler()->ubfx(arm::R0, arm::R1, 16, 8);
136  GetAssembler()->ubfx(arm::R0, arm::R1, 16, 16);
137
138  GetAssembler()->ubfx(arm::R0, arm::R1, 31, 1);
139
140  const char* expected =
141      "ubfx r0, r1, #0, #1\n"
142      "ubfx r0, r1, #0, #8\n"
143      "ubfx r0, r1, #0, #16\n"
144      "ubfx r0, r1, #0, #32\n"
145
146      "ubfx r0, r1, #8, #1\n"
147      "ubfx r0, r1, #8, #8\n"
148      "ubfx r0, r1, #8, #16\n"
149      "ubfx r0, r1, #8, #24\n"
150
151      "ubfx r0, r1, #16, #1\n"
152      "ubfx r0, r1, #16, #8\n"
153      "ubfx r0, r1, #16, #16\n"
154
155      "ubfx r0, r1, #31, #1\n";
156  DriverStr(expected, "ubfx");
157}
158
159TEST_F(AssemblerThumb2Test, Vmstat) {
160  GetAssembler()->vmstat();
161
162  const char* expected = "vmrs APSR_nzcv, FPSCR\n";
163
164  DriverStr(expected, "vmrs");
165}
166
167}  // namespace art
168