Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [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 | #ifndef ART_COMPILER_UTILS_ASSEMBLER_TEST_H_ |
| 18 | #define ART_COMPILER_UTILS_ASSEMBLER_TEST_H_ |
| 19 | |
| 20 | #include "assembler.h" |
| 21 | |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 22 | #include "assembler_test_base.h" |
Andreas Gampe | b40c6a7 | 2014-05-02 14:25:12 -0700 | [diff] [blame] | 23 | #include "common_runtime_test.h" // For ScratchFile |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 24 | |
| 25 | #include <cstdio> |
| 26 | #include <cstdlib> |
| 27 | #include <fstream> |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 28 | #include <iterator> |
| 29 | #include <sys/stat.h> |
| 30 | |
| 31 | namespace art { |
| 32 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 33 | // Helper for a constexpr string length. |
| 34 | constexpr size_t ConstexprStrLen(char const* str, size_t count = 0) { |
| 35 | return ('\0' == str[0]) ? count : ConstexprStrLen(str+1, count+1); |
| 36 | } |
| 37 | |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 38 | enum class RegisterView { // private |
| 39 | kUsePrimaryName, |
Chao-ying Fu | d23840d | 2015-04-07 16:03:04 -0700 | [diff] [blame] | 40 | kUseSecondaryName, |
| 41 | kUseTertiaryName, |
| 42 | kUseQuaternaryName, |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 45 | // For use in the template as the default type to get a nonvector registers version. |
| 46 | struct NoVectorRegs {}; |
| 47 | |
| 48 | template<typename Ass, typename Reg, typename FPReg, typename Imm, typename VecReg = NoVectorRegs> |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 49 | class AssemblerTest : public testing::Test { |
| 50 | public: |
| 51 | Ass* GetAssembler() { |
| 52 | return assembler_.get(); |
| 53 | } |
| 54 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 55 | typedef std::string (*TestFn)(AssemblerTest* assembler_test, Ass* assembler); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 56 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 57 | void DriverFn(TestFn f, const std::string& test_name) { |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 58 | DriverWrapper(f(this, assembler_.get()), test_name); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // This driver assumes the assembler has already been called. |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 62 | void DriverStr(const std::string& assembly_string, const std::string& test_name) { |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 63 | DriverWrapper(assembly_string, test_name); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 66 | std::string RepeatR(void (Ass::*f)(Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 67 | return RepeatTemplatedRegister<Reg>(f, |
| 68 | GetRegisters(), |
| 69 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 70 | fmt); |
| 71 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 72 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 73 | std::string Repeatr(void (Ass::*f)(Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 74 | return RepeatTemplatedRegister<Reg>(f, |
| 75 | GetRegisters(), |
| 76 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 77 | fmt); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 80 | std::string RepeatRR(void (Ass::*f)(Reg, Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 81 | return RepeatTemplatedRegisters<Reg, Reg>(f, |
| 82 | GetRegisters(), |
| 83 | GetRegisters(), |
| 84 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 85 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 86 | fmt); |
| 87 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 88 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 89 | std::string RepeatRRNoDupes(void (Ass::*f)(Reg, Reg), const std::string& fmt) { |
Chris Larsen | 5141763 | 2015-10-02 13:24:25 -0700 | [diff] [blame] | 90 | return RepeatTemplatedRegistersNoDupes<Reg, Reg>(f, |
| 91 | GetRegisters(), |
| 92 | GetRegisters(), |
| 93 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 94 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 95 | fmt); |
| 96 | } |
| 97 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 98 | std::string Repeatrr(void (Ass::*f)(Reg, Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 99 | return RepeatTemplatedRegisters<Reg, Reg>(f, |
| 100 | GetRegisters(), |
| 101 | GetRegisters(), |
| 102 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 103 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 104 | fmt); |
| 105 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 106 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 107 | std::string RepeatRRR(void (Ass::*f)(Reg, Reg, Reg), const std::string& fmt) { |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 108 | return RepeatTemplatedRegisters<Reg, Reg, Reg>(f, |
| 109 | GetRegisters(), |
| 110 | GetRegisters(), |
| 111 | GetRegisters(), |
| 112 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 113 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 114 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 115 | fmt); |
| 116 | } |
| 117 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 118 | std::string Repeatrb(void (Ass::*f)(Reg, Reg), const std::string& fmt) { |
Chao-ying Fu | d23840d | 2015-04-07 16:03:04 -0700 | [diff] [blame] | 119 | return RepeatTemplatedRegisters<Reg, Reg>(f, |
| 120 | GetRegisters(), |
| 121 | GetRegisters(), |
| 122 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 123 | &AssemblerTest::GetRegName<RegisterView::kUseQuaternaryName>, |
| 124 | fmt); |
| 125 | } |
| 126 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 127 | std::string RepeatRr(void (Ass::*f)(Reg, Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 128 | return RepeatTemplatedRegisters<Reg, Reg>(f, |
| 129 | GetRegisters(), |
| 130 | GetRegisters(), |
| 131 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 132 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 133 | fmt); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 136 | std::string RepeatRI(void (Ass::*f)(Reg, const Imm&), size_t imm_bytes, const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 137 | return RepeatRegisterImm<RegisterView::kUsePrimaryName>(f, imm_bytes, fmt); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 140 | std::string Repeatri(void (Ass::*f)(Reg, const Imm&), size_t imm_bytes, const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 141 | return RepeatRegisterImm<RegisterView::kUseSecondaryName>(f, imm_bytes, fmt); |
| 142 | } |
| 143 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 144 | template <typename Reg1, typename Reg2, typename ImmType> |
| 145 | std::string RepeatTemplatedRegistersImmBits(void (Ass::*f)(Reg1, Reg2, ImmType), |
| 146 | int imm_bits, |
| 147 | const std::vector<Reg1*> reg1_registers, |
| 148 | const std::vector<Reg2*> reg2_registers, |
| 149 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 150 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 151 | const std::string& fmt, |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 152 | int bias = 0, |
| 153 | int multiplier = 1) { |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 154 | std::string str; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 155 | std::vector<int64_t> imms = CreateImmediateValuesBits(abs(imm_bits), (imm_bits > 0)); |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 156 | |
| 157 | for (auto reg1 : reg1_registers) { |
| 158 | for (auto reg2 : reg2_registers) { |
| 159 | for (int64_t imm : imms) { |
| 160 | ImmType new_imm = CreateImmediate(imm); |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 161 | (assembler_.get()->*f)(*reg1, *reg2, new_imm * multiplier + bias); |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 162 | std::string base = fmt; |
| 163 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 164 | std::string reg1_string = (this->*GetName1)(*reg1); |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 165 | size_t reg1_index; |
| 166 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 167 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 168 | } |
| 169 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 170 | std::string reg2_string = (this->*GetName2)(*reg2); |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 171 | size_t reg2_index; |
| 172 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 173 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 174 | } |
| 175 | |
| 176 | size_t imm_index = base.find(IMM_TOKEN); |
| 177 | if (imm_index != std::string::npos) { |
| 178 | std::ostringstream sreg; |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 179 | sreg << imm * multiplier + bias; |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 180 | std::string imm_string = sreg.str(); |
| 181 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 182 | } |
| 183 | |
| 184 | if (str.size() > 0) { |
| 185 | str += "\n"; |
| 186 | } |
| 187 | str += base; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | // Add a newline at the end. |
| 192 | str += "\n"; |
| 193 | return str; |
| 194 | } |
| 195 | |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 196 | template <typename Reg1, typename Reg2, typename Reg3, typename ImmType> |
| 197 | std::string RepeatTemplatedRegistersImmBits(void (Ass::*f)(Reg1, Reg2, Reg3, ImmType), |
| 198 | int imm_bits, |
| 199 | const std::vector<Reg1*> reg1_registers, |
| 200 | const std::vector<Reg2*> reg2_registers, |
| 201 | const std::vector<Reg3*> reg3_registers, |
| 202 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 203 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
| 204 | std::string (AssemblerTest::*GetName3)(const Reg3&), |
| 205 | std::string fmt, |
| 206 | int bias) { |
| 207 | std::string str; |
| 208 | std::vector<int64_t> imms = CreateImmediateValuesBits(abs(imm_bits), (imm_bits > 0)); |
| 209 | |
| 210 | for (auto reg1 : reg1_registers) { |
| 211 | for (auto reg2 : reg2_registers) { |
| 212 | for (auto reg3 : reg3_registers) { |
| 213 | for (int64_t imm : imms) { |
| 214 | ImmType new_imm = CreateImmediate(imm); |
| 215 | (assembler_.get()->*f)(*reg1, *reg2, *reg3, new_imm + bias); |
| 216 | std::string base = fmt; |
| 217 | |
| 218 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 219 | size_t reg1_index; |
| 220 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 221 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 222 | } |
| 223 | |
| 224 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 225 | size_t reg2_index; |
| 226 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 227 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 228 | } |
| 229 | |
| 230 | std::string reg3_string = (this->*GetName3)(*reg3); |
| 231 | size_t reg3_index; |
| 232 | while ((reg3_index = base.find(REG3_TOKEN)) != std::string::npos) { |
| 233 | base.replace(reg3_index, ConstexprStrLen(REG3_TOKEN), reg3_string); |
| 234 | } |
| 235 | |
| 236 | size_t imm_index = base.find(IMM_TOKEN); |
| 237 | if (imm_index != std::string::npos) { |
| 238 | std::ostringstream sreg; |
| 239 | sreg << imm + bias; |
| 240 | std::string imm_string = sreg.str(); |
| 241 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 242 | } |
| 243 | |
| 244 | if (str.size() > 0) { |
| 245 | str += "\n"; |
| 246 | } |
| 247 | str += base; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | // Add a newline at the end. |
| 253 | str += "\n"; |
| 254 | return str; |
| 255 | } |
| 256 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 257 | template <typename ImmType, typename Reg1, typename Reg2> |
| 258 | std::string RepeatTemplatedImmBitsRegisters(void (Ass::*f)(ImmType, Reg1, Reg2), |
| 259 | const std::vector<Reg1*> reg1_registers, |
| 260 | const std::vector<Reg2*> reg2_registers, |
| 261 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 262 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
| 263 | int imm_bits, |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 264 | const std::string& fmt) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 265 | std::vector<int64_t> imms = CreateImmediateValuesBits(abs(imm_bits), (imm_bits > 0)); |
| 266 | |
| 267 | WarnOnCombinations(reg1_registers.size() * reg2_registers.size() * imms.size()); |
| 268 | |
| 269 | std::string str; |
| 270 | for (auto reg1 : reg1_registers) { |
| 271 | for (auto reg2 : reg2_registers) { |
| 272 | for (int64_t imm : imms) { |
| 273 | ImmType new_imm = CreateImmediate(imm); |
| 274 | (assembler_.get()->*f)(new_imm, *reg1, *reg2); |
| 275 | std::string base = fmt; |
| 276 | |
| 277 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 278 | size_t reg1_index; |
| 279 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 280 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 281 | } |
| 282 | |
| 283 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 284 | size_t reg2_index; |
| 285 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 286 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 287 | } |
| 288 | |
| 289 | size_t imm_index = base.find(IMM_TOKEN); |
| 290 | if (imm_index != std::string::npos) { |
| 291 | std::ostringstream sreg; |
| 292 | sreg << imm; |
| 293 | std::string imm_string = sreg.str(); |
| 294 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 295 | } |
| 296 | |
| 297 | if (str.size() > 0) { |
| 298 | str += "\n"; |
| 299 | } |
| 300 | str += base; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | // Add a newline at the end. |
| 305 | str += "\n"; |
| 306 | return str; |
| 307 | } |
| 308 | |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 309 | template <typename RegType, typename ImmType> |
| 310 | std::string RepeatTemplatedRegisterImmBits(void (Ass::*f)(RegType, ImmType), |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 311 | int imm_bits, |
| 312 | const std::vector<Reg*> registers, |
| 313 | std::string (AssemblerTest::*GetName)(const RegType&), |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 314 | const std::string& fmt, |
| 315 | int bias) { |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 316 | std::string str; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 317 | std::vector<int64_t> imms = CreateImmediateValuesBits(abs(imm_bits), (imm_bits > 0)); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 318 | |
| 319 | for (auto reg : registers) { |
| 320 | for (int64_t imm : imms) { |
| 321 | ImmType new_imm = CreateImmediate(imm); |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 322 | (assembler_.get()->*f)(*reg, new_imm + bias); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 323 | std::string base = fmt; |
| 324 | |
| 325 | std::string reg_string = (this->*GetName)(*reg); |
| 326 | size_t reg_index; |
| 327 | while ((reg_index = base.find(REG_TOKEN)) != std::string::npos) { |
| 328 | base.replace(reg_index, ConstexprStrLen(REG_TOKEN), reg_string); |
| 329 | } |
| 330 | |
| 331 | size_t imm_index = base.find(IMM_TOKEN); |
| 332 | if (imm_index != std::string::npos) { |
| 333 | std::ostringstream sreg; |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 334 | sreg << imm + bias; |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 335 | std::string imm_string = sreg.str(); |
| 336 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 337 | } |
| 338 | |
| 339 | if (str.size() > 0) { |
| 340 | str += "\n"; |
| 341 | } |
| 342 | str += base; |
| 343 | } |
| 344 | } |
| 345 | // Add a newline at the end. |
| 346 | str += "\n"; |
| 347 | return str; |
| 348 | } |
| 349 | |
| 350 | template <typename ImmType> |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 351 | std::string RepeatRRIb(void (Ass::*f)(Reg, Reg, ImmType), |
| 352 | int imm_bits, |
| 353 | const std::string& fmt, |
| 354 | int bias = 0) { |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 355 | return RepeatTemplatedRegistersImmBits<Reg, Reg, ImmType>(f, |
| 356 | imm_bits, |
| 357 | GetRegisters(), |
| 358 | GetRegisters(), |
| 359 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 360 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 361 | fmt, |
| 362 | bias); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | template <typename ImmType> |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 366 | std::string RepeatRRRIb(void (Ass::*f)(Reg, Reg, Reg, ImmType), |
| 367 | int imm_bits, |
| 368 | const std::string& fmt, |
| 369 | int bias = 0) { |
| 370 | return RepeatTemplatedRegistersImmBits<Reg, Reg, Reg, ImmType>(f, |
| 371 | imm_bits, |
| 372 | GetRegisters(), |
| 373 | GetRegisters(), |
| 374 | GetRegisters(), |
| 375 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 376 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 377 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 378 | fmt, |
| 379 | bias); |
| 380 | } |
| 381 | |
| 382 | template <typename ImmType> |
| 383 | std::string RepeatRIb(void (Ass::*f)(Reg, ImmType), int imm_bits, std::string fmt, int bias = 0) { |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 384 | return RepeatTemplatedRegisterImmBits<Reg, ImmType>(f, |
| 385 | imm_bits, |
| 386 | GetRegisters(), |
| 387 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 388 | fmt, |
| 389 | bias); |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | template <typename ImmType> |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 393 | std::string RepeatFRIb(void (Ass::*f)(FPReg, Reg, ImmType), |
| 394 | int imm_bits, |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 395 | const std::string& fmt, |
| 396 | int bias = 0) { |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 397 | return RepeatTemplatedRegistersImmBits<FPReg, Reg, ImmType>(f, |
| 398 | imm_bits, |
| 399 | GetFPRegisters(), |
| 400 | GetRegisters(), |
| 401 | &AssemblerTest::GetFPRegName, |
| 402 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
Chris Larsen | e366059 | 2016-11-09 11:13:42 -0800 | [diff] [blame] | 403 | fmt, |
| 404 | bias); |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 407 | std::string RepeatFF(void (Ass::*f)(FPReg, FPReg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 408 | return RepeatTemplatedRegisters<FPReg, FPReg>(f, |
| 409 | GetFPRegisters(), |
| 410 | GetFPRegisters(), |
| 411 | &AssemblerTest::GetFPRegName, |
| 412 | &AssemblerTest::GetFPRegName, |
| 413 | fmt); |
| 414 | } |
| 415 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 416 | std::string RepeatFFF(void (Ass::*f)(FPReg, FPReg, FPReg), const std::string& fmt) { |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 417 | return RepeatTemplatedRegisters<FPReg, FPReg, FPReg>(f, |
| 418 | GetFPRegisters(), |
| 419 | GetFPRegisters(), |
| 420 | GetFPRegisters(), |
| 421 | &AssemblerTest::GetFPRegName, |
| 422 | &AssemblerTest::GetFPRegName, |
| 423 | &AssemblerTest::GetFPRegName, |
| 424 | fmt); |
| 425 | } |
| 426 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 427 | std::string RepeatFFR(void (Ass::*f)(FPReg, FPReg, Reg), const std::string& fmt) { |
Alexey Frunze | 674b9ee | 2016-09-20 14:54:15 -0700 | [diff] [blame] | 428 | return RepeatTemplatedRegisters<FPReg, FPReg, Reg>( |
| 429 | f, |
| 430 | GetFPRegisters(), |
| 431 | GetFPRegisters(), |
| 432 | GetRegisters(), |
| 433 | &AssemblerTest::GetFPRegName, |
| 434 | &AssemblerTest::GetFPRegName, |
| 435 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 436 | fmt); |
| 437 | } |
| 438 | |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 439 | std::string RepeatFFI(void (Ass::*f)(FPReg, FPReg, const Imm&), |
| 440 | size_t imm_bytes, |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 441 | const std::string& fmt) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 442 | return RepeatTemplatedRegistersImm<FPReg, FPReg>(f, |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 443 | GetFPRegisters(), |
| 444 | GetFPRegisters(), |
| 445 | &AssemblerTest::GetFPRegName, |
| 446 | &AssemblerTest::GetFPRegName, |
| 447 | imm_bytes, |
| 448 | fmt); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 449 | } |
| 450 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 451 | template <typename ImmType> |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 452 | std::string RepeatFFIb(void (Ass::*f)(FPReg, FPReg, ImmType), |
| 453 | int imm_bits, |
| 454 | const std::string& fmt) { |
Alexey Frunze | a8aaf5a | 2016-06-27 14:48:20 -0700 | [diff] [blame] | 455 | return RepeatTemplatedRegistersImmBits<FPReg, FPReg, ImmType>(f, |
| 456 | imm_bits, |
| 457 | GetFPRegisters(), |
| 458 | GetFPRegisters(), |
| 459 | &AssemblerTest::GetFPRegName, |
| 460 | &AssemblerTest::GetFPRegName, |
| 461 | fmt); |
| 462 | } |
| 463 | |
| 464 | template <typename ImmType> |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 465 | std::string RepeatIbFF(void (Ass::*f)(ImmType, FPReg, FPReg), |
| 466 | int imm_bits, |
| 467 | const std::string& fmt) { |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 468 | return RepeatTemplatedImmBitsRegisters<ImmType, FPReg, FPReg>(f, |
| 469 | GetFPRegisters(), |
| 470 | GetFPRegisters(), |
| 471 | &AssemblerTest::GetFPRegName, |
| 472 | &AssemblerTest::GetFPRegName, |
| 473 | imm_bits, |
| 474 | fmt); |
| 475 | } |
| 476 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 477 | std::string RepeatFR(void (Ass::*f)(FPReg, Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 478 | return RepeatTemplatedRegisters<FPReg, Reg>(f, |
| 479 | GetFPRegisters(), |
| 480 | GetRegisters(), |
| 481 | &AssemblerTest::GetFPRegName, |
| 482 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 483 | fmt); |
| 484 | } |
| 485 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 486 | std::string RepeatFr(void (Ass::*f)(FPReg, Reg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 487 | return RepeatTemplatedRegisters<FPReg, Reg>(f, |
| 488 | GetFPRegisters(), |
| 489 | GetRegisters(), |
| 490 | &AssemblerTest::GetFPRegName, |
| 491 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 492 | fmt); |
| 493 | } |
| 494 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 495 | std::string RepeatRF(void (Ass::*f)(Reg, FPReg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 496 | return RepeatTemplatedRegisters<Reg, FPReg>(f, |
| 497 | GetRegisters(), |
| 498 | GetFPRegisters(), |
| 499 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 500 | &AssemblerTest::GetFPRegName, |
| 501 | fmt); |
| 502 | } |
| 503 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 504 | std::string RepeatrF(void (Ass::*f)(Reg, FPReg), const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 505 | return RepeatTemplatedRegisters<Reg, FPReg>(f, |
| 506 | GetRegisters(), |
| 507 | GetFPRegisters(), |
| 508 | &AssemblerTest::GetRegName<RegisterView::kUseSecondaryName>, |
| 509 | &AssemblerTest::GetFPRegName, |
| 510 | fmt); |
| 511 | } |
| 512 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 513 | std::string RepeatI(void (Ass::*f)(const Imm&), |
| 514 | size_t imm_bytes, |
| 515 | const std::string& fmt, |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 516 | bool as_uint = false) { |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 517 | std::string str; |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 518 | std::vector<int64_t> imms = CreateImmediateValues(imm_bytes, as_uint); |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 519 | |
| 520 | WarnOnCombinations(imms.size()); |
| 521 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 522 | for (int64_t imm : imms) { |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 523 | Imm new_imm = CreateImmediate(imm); |
| 524 | (assembler_.get()->*f)(new_imm); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 525 | std::string base = fmt; |
| 526 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 527 | size_t imm_index = base.find(IMM_TOKEN); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 528 | if (imm_index != std::string::npos) { |
| 529 | std::ostringstream sreg; |
| 530 | sreg << imm; |
| 531 | std::string imm_string = sreg.str(); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 532 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | if (str.size() > 0) { |
| 536 | str += "\n"; |
| 537 | } |
| 538 | str += base; |
| 539 | } |
| 540 | // Add a newline at the end. |
| 541 | str += "\n"; |
| 542 | return str; |
| 543 | } |
| 544 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 545 | std::string RepeatVV(void (Ass::*f)(VecReg, VecReg), const std::string& fmt) { |
| 546 | return RepeatTemplatedRegisters<VecReg, VecReg>(f, |
| 547 | GetVectorRegisters(), |
| 548 | GetVectorRegisters(), |
| 549 | &AssemblerTest::GetVecRegName, |
| 550 | &AssemblerTest::GetVecRegName, |
| 551 | fmt); |
| 552 | } |
| 553 | |
| 554 | std::string RepeatVVV(void (Ass::*f)(VecReg, VecReg, VecReg), const std::string& fmt) { |
| 555 | return RepeatTemplatedRegisters<VecReg, VecReg, VecReg>(f, |
| 556 | GetVectorRegisters(), |
| 557 | GetVectorRegisters(), |
| 558 | GetVectorRegisters(), |
| 559 | &AssemblerTest::GetVecRegName, |
| 560 | &AssemblerTest::GetVecRegName, |
| 561 | &AssemblerTest::GetVecRegName, |
| 562 | fmt); |
| 563 | } |
| 564 | |
| 565 | std::string RepeatVR(void (Ass::*f)(VecReg, Reg), const std::string& fmt) { |
| 566 | return RepeatTemplatedRegisters<VecReg, Reg>( |
| 567 | f, |
| 568 | GetVectorRegisters(), |
| 569 | GetRegisters(), |
| 570 | &AssemblerTest::GetVecRegName, |
| 571 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 572 | fmt); |
| 573 | } |
| 574 | |
| 575 | template <typename ImmType> |
| 576 | std::string RepeatVRIb(void (Ass::*f)(VecReg, Reg, ImmType), |
| 577 | int imm_bits, |
| 578 | const std::string& fmt, |
| 579 | int bias = 0, |
| 580 | int multiplier = 1) { |
| 581 | return RepeatTemplatedRegistersImmBits<VecReg, Reg, ImmType>( |
| 582 | f, |
| 583 | imm_bits, |
| 584 | GetVectorRegisters(), |
| 585 | GetRegisters(), |
| 586 | &AssemblerTest::GetVecRegName, |
| 587 | &AssemblerTest::GetRegName<RegisterView::kUsePrimaryName>, |
| 588 | fmt, |
| 589 | bias, |
| 590 | multiplier); |
| 591 | } |
| 592 | |
| 593 | template <typename ImmType> |
| 594 | std::string RepeatVVIb(void (Ass::*f)(VecReg, VecReg, ImmType), |
| 595 | int imm_bits, |
| 596 | const std::string& fmt, |
| 597 | int bias = 0) { |
| 598 | return RepeatTemplatedRegistersImmBits<VecReg, VecReg, ImmType>(f, |
| 599 | imm_bits, |
| 600 | GetVectorRegisters(), |
| 601 | GetVectorRegisters(), |
| 602 | &AssemblerTest::GetVecRegName, |
| 603 | &AssemblerTest::GetVecRegName, |
| 604 | fmt, |
| 605 | bias); |
| 606 | } |
| 607 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 608 | // This is intended to be run as a test. |
| 609 | bool CheckTools() { |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 610 | return test_helper_->CheckTools(); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 613 | // The following functions are public so that TestFn can use them... |
| 614 | |
| 615 | virtual std::vector<Reg*> GetRegisters() = 0; |
| 616 | |
| 617 | virtual std::vector<FPReg*> GetFPRegisters() { |
| 618 | UNIMPLEMENTED(FATAL) << "Architecture does not support floating-point registers"; |
| 619 | UNREACHABLE(); |
| 620 | } |
| 621 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 622 | virtual std::vector<VecReg*> GetVectorRegisters() { |
| 623 | UNIMPLEMENTED(FATAL) << "Architecture does not support vector registers"; |
| 624 | UNREACHABLE(); |
| 625 | } |
| 626 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 627 | // Secondary register names are the secondary view on registers, e.g., 32b on 64b systems. |
| 628 | virtual std::string GetSecondaryRegisterName(const Reg& reg ATTRIBUTE_UNUSED) { |
| 629 | UNIMPLEMENTED(FATAL) << "Architecture does not support secondary registers"; |
| 630 | UNREACHABLE(); |
| 631 | } |
| 632 | |
Chao-ying Fu | d23840d | 2015-04-07 16:03:04 -0700 | [diff] [blame] | 633 | // Tertiary register names are the tertiary view on registers, e.g., 16b on 64b systems. |
| 634 | virtual std::string GetTertiaryRegisterName(const Reg& reg ATTRIBUTE_UNUSED) { |
| 635 | UNIMPLEMENTED(FATAL) << "Architecture does not support tertiary registers"; |
| 636 | UNREACHABLE(); |
| 637 | } |
| 638 | |
| 639 | // Quaternary register names are the quaternary view on registers, e.g., 8b on 64b systems. |
| 640 | virtual std::string GetQuaternaryRegisterName(const Reg& reg ATTRIBUTE_UNUSED) { |
| 641 | UNIMPLEMENTED(FATAL) << "Architecture does not support quaternary registers"; |
| 642 | UNREACHABLE(); |
| 643 | } |
| 644 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 645 | std::string GetRegisterName(const Reg& reg) { |
| 646 | return GetRegName<RegisterView::kUsePrimaryName>(reg); |
| 647 | } |
| 648 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 649 | protected: |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 650 | explicit AssemblerTest() {} |
| 651 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 652 | void SetUp() OVERRIDE { |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 653 | arena_.reset(new ArenaAllocator(&pool_)); |
Chris Larsen | 3add9cb | 2016-04-14 14:01:33 -0700 | [diff] [blame] | 654 | assembler_.reset(CreateAssembler(arena_.get())); |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 655 | test_helper_.reset( |
| 656 | new AssemblerTestInfrastructure(GetArchitectureString(), |
| 657 | GetAssemblerCmdName(), |
| 658 | GetAssemblerParameters(), |
| 659 | GetObjdumpCmdName(), |
| 660 | GetObjdumpParameters(), |
| 661 | GetDisassembleCmdName(), |
| 662 | GetDisassembleParameters(), |
| 663 | GetAssemblyHeader())); |
Andreas Gampe | b40c6a7 | 2014-05-02 14:25:12 -0700 | [diff] [blame] | 664 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 665 | SetUpHelpers(); |
| 666 | } |
| 667 | |
Andreas Gampe | 7747c8d | 2014-08-06 14:53:03 -0700 | [diff] [blame] | 668 | void TearDown() OVERRIDE { |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 669 | test_helper_.reset(); // Clean up the helper. |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 670 | assembler_.reset(); |
| 671 | arena_.reset(); |
Andreas Gampe | 7747c8d | 2014-08-06 14:53:03 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Chris Larsen | 3add9cb | 2016-04-14 14:01:33 -0700 | [diff] [blame] | 674 | // Override this to set up any architecture-specific things, e.g., CPU revision. |
| 675 | virtual Ass* CreateAssembler(ArenaAllocator* arena) { |
| 676 | return new (arena) Ass(arena); |
| 677 | } |
| 678 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 679 | // Override this to set up any architecture-specific things, e.g., register vectors. |
| 680 | virtual void SetUpHelpers() {} |
| 681 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 682 | // Get the typically used name for this architecture, e.g., aarch64, x86_64, ... |
| 683 | virtual std::string GetArchitectureString() = 0; |
| 684 | |
| 685 | // Get the name of the assembler, e.g., "as" by default. |
| 686 | virtual std::string GetAssemblerCmdName() { |
| 687 | return "as"; |
| 688 | } |
| 689 | |
| 690 | // Switches to the assembler command. Default none. |
| 691 | virtual std::string GetAssemblerParameters() { |
| 692 | return ""; |
| 693 | } |
| 694 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 695 | // Get the name of the objdump, e.g., "objdump" by default. |
| 696 | virtual std::string GetObjdumpCmdName() { |
| 697 | return "objdump"; |
| 698 | } |
| 699 | |
| 700 | // Switches to the objdump command. Default is " -h". |
| 701 | virtual std::string GetObjdumpParameters() { |
| 702 | return " -h"; |
| 703 | } |
| 704 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 705 | // Get the name of the objdump, e.g., "objdump" by default. |
| 706 | virtual std::string GetDisassembleCmdName() { |
| 707 | return "objdump"; |
| 708 | } |
| 709 | |
| 710 | // Switches to the objdump command. As it's a binary, one needs to push the architecture and |
| 711 | // such to objdump, so it's architecture-specific and there is no default. |
| 712 | virtual std::string GetDisassembleParameters() = 0; |
| 713 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 714 | // Create a couple of immediate values up to the number of bytes given. |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 715 | virtual std::vector<int64_t> CreateImmediateValues(size_t imm_bytes, bool as_uint = false) { |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 716 | std::vector<int64_t> res; |
| 717 | res.push_back(0); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 718 | if (!as_uint) { |
| 719 | res.push_back(-1); |
| 720 | } else { |
| 721 | res.push_back(0xFF); |
| 722 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 723 | res.push_back(0x12); |
| 724 | if (imm_bytes >= 2) { |
| 725 | res.push_back(0x1234); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 726 | if (!as_uint) { |
| 727 | res.push_back(-0x1234); |
| 728 | } else { |
| 729 | res.push_back(0xFFFF); |
| 730 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 731 | if (imm_bytes >= 4) { |
| 732 | res.push_back(0x12345678); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 733 | if (!as_uint) { |
| 734 | res.push_back(-0x12345678); |
| 735 | } else { |
| 736 | res.push_back(0xFFFFFFFF); |
| 737 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 738 | if (imm_bytes >= 6) { |
| 739 | res.push_back(0x123456789ABC); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 740 | if (!as_uint) { |
| 741 | res.push_back(-0x123456789ABC); |
| 742 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 743 | if (imm_bytes >= 8) { |
| 744 | res.push_back(0x123456789ABCDEF0); |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 745 | if (!as_uint) { |
| 746 | res.push_back(-0x123456789ABCDEF0); |
| 747 | } else { |
| 748 | res.push_back(0xFFFFFFFFFFFFFFFF); |
| 749 | } |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | return res; |
| 755 | } |
| 756 | |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 757 | const int kMaxBitsExhaustiveTest = 8; |
| 758 | |
| 759 | // Create a couple of immediate values up to the number of bits given. |
| 760 | virtual std::vector<int64_t> CreateImmediateValuesBits(const int imm_bits, bool as_uint = false) { |
| 761 | CHECK_GT(imm_bits, 0); |
| 762 | CHECK_LE(imm_bits, 64); |
| 763 | std::vector<int64_t> res; |
| 764 | |
| 765 | if (imm_bits <= kMaxBitsExhaustiveTest) { |
| 766 | if (as_uint) { |
| 767 | for (uint64_t i = MinInt<uint64_t>(imm_bits); i <= MaxInt<uint64_t>(imm_bits); i++) { |
| 768 | res.push_back(static_cast<int64_t>(i)); |
| 769 | } |
| 770 | } else { |
| 771 | for (int64_t i = MinInt<int64_t>(imm_bits); i <= MaxInt<int64_t>(imm_bits); i++) { |
| 772 | res.push_back(i); |
| 773 | } |
| 774 | } |
| 775 | } else { |
| 776 | if (as_uint) { |
| 777 | for (uint64_t i = MinInt<uint64_t>(kMaxBitsExhaustiveTest); |
| 778 | i <= MaxInt<uint64_t>(kMaxBitsExhaustiveTest); |
| 779 | i++) { |
| 780 | res.push_back(static_cast<int64_t>(i)); |
| 781 | } |
| 782 | for (int i = 0; i <= imm_bits; i++) { |
| 783 | uint64_t j = (MaxInt<uint64_t>(kMaxBitsExhaustiveTest) + 1) + |
| 784 | ((MaxInt<uint64_t>(imm_bits) - |
| 785 | (MaxInt<uint64_t>(kMaxBitsExhaustiveTest) + 1)) |
| 786 | * i / imm_bits); |
| 787 | res.push_back(static_cast<int64_t>(j)); |
| 788 | } |
| 789 | } else { |
| 790 | for (int i = 0; i <= imm_bits; i++) { |
| 791 | int64_t j = MinInt<int64_t>(imm_bits) + |
| 792 | ((((MinInt<int64_t>(kMaxBitsExhaustiveTest) - 1) - |
| 793 | MinInt<int64_t>(imm_bits)) |
| 794 | * i) / imm_bits); |
| 795 | res.push_back(static_cast<int64_t>(j)); |
| 796 | } |
| 797 | for (int64_t i = MinInt<int64_t>(kMaxBitsExhaustiveTest); |
| 798 | i <= MaxInt<int64_t>(kMaxBitsExhaustiveTest); |
| 799 | i++) { |
| 800 | res.push_back(static_cast<int64_t>(i)); |
| 801 | } |
| 802 | for (int i = 0; i <= imm_bits; i++) { |
| 803 | int64_t j = (MaxInt<int64_t>(kMaxBitsExhaustiveTest) + 1) + |
| 804 | ((MaxInt<int64_t>(imm_bits) - (MaxInt<int64_t>(kMaxBitsExhaustiveTest) + 1)) |
| 805 | * i / imm_bits); |
| 806 | res.push_back(static_cast<int64_t>(j)); |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | return res; |
| 812 | } |
| 813 | |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 814 | // Create an immediate from the specific value. |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 815 | virtual Imm CreateImmediate(int64_t imm_value) = 0; |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 816 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 817 | template <typename RegType> |
| 818 | std::string RepeatTemplatedRegister(void (Ass::*f)(RegType), |
| 819 | const std::vector<RegType*> registers, |
| 820 | std::string (AssemblerTest::*GetName)(const RegType&), |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 821 | const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 822 | std::string str; |
| 823 | for (auto reg : registers) { |
| 824 | (assembler_.get()->*f)(*reg); |
| 825 | std::string base = fmt; |
| 826 | |
| 827 | std::string reg_string = (this->*GetName)(*reg); |
| 828 | size_t reg_index; |
| 829 | if ((reg_index = base.find(REG_TOKEN)) != std::string::npos) { |
| 830 | base.replace(reg_index, ConstexprStrLen(REG_TOKEN), reg_string); |
| 831 | } |
| 832 | |
| 833 | if (str.size() > 0) { |
| 834 | str += "\n"; |
| 835 | } |
| 836 | str += base; |
| 837 | } |
| 838 | // Add a newline at the end. |
| 839 | str += "\n"; |
| 840 | return str; |
| 841 | } |
| 842 | |
| 843 | template <typename Reg1, typename Reg2> |
| 844 | std::string RepeatTemplatedRegisters(void (Ass::*f)(Reg1, Reg2), |
| 845 | const std::vector<Reg1*> reg1_registers, |
| 846 | const std::vector<Reg2*> reg2_registers, |
| 847 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 848 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 849 | const std::string& fmt) { |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 850 | WarnOnCombinations(reg1_registers.size() * reg2_registers.size()); |
| 851 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 852 | std::string str; |
| 853 | for (auto reg1 : reg1_registers) { |
| 854 | for (auto reg2 : reg2_registers) { |
| 855 | (assembler_.get()->*f)(*reg1, *reg2); |
| 856 | std::string base = fmt; |
| 857 | |
| 858 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 859 | size_t reg1_index; |
| 860 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 861 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 862 | } |
| 863 | |
| 864 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 865 | size_t reg2_index; |
| 866 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 867 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 868 | } |
| 869 | |
| 870 | if (str.size() > 0) { |
| 871 | str += "\n"; |
| 872 | } |
| 873 | str += base; |
| 874 | } |
| 875 | } |
| 876 | // Add a newline at the end. |
| 877 | str += "\n"; |
| 878 | return str; |
| 879 | } |
| 880 | |
Chris Larsen | 5141763 | 2015-10-02 13:24:25 -0700 | [diff] [blame] | 881 | template <typename Reg1, typename Reg2> |
| 882 | std::string RepeatTemplatedRegistersNoDupes(void (Ass::*f)(Reg1, Reg2), |
| 883 | const std::vector<Reg1*> reg1_registers, |
| 884 | const std::vector<Reg2*> reg2_registers, |
| 885 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 886 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 887 | const std::string& fmt) { |
Chris Larsen | 5141763 | 2015-10-02 13:24:25 -0700 | [diff] [blame] | 888 | WarnOnCombinations(reg1_registers.size() * reg2_registers.size()); |
| 889 | |
| 890 | std::string str; |
| 891 | for (auto reg1 : reg1_registers) { |
| 892 | for (auto reg2 : reg2_registers) { |
| 893 | if (reg1 == reg2) continue; |
| 894 | (assembler_.get()->*f)(*reg1, *reg2); |
| 895 | std::string base = fmt; |
| 896 | |
| 897 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 898 | size_t reg1_index; |
| 899 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 900 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 901 | } |
| 902 | |
| 903 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 904 | size_t reg2_index; |
| 905 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 906 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 907 | } |
| 908 | |
| 909 | if (str.size() > 0) { |
| 910 | str += "\n"; |
| 911 | } |
| 912 | str += base; |
| 913 | } |
| 914 | } |
| 915 | // Add a newline at the end. |
| 916 | str += "\n"; |
| 917 | return str; |
| 918 | } |
| 919 | |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 920 | template <typename Reg1, typename Reg2, typename Reg3> |
| 921 | std::string RepeatTemplatedRegisters(void (Ass::*f)(Reg1, Reg2, Reg3), |
| 922 | const std::vector<Reg1*> reg1_registers, |
| 923 | const std::vector<Reg2*> reg2_registers, |
| 924 | const std::vector<Reg3*> reg3_registers, |
| 925 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 926 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
| 927 | std::string (AssemblerTest::*GetName3)(const Reg3&), |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 928 | const std::string& fmt) { |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 929 | std::string str; |
| 930 | for (auto reg1 : reg1_registers) { |
| 931 | for (auto reg2 : reg2_registers) { |
| 932 | for (auto reg3 : reg3_registers) { |
| 933 | (assembler_.get()->*f)(*reg1, *reg2, *reg3); |
| 934 | std::string base = fmt; |
| 935 | |
| 936 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 937 | size_t reg1_index; |
| 938 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 939 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 940 | } |
| 941 | |
| 942 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 943 | size_t reg2_index; |
| 944 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 945 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 946 | } |
| 947 | |
| 948 | std::string reg3_string = (this->*GetName3)(*reg3); |
| 949 | size_t reg3_index; |
| 950 | while ((reg3_index = base.find(REG3_TOKEN)) != std::string::npos) { |
| 951 | base.replace(reg3_index, ConstexprStrLen(REG3_TOKEN), reg3_string); |
| 952 | } |
| 953 | |
| 954 | if (str.size() > 0) { |
| 955 | str += "\n"; |
| 956 | } |
| 957 | str += base; |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | // Add a newline at the end. |
| 962 | str += "\n"; |
| 963 | return str; |
| 964 | } |
| 965 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 966 | template <typename Reg1, typename Reg2> |
| 967 | std::string RepeatTemplatedRegistersImm(void (Ass::*f)(Reg1, Reg2, const Imm&), |
| 968 | const std::vector<Reg1*> reg1_registers, |
| 969 | const std::vector<Reg2*> reg2_registers, |
| 970 | std::string (AssemblerTest::*GetName1)(const Reg1&), |
| 971 | std::string (AssemblerTest::*GetName2)(const Reg2&), |
| 972 | size_t imm_bytes, |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 973 | const std::string& fmt) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 974 | std::vector<int64_t> imms = CreateImmediateValues(imm_bytes); |
| 975 | WarnOnCombinations(reg1_registers.size() * reg2_registers.size() * imms.size()); |
| 976 | |
| 977 | std::string str; |
| 978 | for (auto reg1 : reg1_registers) { |
| 979 | for (auto reg2 : reg2_registers) { |
| 980 | for (int64_t imm : imms) { |
| 981 | Imm new_imm = CreateImmediate(imm); |
| 982 | (assembler_.get()->*f)(*reg1, *reg2, new_imm); |
| 983 | std::string base = fmt; |
| 984 | |
| 985 | std::string reg1_string = (this->*GetName1)(*reg1); |
| 986 | size_t reg1_index; |
| 987 | while ((reg1_index = base.find(REG1_TOKEN)) != std::string::npos) { |
| 988 | base.replace(reg1_index, ConstexprStrLen(REG1_TOKEN), reg1_string); |
| 989 | } |
| 990 | |
| 991 | std::string reg2_string = (this->*GetName2)(*reg2); |
| 992 | size_t reg2_index; |
| 993 | while ((reg2_index = base.find(REG2_TOKEN)) != std::string::npos) { |
| 994 | base.replace(reg2_index, ConstexprStrLen(REG2_TOKEN), reg2_string); |
| 995 | } |
| 996 | |
| 997 | size_t imm_index = base.find(IMM_TOKEN); |
| 998 | if (imm_index != std::string::npos) { |
| 999 | std::ostringstream sreg; |
| 1000 | sreg << imm; |
| 1001 | std::string imm_string = sreg.str(); |
| 1002 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 1003 | } |
| 1004 | |
| 1005 | if (str.size() > 0) { |
| 1006 | str += "\n"; |
| 1007 | } |
| 1008 | str += base; |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | // Add a newline at the end. |
| 1013 | str += "\n"; |
| 1014 | return str; |
| 1015 | } |
| 1016 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1017 | template <RegisterView kRegView> |
| 1018 | std::string GetRegName(const Reg& reg) { |
| 1019 | std::ostringstream sreg; |
| 1020 | switch (kRegView) { |
| 1021 | case RegisterView::kUsePrimaryName: |
| 1022 | sreg << reg; |
| 1023 | break; |
| 1024 | |
| 1025 | case RegisterView::kUseSecondaryName: |
| 1026 | sreg << GetSecondaryRegisterName(reg); |
| 1027 | break; |
Chao-ying Fu | d23840d | 2015-04-07 16:03:04 -0700 | [diff] [blame] | 1028 | |
| 1029 | case RegisterView::kUseTertiaryName: |
| 1030 | sreg << GetTertiaryRegisterName(reg); |
| 1031 | break; |
| 1032 | |
| 1033 | case RegisterView::kUseQuaternaryName: |
| 1034 | sreg << GetQuaternaryRegisterName(reg); |
| 1035 | break; |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1036 | } |
| 1037 | return sreg.str(); |
| 1038 | } |
| 1039 | |
| 1040 | std::string GetFPRegName(const FPReg& reg) { |
| 1041 | std::ostringstream sreg; |
| 1042 | sreg << reg; |
| 1043 | return sreg.str(); |
| 1044 | } |
| 1045 | |
Goran Jakovljevic | 5a9e51d | 2017-03-16 16:11:43 +0000 | [diff] [blame^] | 1046 | std::string GetVecRegName(const VecReg& reg) { |
| 1047 | std::ostringstream sreg; |
| 1048 | sreg << reg; |
| 1049 | return sreg.str(); |
| 1050 | } |
| 1051 | |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 1052 | // If the assembly file needs a header, return it in a sub-class. |
| 1053 | virtual const char* GetAssemblyHeader() { |
| 1054 | return nullptr; |
| 1055 | } |
| 1056 | |
| 1057 | void WarnOnCombinations(size_t count) { |
| 1058 | if (count > kWarnManyCombinationsThreshold) { |
| 1059 | GTEST_LOG_(WARNING) << "Many combinations (" << count << "), test generation might be slow."; |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | static constexpr const char* REG_TOKEN = "{reg}"; |
| 1064 | static constexpr const char* REG1_TOKEN = "{reg1}"; |
| 1065 | static constexpr const char* REG2_TOKEN = "{reg2}"; |
Chris Larsen | dbce0d7 | 2015-09-17 13:34:00 -0700 | [diff] [blame] | 1066 | static constexpr const char* REG3_TOKEN = "{reg3}"; |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 1067 | static constexpr const char* IMM_TOKEN = "{imm}"; |
| 1068 | |
| 1069 | private: |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1070 | template <RegisterView kRegView> |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 1071 | std::string RepeatRegisterImm(void (Ass::*f)(Reg, const Imm&), |
| 1072 | size_t imm_bytes, |
| 1073 | const std::string& fmt) { |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1074 | const std::vector<Reg*> registers = GetRegisters(); |
| 1075 | std::string str; |
| 1076 | std::vector<int64_t> imms = CreateImmediateValues(imm_bytes); |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 1077 | |
| 1078 | WarnOnCombinations(registers.size() * imms.size()); |
| 1079 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1080 | for (auto reg : registers) { |
| 1081 | for (int64_t imm : imms) { |
| 1082 | Imm new_imm = CreateImmediate(imm); |
| 1083 | (assembler_.get()->*f)(*reg, new_imm); |
| 1084 | std::string base = fmt; |
| 1085 | |
| 1086 | std::string reg_string = GetRegName<kRegView>(*reg); |
| 1087 | size_t reg_index; |
| 1088 | while ((reg_index = base.find(REG_TOKEN)) != std::string::npos) { |
| 1089 | base.replace(reg_index, ConstexprStrLen(REG_TOKEN), reg_string); |
| 1090 | } |
| 1091 | |
| 1092 | size_t imm_index = base.find(IMM_TOKEN); |
| 1093 | if (imm_index != std::string::npos) { |
| 1094 | std::ostringstream sreg; |
| 1095 | sreg << imm; |
| 1096 | std::string imm_string = sreg.str(); |
| 1097 | base.replace(imm_index, ConstexprStrLen(IMM_TOKEN), imm_string); |
| 1098 | } |
| 1099 | |
| 1100 | if (str.size() > 0) { |
| 1101 | str += "\n"; |
| 1102 | } |
| 1103 | str += base; |
| 1104 | } |
| 1105 | } |
| 1106 | // Add a newline at the end. |
| 1107 | str += "\n"; |
| 1108 | return str; |
| 1109 | } |
| 1110 | |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1111 | // Override this to pad the code with NOPs to a certain size if needed. |
| 1112 | virtual void Pad(std::vector<uint8_t>& data ATTRIBUTE_UNUSED) { |
| 1113 | } |
| 1114 | |
Andreas Gampe | 2e965ac | 2016-11-03 17:24:15 -0700 | [diff] [blame] | 1115 | void DriverWrapper(const std::string& assembly_text, const std::string& test_name) { |
Vladimir Marko | cf93a5c | 2015-06-16 11:33:24 +0000 | [diff] [blame] | 1116 | assembler_->FinalizeCode(); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 1117 | size_t cs = assembler_->CodeSize(); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1118 | std::unique_ptr<std::vector<uint8_t>> data(new std::vector<uint8_t>(cs)); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 1119 | MemoryRegion code(&(*data)[0], data->size()); |
| 1120 | assembler_->FinalizeInstructions(code); |
Alexey Frunze | a0e87b0 | 2015-09-24 22:57:20 -0700 | [diff] [blame] | 1121 | Pad(*data); |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 1122 | test_helper_->Driver(*data, assembly_text, test_name); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Andreas Gampe | 849cc5e | 2014-11-18 13:46:46 -0800 | [diff] [blame] | 1125 | static constexpr size_t kWarnManyCombinationsThreshold = 500; |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1126 | |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1127 | ArenaPool pool_; |
| 1128 | std::unique_ptr<ArenaAllocator> arena_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 1129 | std::unique_ptr<Ass> assembler_; |
Andreas Gampe | 03b9ee4 | 2015-04-24 21:41:45 -0700 | [diff] [blame] | 1130 | std::unique_ptr<AssemblerTestInfrastructure> test_helper_; |
Andreas Gampe | 7747c8d | 2014-08-06 14:53:03 -0700 | [diff] [blame] | 1131 | |
Andreas Gampe | 851df20 | 2014-11-12 14:05:46 -0800 | [diff] [blame] | 1132 | DISALLOW_COPY_AND_ASSIGN(AssemblerTest); |
Andreas Gampe | 5a4fa82 | 2014-03-31 16:50:12 -0700 | [diff] [blame] | 1133 | }; |
| 1134 | |
| 1135 | } // namespace art |
| 1136 | |
| 1137 | #endif // ART_COMPILER_UTILS_ASSEMBLER_TEST_H_ |