Roland Levillain | 1a28fc4 | 2014-11-13 18:03:06 +0000 | [diff] [blame] | 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_arm32.h" |
| 18 | |
| 19 | #include "base/stl_util.h" |
| 20 | #include "utils/assembler_test.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | class AssemblerArm32Test : public AssemblerTest<arm::Arm32Assembler, |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 25 | arm::Register, arm::SRegister, |
Roland Levillain | 1a28fc4 | 2014-11-13 18:03:06 +0000 | [diff] [blame] | 26 | uint32_t> { |
| 27 | protected: |
| 28 | std::string GetArchitectureString() OVERRIDE { |
| 29 | return "arm"; |
| 30 | } |
| 31 | |
| 32 | std::string GetDisassembleParameters() OVERRIDE { |
| 33 | return " -D -bbinary -marm --no-show-raw-insn"; |
| 34 | } |
| 35 | |
| 36 | void SetUpHelpers() OVERRIDE { |
| 37 | if (registers_.size() == 0) { |
| 38 | registers_.insert(end(registers_), |
| 39 | { // NOLINT(whitespace/braces) |
| 40 | new arm::Register(arm::R0), |
| 41 | new arm::Register(arm::R1), |
| 42 | new arm::Register(arm::R2), |
| 43 | new arm::Register(arm::R3), |
| 44 | new arm::Register(arm::R4), |
| 45 | new arm::Register(arm::R5), |
| 46 | new arm::Register(arm::R6), |
| 47 | new arm::Register(arm::R7), |
| 48 | new arm::Register(arm::R8), |
| 49 | new arm::Register(arm::R9), |
| 50 | new arm::Register(arm::R10), |
| 51 | new arm::Register(arm::R11), |
| 52 | new arm::Register(arm::R12), |
| 53 | new arm::Register(arm::R13), |
| 54 | new arm::Register(arm::R14), |
| 55 | new arm::Register(arm::R15) |
| 56 | }); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void TearDown() OVERRIDE { |
| 61 | AssemblerTest::TearDown(); |
| 62 | STLDeleteElements(®isters_); |
| 63 | } |
| 64 | |
| 65 | std::vector<arm::Register*> GetRegisters() OVERRIDE { |
| 66 | return registers_; |
| 67 | } |
| 68 | |
| 69 | uint32_t CreateImmediate(int64_t imm_value) OVERRIDE { |
| 70 | return imm_value; |
| 71 | } |
| 72 | |
| 73 | private: |
| 74 | std::vector<arm::Register*> registers_; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | TEST_F(AssemblerArm32Test, Toolchain) { |
| 79 | EXPECT_TRUE(CheckTools()); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | TEST_F(AssemblerArm32Test, Sbfx) { |
| 84 | GetAssembler()->sbfx(arm::R0, arm::R1, 0, 1); |
| 85 | GetAssembler()->sbfx(arm::R0, arm::R1, 0, 8); |
| 86 | GetAssembler()->sbfx(arm::R0, arm::R1, 0, 16); |
| 87 | GetAssembler()->sbfx(arm::R0, arm::R1, 0, 32); |
| 88 | |
| 89 | GetAssembler()->sbfx(arm::R0, arm::R1, 8, 1); |
| 90 | GetAssembler()->sbfx(arm::R0, arm::R1, 8, 8); |
| 91 | GetAssembler()->sbfx(arm::R0, arm::R1, 8, 16); |
| 92 | GetAssembler()->sbfx(arm::R0, arm::R1, 8, 24); |
| 93 | |
| 94 | GetAssembler()->sbfx(arm::R0, arm::R1, 16, 1); |
| 95 | GetAssembler()->sbfx(arm::R0, arm::R1, 16, 8); |
| 96 | GetAssembler()->sbfx(arm::R0, arm::R1, 16, 16); |
| 97 | |
| 98 | GetAssembler()->sbfx(arm::R0, arm::R1, 31, 1); |
| 99 | |
| 100 | const char* expected = |
| 101 | "sbfx r0, r1, #0, #1\n" |
| 102 | "sbfx r0, r1, #0, #8\n" |
| 103 | "sbfx r0, r1, #0, #16\n" |
| 104 | "sbfx r0, r1, #0, #32\n" |
| 105 | |
| 106 | "sbfx r0, r1, #8, #1\n" |
| 107 | "sbfx r0, r1, #8, #8\n" |
| 108 | "sbfx r0, r1, #8, #16\n" |
| 109 | "sbfx r0, r1, #8, #24\n" |
| 110 | |
| 111 | "sbfx r0, r1, #16, #1\n" |
| 112 | "sbfx r0, r1, #16, #8\n" |
| 113 | "sbfx r0, r1, #16, #16\n" |
| 114 | |
| 115 | "sbfx r0, r1, #31, #1\n"; |
| 116 | DriverStr(expected, "sbfx"); |
| 117 | } |
| 118 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 119 | TEST_F(AssemblerArm32Test, Ubfx) { |
| 120 | GetAssembler()->ubfx(arm::R0, arm::R1, 0, 1); |
| 121 | GetAssembler()->ubfx(arm::R0, arm::R1, 0, 8); |
| 122 | GetAssembler()->ubfx(arm::R0, arm::R1, 0, 16); |
| 123 | GetAssembler()->ubfx(arm::R0, arm::R1, 0, 32); |
| 124 | |
| 125 | GetAssembler()->ubfx(arm::R0, arm::R1, 8, 1); |
| 126 | GetAssembler()->ubfx(arm::R0, arm::R1, 8, 8); |
| 127 | GetAssembler()->ubfx(arm::R0, arm::R1, 8, 16); |
| 128 | GetAssembler()->ubfx(arm::R0, arm::R1, 8, 24); |
| 129 | |
| 130 | GetAssembler()->ubfx(arm::R0, arm::R1, 16, 1); |
| 131 | GetAssembler()->ubfx(arm::R0, arm::R1, 16, 8); |
| 132 | GetAssembler()->ubfx(arm::R0, arm::R1, 16, 16); |
| 133 | |
| 134 | GetAssembler()->ubfx(arm::R0, arm::R1, 31, 1); |
| 135 | |
| 136 | const char* expected = |
| 137 | "ubfx r0, r1, #0, #1\n" |
| 138 | "ubfx r0, r1, #0, #8\n" |
| 139 | "ubfx r0, r1, #0, #16\n" |
| 140 | "ubfx r0, r1, #0, #32\n" |
| 141 | |
| 142 | "ubfx r0, r1, #8, #1\n" |
| 143 | "ubfx r0, r1, #8, #8\n" |
| 144 | "ubfx r0, r1, #8, #16\n" |
| 145 | "ubfx r0, r1, #8, #24\n" |
| 146 | |
| 147 | "ubfx r0, r1, #16, #1\n" |
| 148 | "ubfx r0, r1, #16, #8\n" |
| 149 | "ubfx r0, r1, #16, #16\n" |
| 150 | |
| 151 | "ubfx r0, r1, #31, #1\n"; |
| 152 | DriverStr(expected, "ubfx"); |
| 153 | } |
| 154 | |
Roland Levillain | 1a28fc4 | 2014-11-13 18:03:06 +0000 | [diff] [blame] | 155 | } // namespace art |