1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
#define ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
#include "dex_instruction.h"
namespace art {
inline constexpr size_t Instruction::SizeInCodeUnits(Format format) {
switch (format) {
case k10x:
case k12x:
case k11n:
case k11x:
case k10t: return 1;
case k20t:
case k22x:
case k21t:
case k21s:
case k21h:
case k21c:
case k23x:
case k22b:
case k22t:
case k22s:
case k22c: return 2;
case k32x:
case k30t:
case k31t:
case k31i:
case k31c:
case k35c:
case k3rc: return 3;
case k45cc:
case k4rcc: return 4;
case k51l: return 5;
case kInvalidFormat: return 0;
}
}
//------------------------------------------------------------------------------
// VRegA
//------------------------------------------------------------------------------
inline bool Instruction::HasVRegA() const {
switch (FormatOf(Opcode())) {
case k10t: return true;
case k10x: return true;
case k11n: return true;
case k11x: return true;
case k12x: return true;
case k20t: return true;
case k21c: return true;
case k21h: return true;
case k21s: return true;
case k21t: return true;
case k22b: return true;
case k22c: return true;
case k22s: return true;
case k22t: return true;
case k22x: return true;
case k23x: return true;
case k30t: return true;
case k31c: return true;
case k31i: return true;
case k31t: return true;
case k32x: return true;
case k35c: return true;
case k3rc: return true;
case k45cc: return true;
case k4rcc: return true;
case k51l: return true;
default: return false;
}
}
inline int32_t Instruction::VRegA() const {
return VRegA(FormatOf(Opcode()), Fetch16(0));
}
inline int32_t Instruction::VRegA(Format format, uint16_t inst_data) const {
DCHECK_EQ(format, FormatOf(Opcode()));
switch (format) {
case k10t: return VRegA_10t(inst_data);
case k10x: return VRegA_10x(inst_data);
case k11n: return VRegA_11n(inst_data);
case k11x: return VRegA_11x(inst_data);
case k12x: return VRegA_12x(inst_data);
case k20t: return VRegA_20t();
case k21c: return VRegA_21c(inst_data);
case k21h: return VRegA_21h(inst_data);
case k21s: return VRegA_21s(inst_data);
case k21t: return VRegA_21t(inst_data);
case k22b: return VRegA_22b(inst_data);
case k22c: return VRegA_22c(inst_data);
case k22s: return VRegA_22s(inst_data);
case k22t: return VRegA_22t(inst_data);
case k22x: return VRegA_22x(inst_data);
case k23x: return VRegA_23x(inst_data);
case k30t: return VRegA_30t();
case k31c: return VRegA_31c(inst_data);
case k31i: return VRegA_31i(inst_data);
case k31t: return VRegA_31t(inst_data);
case k32x: return VRegA_32x();
case k35c: return VRegA_35c(inst_data);
case k3rc: return VRegA_3rc(inst_data);
case k45cc: return VRegA_45cc(inst_data);
case k4rcc: return VRegA_4rcc(inst_data);
case k51l: return VRegA_51l(inst_data);
default:
LOG(FATAL) << "Tried to access vA of instruction " << Name() << " which has no A operand.";
exit(EXIT_FAILURE);
}
}
inline int8_t Instruction::VRegA_10t(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k10t);
return static_cast<int8_t>(InstAA(inst_data));
}
inline uint8_t Instruction::VRegA_10x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k10x);
return InstAA(inst_data);
}
inline uint4_t Instruction::VRegA_11n(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k11n);
return InstA(inst_data);
}
inline uint8_t Instruction::VRegA_11x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k11x);
return InstAA(inst_data);
}
inline uint4_t Instruction::VRegA_12x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k12x);
return InstA(inst_data);
}
inline int16_t Instruction::VRegA_20t() const {
DCHECK_EQ(FormatOf(Opcode()), k20t);
return static_cast<int16_t>(Fetch16(1));
}
inline uint8_t Instruction::VRegA_21c(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k21c);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_21h(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k21h);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_21s(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k21s);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_21t(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k21t);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_22b(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22b);
return InstAA(inst_data);
}
inline uint4_t Instruction::VRegA_22c(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22c);
return InstA(inst_data);
}
inline uint4_t Instruction::VRegA_22s(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22s);
return InstA(inst_data);
}
inline uint4_t Instruction::VRegA_22t(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22t);
return InstA(inst_data);
}
inline uint8_t Instruction::VRegA_22x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22x);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_23x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k23x);
return InstAA(inst_data);
}
inline int32_t Instruction::VRegA_30t() const {
DCHECK_EQ(FormatOf(Opcode()), k30t);
return static_cast<int32_t>(Fetch32(1));
}
inline uint8_t Instruction::VRegA_31c(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k31c);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_31i(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k31i);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_31t(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k31t);
return InstAA(inst_data);
}
inline uint16_t Instruction::VRegA_32x() const {
DCHECK_EQ(FormatOf(Opcode()), k32x);
return Fetch16(1);
}
inline uint4_t Instruction::VRegA_35c(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k35c);
return InstB(inst_data); // This is labeled A in the spec.
}
inline uint8_t Instruction::VRegA_3rc(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k3rc);
return InstAA(inst_data);
}
inline uint8_t Instruction::VRegA_51l(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k51l);
return InstAA(inst_data);
}
inline uint4_t Instruction::VRegA_45cc(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k45cc);
return InstB(inst_data); // This is labeled A in the spec.
}
inline uint8_t Instruction::VRegA_4rcc(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k4rcc);
return InstAA(inst_data);
}
//------------------------------------------------------------------------------
// VRegB
//------------------------------------------------------------------------------
inline bool Instruction::HasVRegB() const {
switch (FormatOf(Opcode())) {
case k11n: return true;
case k12x: return true;
case k21c: return true;
case k21h: return true;
case k21s: return true;
case k21t: return true;
case k22b: return true;
case k22c: return true;
case k22s: return true;
case k22t: return true;
case k22x: return true;
case k23x: return true;
case k31c: return true;
case k31i: return true;
case k31t: return true;
case k32x: return true;
case k35c: return true;
case k3rc: return true;
case k45cc: return true;
case k4rcc: return true;
case k51l: return true;
default: return false;
}
}
inline bool Instruction::HasWideVRegB() const {
return FormatOf(Opcode()) == k51l;
}
inline int32_t Instruction::VRegB() const {
return VRegB(FormatOf(Opcode()), Fetch16(0));
}
inline int32_t Instruction::VRegB(Format format, uint16_t inst_data) const {
DCHECK_EQ(format, FormatOf(Opcode()));
switch (format) {
case k11n: return VRegB_11n(inst_data);
case k12x: return VRegB_12x(inst_data);
case k21c: return VRegB_21c();
case k21h: return VRegB_21h();
case k21s: return VRegB_21s();
case k21t: return VRegB_21t();
case k22b: return VRegB_22b();
case k22c: return VRegB_22c(inst_data);
case k22s: return VRegB_22s(inst_data);
case k22t: return VRegB_22t(inst_data);
case k22x: return VRegB_22x();
case k23x: return VRegB_23x();
case k31c: return VRegB_31c();
case k31i: return VRegB_31i();
case k31t: return VRegB_31t();
case k32x: return VRegB_32x();
case k35c: return VRegB_35c();
case k3rc: return VRegB_3rc();
case k45cc: return VRegB_45cc();
case k4rcc: return VRegB_4rcc();
case k51l: return VRegB_51l();
default:
LOG(FATAL) << "Tried to access vB of instruction " << Name() << " which has no B operand.";
exit(EXIT_FAILURE);
}
}
inline uint64_t Instruction::WideVRegB() const {
return VRegB_51l();
}
inline int4_t Instruction::VRegB_11n(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k11n);
return static_cast<int4_t>((InstB(inst_data) << 28) >> 28);
}
inline uint4_t Instruction::VRegB_12x(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k12x);
return InstB(inst_data);
}
inline uint16_t Instruction::VRegB_21c() const {
DCHECK_EQ(FormatOf(Opcode()), k21c);
return Fetch16(1);
}
inline uint16_t Instruction::VRegB_21h() const {
DCHECK_EQ(FormatOf(Opcode()), k21h);
return Fetch16(1);
}
inline int16_t Instruction::VRegB_21s() const {
DCHECK_EQ(FormatOf(Opcode()), k21s);
return static_cast<int16_t>(Fetch16(1));
}
inline int16_t Instruction::VRegB_21t() const {
DCHECK_EQ(FormatOf(Opcode()), k21t);
return static_cast<int16_t>(Fetch16(1));
}
inline uint8_t Instruction::VRegB_22b() const {
DCHECK_EQ(FormatOf(Opcode()), k22b);
return static_cast<uint8_t>(Fetch16(1) & 0xff);
}
inline uint4_t Instruction::VRegB_22c(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22c);
return InstB(inst_data);
}
inline uint4_t Instruction::VRegB_22s(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22s);
return InstB(inst_data);
}
inline uint4_t Instruction::VRegB_22t(uint16_t inst_data) const {
DCHECK_EQ(FormatOf(Opcode()), k22t);
return InstB(inst_data);
}
inline uint16_t Instruction::VRegB_22x() const {
DCHECK_EQ(FormatOf(Opcode()), k22x);
return Fetch16(1);
}
inline uint8_t Instruction::VRegB_23x() const {
DCHECK_EQ(FormatOf(Opcode()), k23x);
return static_cast<uint8_t>(Fetch16(1) & 0xff);
}
inline uint32_t Instruction::VRegB_31c() const {
DCHECK_EQ(FormatOf(Opcode()), k31c);
return Fetch32(1);
}
inline int32_t Instruction::VRegB_31i() const {
DCHECK_EQ(FormatOf(Opcode()), k31i);
return static_cast<int32_t>(Fetch32(1));
}
inline int32_t Instruction::VRegB_31t() const {
DCHECK_EQ(FormatOf(Opcode()), k31t);
return static_cast<int32_t>(Fetch32(1));
}
inline uint16_t Instruction::VRegB_32x() const {
DCHECK_EQ(FormatOf(Opcode()), k32x);
return Fetch16(2);
}
inline uint16_t Instruction::VRegB_35c() const {
DCHECK_EQ(FormatOf(Opcode()), k35c);
return Fetch16(1);
}
inline uint16_t Instruction::VRegB_3rc() const {
DCHECK_EQ(FormatOf(Opcode()), k3rc);
return Fetch16(1);
}
inline uint16_t Instruction::VRegB_45cc() const {
DCHECK_EQ(FormatOf(Opcode()), k45cc);
return Fetch16(1);
}
inline uint16_t Instruction::VRegB_4rcc() const {
DCHECK_EQ(FormatOf(Opcode()), k4rcc);
return Fetch16(1);
}
inline uint64_t Instruction::VRegB_51l() const {
DCHECK_EQ(FormatOf(Opcode()), k51l);
uint64_t vB_wide = Fetch32(1) | ((uint64_t) Fetch32(3) << 32);
return vB_wide;
}
//------------------------------------------------------------------------------
// VRegC
//------------------------------------------------------------------------------
inline bool Instruction::HasVRegC() const {
switch (FormatOf(Opcode())) {
case k22b: return true;
case k22c: return true;
case k22s: return true;
case k22t: return true;
case k23x: return true;
case k35c: return true;
case k3rc: return true;
case k45cc: return true;
case k4rcc: return true;
default: return false;
}
}
inline int32_t Instruction::VRegC() const {
return VRegC(FormatOf(Opcode()));
}
inline int32_t Instruction::VRegC(Format format) const {
DCHECK_EQ(format, FormatOf(Opcode()));
switch (format) {
case k22b: return VRegC_22b();
case k22c: return VRegC_22c();
case k22s: return VRegC_22s();
case k22t: return VRegC_22t();
case k23x: return VRegC_23x();
case k35c: return VRegC_35c();
case k3rc: return VRegC_3rc();
case k45cc: return VRegC_45cc();
case k4rcc: return VRegC_4rcc();
default:
LOG(FATAL) << "Tried to access vC of instruction " << Name() << " which has no C operand.";
exit(EXIT_FAILURE);
}
}
inline int8_t Instruction::VRegC_22b() const {
DCHECK_EQ(FormatOf(Opcode()), k22b);
return static_cast<int8_t>(Fetch16(1) >> 8);
}
inline uint16_t Instruction::VRegC_22c() const {
DCHECK_EQ(FormatOf(Opcode()), k22c);
return Fetch16(1);
}
inline int16_t Instruction::VRegC_22s() const {
DCHECK_EQ(FormatOf(Opcode()), k22s);
return static_cast<int16_t>(Fetch16(1));
}
inline int16_t Instruction::VRegC_22t() const {
DCHECK_EQ(FormatOf(Opcode()), k22t);
return static_cast<int16_t>(Fetch16(1));
}
inline uint8_t Instruction::VRegC_23x() const {
DCHECK_EQ(FormatOf(Opcode()), k23x);
return static_cast<uint8_t>(Fetch16(1) >> 8);
}
inline uint4_t Instruction::VRegC_35c() const {
DCHECK_EQ(FormatOf(Opcode()), k35c);
return static_cast<uint4_t>(Fetch16(2) & 0x0f);
}
inline uint16_t Instruction::VRegC_3rc() const {
DCHECK_EQ(FormatOf(Opcode()), k3rc);
return Fetch16(2);
}
inline uint4_t Instruction::VRegC_45cc() const {
DCHECK_EQ(FormatOf(Opcode()), k45cc);
return static_cast<uint4_t>(Fetch16(2) & 0x0f);
}
inline uint16_t Instruction::VRegC_4rcc() const {
DCHECK_EQ(FormatOf(Opcode()), k4rcc);
return Fetch16(2);
}
//------------------------------------------------------------------------------
// VRegH
//------------------------------------------------------------------------------
inline bool Instruction::HasVRegH() const {
switch (FormatOf(Opcode())) {
case k45cc: return true;
case k4rcc: return true;
default : return false;
}
}
inline int32_t Instruction::VRegH() const {
switch (FormatOf(Opcode())) {
case k45cc: return VRegH_45cc();
case k4rcc: return VRegH_4rcc();
default :
LOG(FATAL) << "Tried to access vH of instruction " << Name() << " which has no H operand.";
exit(EXIT_FAILURE);
}
}
inline uint16_t Instruction::VRegH_45cc() const {
DCHECK_EQ(FormatOf(Opcode()), k45cc);
return Fetch16(3);
}
inline uint16_t Instruction::VRegH_4rcc() const {
DCHECK_EQ(FormatOf(Opcode()), k4rcc);
return Fetch16(3);
}
inline bool Instruction::HasVarArgs() const {
return (FormatOf(Opcode()) == k35c) || (FormatOf(Opcode()) == k45cc);
}
inline uint32_t Instruction::GetVarArgs(uint32_t arg[kMaxVarArgRegs], uint16_t inst_data) const {
DCHECK(HasVarArgs());
/*
* Note that the fields mentioned in the spec don't appear in
* their "usual" positions here compared to most formats. This
* was done so that the field names for the argument count and
* reference index match between this format and the corresponding
* range formats (3rc and friends).
*
* Bottom line: The argument count is always in vA, and the
* method constant (or equivalent) is always in vB.
*/
uint16_t regList = Fetch16(2);
uint4_t count = InstB(inst_data); // This is labeled A in the spec.
DCHECK_LE(count, 5U) << "Invalid arg count in 35c (" << count << ")";
/*
* Copy the argument registers into the arg[] array, and
* also copy the first argument (if any) into vC. (The
* DecodedInstruction structure doesn't have separate
* fields for {vD, vE, vF, vG}, so there's no need to make
* copies of those.) Note that cases 5..2 fall through.
*/
switch (count) {
case 5:
arg[4] = InstA(inst_data);
FALLTHROUGH_INTENDED;
case 4:
arg[3] = (regList >> 12) & 0x0f;
FALLTHROUGH_INTENDED;
case 3:
arg[2] = (regList >> 8) & 0x0f;
FALLTHROUGH_INTENDED;
case 2:
arg[1] = (regList >> 4) & 0x0f;
FALLTHROUGH_INTENDED;
case 1:
arg[0] = regList & 0x0f;
break;
default: // case 0
break; // Valid, but no need to do anything.
}
return count;
}
} // namespace art
#endif // ART_LIBDEXFILE_DEX_DEX_INSTRUCTION_INL_H_
|