macro_jit_x64.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/assert.h"
  5. #include "common/logging/log.h"
  6. #include "common/microprofile.h"
  7. #include "common/x64/xbyak_util.h"
  8. #include "video_core/engines/maxwell_3d.h"
  9. #include "video_core/macro/macro_interpreter.h"
  10. #include "video_core/macro/macro_jit_x64.h"
  11. MICROPROFILE_DEFINE(MacroJitCompile, "GPU", "Compile macro JIT", MP_RGB(173, 255, 47));
  12. MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255, 0));
  13. namespace Tegra {
  14. static const Xbyak::Reg64 STATE = Xbyak::util::rbx;
  15. static const Xbyak::Reg32 RESULT = Xbyak::util::ebp;
  16. static const Xbyak::Reg64 PARAMETERS = Xbyak::util::r12;
  17. static const Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d;
  18. static const Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15;
  19. static const std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({
  20. STATE,
  21. RESULT,
  22. PARAMETERS,
  23. METHOD_ADDRESS,
  24. BRANCH_HOLDER,
  25. });
  26. MacroJITx64::MacroJITx64(Engines::Maxwell3D& maxwell3d)
  27. : MacroEngine::MacroEngine(maxwell3d), maxwell3d(maxwell3d) {}
  28. std::unique_ptr<CachedMacro> MacroJITx64::Compile(const std::vector<u32>& code) {
  29. return std::make_unique<MacroJITx64Impl>(maxwell3d, code);
  30. }
  31. MacroJITx64Impl::MacroJITx64Impl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code)
  32. : Xbyak::CodeGenerator(MAX_CODE_SIZE), code(code), maxwell3d(maxwell3d) {
  33. Compile();
  34. }
  35. MacroJITx64Impl::~MacroJITx64Impl() = default;
  36. void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) {
  37. MICROPROFILE_SCOPE(MacroJitExecute);
  38. ASSERT_OR_EXECUTE(program != nullptr, { return; });
  39. JITState state{};
  40. state.maxwell3d = &maxwell3d;
  41. state.registers = {};
  42. program(&state, parameters.data());
  43. }
  44. void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) {
  45. const bool is_a_zero = opcode.src_a == 0;
  46. const bool is_b_zero = opcode.src_b == 0;
  47. const bool valid_operation = !is_a_zero && !is_b_zero;
  48. [[maybe_unused]] const bool is_move_operation = !is_a_zero && is_b_zero;
  49. const bool has_zero_register = is_a_zero || is_b_zero;
  50. const bool no_zero_reg_skip = opcode.alu_operation == Macro::ALUOperation::AddWithCarry ||
  51. opcode.alu_operation == Macro::ALUOperation::SubtractWithBorrow;
  52. Xbyak::Reg32 src_a;
  53. Xbyak::Reg32 src_b;
  54. if (!optimizer.zero_reg_skip || no_zero_reg_skip) {
  55. src_a = Compile_GetRegister(opcode.src_a, RESULT);
  56. src_b = Compile_GetRegister(opcode.src_b, eax);
  57. } else {
  58. if (!is_a_zero) {
  59. src_a = Compile_GetRegister(opcode.src_a, RESULT);
  60. }
  61. if (!is_b_zero) {
  62. src_b = Compile_GetRegister(opcode.src_b, eax);
  63. }
  64. }
  65. bool has_emitted = false;
  66. switch (opcode.alu_operation) {
  67. case Macro::ALUOperation::Add:
  68. if (optimizer.zero_reg_skip) {
  69. if (valid_operation) {
  70. add(src_a, src_b);
  71. }
  72. } else {
  73. add(src_a, src_b);
  74. }
  75. if (!optimizer.can_skip_carry) {
  76. setc(byte[STATE + offsetof(JITState, carry_flag)]);
  77. }
  78. break;
  79. case Macro::ALUOperation::AddWithCarry:
  80. bt(dword[STATE + offsetof(JITState, carry_flag)], 0);
  81. adc(src_a, src_b);
  82. setc(byte[STATE + offsetof(JITState, carry_flag)]);
  83. break;
  84. case Macro::ALUOperation::Subtract:
  85. if (optimizer.zero_reg_skip) {
  86. if (valid_operation) {
  87. sub(src_a, src_b);
  88. has_emitted = true;
  89. }
  90. } else {
  91. sub(src_a, src_b);
  92. has_emitted = true;
  93. }
  94. if (!optimizer.can_skip_carry && has_emitted) {
  95. setc(byte[STATE + offsetof(JITState, carry_flag)]);
  96. }
  97. break;
  98. case Macro::ALUOperation::SubtractWithBorrow:
  99. bt(dword[STATE + offsetof(JITState, carry_flag)], 0);
  100. sbb(src_a, src_b);
  101. setc(byte[STATE + offsetof(JITState, carry_flag)]);
  102. break;
  103. case Macro::ALUOperation::Xor:
  104. if (optimizer.zero_reg_skip) {
  105. if (valid_operation) {
  106. xor_(src_a, src_b);
  107. }
  108. } else {
  109. xor_(src_a, src_b);
  110. }
  111. break;
  112. case Macro::ALUOperation::Or:
  113. if (optimizer.zero_reg_skip) {
  114. if (valid_operation) {
  115. or_(src_a, src_b);
  116. }
  117. } else {
  118. or_(src_a, src_b);
  119. }
  120. break;
  121. case Macro::ALUOperation::And:
  122. if (optimizer.zero_reg_skip) {
  123. if (!has_zero_register) {
  124. and_(src_a, src_b);
  125. }
  126. } else {
  127. and_(src_a, src_b);
  128. }
  129. break;
  130. case Macro::ALUOperation::AndNot:
  131. if (optimizer.zero_reg_skip) {
  132. if (!is_a_zero) {
  133. not_(src_b);
  134. and_(src_a, src_b);
  135. }
  136. } else {
  137. not_(src_b);
  138. and_(src_a, src_b);
  139. }
  140. break;
  141. case Macro::ALUOperation::Nand:
  142. if (optimizer.zero_reg_skip) {
  143. if (!is_a_zero) {
  144. and_(src_a, src_b);
  145. not_(src_a);
  146. }
  147. } else {
  148. and_(src_a, src_b);
  149. not_(src_a);
  150. }
  151. break;
  152. default:
  153. UNIMPLEMENTED_MSG("Unimplemented ALU operation {}",
  154. static_cast<std::size_t>(opcode.alu_operation.Value()));
  155. break;
  156. }
  157. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  158. }
  159. void MacroJITx64Impl::Compile_AddImmediate(Macro::Opcode opcode) {
  160. if (optimizer.skip_dummy_addimmediate) {
  161. // Games tend to use this as an exit instruction placeholder. It's to encode an instruction
  162. // without doing anything. In our case we can just not emit anything.
  163. if (opcode.result_operation == Macro::ResultOperation::Move && opcode.dst == 0) {
  164. return;
  165. }
  166. }
  167. // Check for redundant moves
  168. if (optimizer.optimize_for_method_move &&
  169. opcode.result_operation == Macro::ResultOperation::MoveAndSetMethod) {
  170. if (next_opcode.has_value()) {
  171. const auto next = *next_opcode;
  172. if (next.result_operation == Macro::ResultOperation::MoveAndSetMethod &&
  173. opcode.dst == next.dst) {
  174. return;
  175. }
  176. }
  177. }
  178. if (optimizer.zero_reg_skip && opcode.src_a == 0) {
  179. if (opcode.immediate == 0) {
  180. xor_(RESULT, RESULT);
  181. } else {
  182. mov(RESULT, opcode.immediate);
  183. }
  184. } else {
  185. auto result = Compile_GetRegister(opcode.src_a, RESULT);
  186. if (opcode.immediate > 2) {
  187. add(result, opcode.immediate);
  188. } else if (opcode.immediate == 1) {
  189. inc(result);
  190. } else if (opcode.immediate < 0) {
  191. sub(result, opcode.immediate * -1);
  192. }
  193. }
  194. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  195. }
  196. void MacroJITx64Impl::Compile_ExtractInsert(Macro::Opcode opcode) {
  197. auto dst = Compile_GetRegister(opcode.src_a, RESULT);
  198. auto src = Compile_GetRegister(opcode.src_b, eax);
  199. if (opcode.bf_src_bit != 0 && opcode.bf_src_bit != 31) {
  200. shr(src, opcode.bf_src_bit);
  201. } else if (opcode.bf_src_bit == 31) {
  202. xor_(src, src);
  203. }
  204. // Don't bother masking the whole register since we're using a 32 bit register
  205. if (opcode.bf_size != 31 && opcode.bf_size != 0) {
  206. and_(src, opcode.GetBitfieldMask());
  207. } else if (opcode.bf_size == 0) {
  208. xor_(src, src);
  209. }
  210. if (opcode.bf_dst_bit != 31 && opcode.bf_dst_bit != 0) {
  211. shl(src, opcode.bf_dst_bit);
  212. } else if (opcode.bf_dst_bit == 31) {
  213. xor_(src, src);
  214. }
  215. const u32 mask = ~(opcode.GetBitfieldMask() << opcode.bf_dst_bit);
  216. if (mask != 0xffffffff) {
  217. and_(dst, mask);
  218. }
  219. or_(dst, src);
  220. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  221. }
  222. void MacroJITx64Impl::Compile_ExtractShiftLeftImmediate(Macro::Opcode opcode) {
  223. const auto dst = Compile_GetRegister(opcode.src_a, ecx);
  224. const auto src = Compile_GetRegister(opcode.src_b, RESULT);
  225. shr(src, dst.cvt8());
  226. if (opcode.bf_size != 0 && opcode.bf_size != 31) {
  227. and_(src, opcode.GetBitfieldMask());
  228. } else if (opcode.bf_size == 0) {
  229. xor_(src, src);
  230. }
  231. if (opcode.bf_dst_bit != 0 && opcode.bf_dst_bit != 31) {
  232. shl(src, opcode.bf_dst_bit);
  233. } else if (opcode.bf_dst_bit == 31) {
  234. xor_(src, src);
  235. }
  236. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  237. }
  238. void MacroJITx64Impl::Compile_ExtractShiftLeftRegister(Macro::Opcode opcode) {
  239. const auto dst = Compile_GetRegister(opcode.src_a, ecx);
  240. const auto src = Compile_GetRegister(opcode.src_b, RESULT);
  241. if (opcode.bf_src_bit != 0) {
  242. shr(src, opcode.bf_src_bit);
  243. }
  244. if (opcode.bf_size != 31) {
  245. and_(src, opcode.GetBitfieldMask());
  246. }
  247. shl(src, dst.cvt8());
  248. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  249. }
  250. void MacroJITx64Impl::Compile_Read(Macro::Opcode opcode) {
  251. if (optimizer.zero_reg_skip && opcode.src_a == 0) {
  252. if (opcode.immediate == 0) {
  253. xor_(RESULT, RESULT);
  254. } else {
  255. mov(RESULT, opcode.immediate);
  256. }
  257. } else {
  258. auto result = Compile_GetRegister(opcode.src_a, RESULT);
  259. if (opcode.immediate > 2) {
  260. add(result, opcode.immediate);
  261. } else if (opcode.immediate == 1) {
  262. inc(result);
  263. } else if (opcode.immediate < 0) {
  264. sub(result, opcode.immediate * -1);
  265. }
  266. }
  267. // Equivalent to Engines::Maxwell3D::GetRegisterValue:
  268. if (optimizer.enable_asserts) {
  269. Xbyak::Label pass_range_check;
  270. cmp(RESULT, static_cast<u32>(Engines::Maxwell3D::Regs::NUM_REGS));
  271. jb(pass_range_check);
  272. int3();
  273. L(pass_range_check);
  274. }
  275. mov(rax, qword[STATE]);
  276. mov(RESULT,
  277. dword[rax + offsetof(Engines::Maxwell3D, regs) +
  278. offsetof(Engines::Maxwell3D::Regs, reg_array) + RESULT.cvt64() * sizeof(u32)]);
  279. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  280. }
  281. static void Send(Engines::Maxwell3D* maxwell3d, Macro::MethodAddress method_address, u32 value) {
  282. maxwell3d->CallMethodFromMME(method_address.address, value);
  283. }
  284. void Tegra::MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) {
  285. Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  286. mov(Common::X64::ABI_PARAM1, qword[STATE]);
  287. mov(Common::X64::ABI_PARAM2, METHOD_ADDRESS);
  288. mov(Common::X64::ABI_PARAM3, value);
  289. Common::X64::CallFarFunction(*this, &Send);
  290. Common::X64::ABI_PopRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  291. Xbyak::Label dont_process{};
  292. // Get increment
  293. test(METHOD_ADDRESS, 0x3f000);
  294. // If zero, method address doesn't update
  295. je(dont_process);
  296. mov(ecx, METHOD_ADDRESS);
  297. and_(METHOD_ADDRESS, 0xfff);
  298. shr(ecx, 12);
  299. and_(ecx, 0x3f);
  300. lea(eax, ptr[rcx + METHOD_ADDRESS.cvt64()]);
  301. sal(ecx, 12);
  302. or_(eax, ecx);
  303. mov(METHOD_ADDRESS, eax);
  304. L(dont_process);
  305. }
  306. void Tegra::MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
  307. ASSERT_MSG(!is_delay_slot, "Executing a branch in a delay slot is not valid");
  308. const s32 jump_address =
  309. static_cast<s32>(pc) + static_cast<s32>(opcode.GetBranchTarget() / sizeof(s32));
  310. Xbyak::Label end;
  311. auto value = Compile_GetRegister(opcode.src_a, eax);
  312. test(value, value);
  313. if (optimizer.has_delayed_pc) {
  314. switch (opcode.branch_condition) {
  315. case Macro::BranchCondition::Zero:
  316. jne(end, T_NEAR);
  317. break;
  318. case Macro::BranchCondition::NotZero:
  319. je(end, T_NEAR);
  320. break;
  321. }
  322. if (opcode.branch_annul) {
  323. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  324. jmp(labels[jump_address], T_NEAR);
  325. } else {
  326. Xbyak::Label handle_post_exit{};
  327. Xbyak::Label skip{};
  328. jmp(skip, T_NEAR);
  329. if (opcode.is_exit) {
  330. L(handle_post_exit);
  331. // Execute 1 instruction
  332. mov(BRANCH_HOLDER, end_of_code);
  333. // Jump to next instruction to skip delay slot check
  334. jmp(labels[jump_address], T_NEAR);
  335. } else {
  336. L(handle_post_exit);
  337. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  338. jmp(labels[jump_address], T_NEAR);
  339. }
  340. L(skip);
  341. mov(BRANCH_HOLDER, handle_post_exit);
  342. jmp(delay_skip[pc], T_NEAR);
  343. }
  344. } else {
  345. switch (opcode.branch_condition) {
  346. case Macro::BranchCondition::Zero:
  347. je(labels[jump_address], T_NEAR);
  348. break;
  349. case Macro::BranchCondition::NotZero:
  350. jne(labels[jump_address], T_NEAR);
  351. break;
  352. }
  353. }
  354. L(end);
  355. }
  356. void Tegra::MacroJITx64Impl::Optimizer_ScanFlags() {
  357. optimizer.can_skip_carry = true;
  358. optimizer.has_delayed_pc = false;
  359. for (auto raw_op : code) {
  360. Macro::Opcode op{};
  361. op.raw = raw_op;
  362. if (op.operation == Macro::Operation::ALU) {
  363. // Scan for any ALU operations which actually use the carry flag, if they don't exist in
  364. // our current code we can skip emitting the carry flag handling operations
  365. if (op.alu_operation == Macro::ALUOperation::AddWithCarry ||
  366. op.alu_operation == Macro::ALUOperation::SubtractWithBorrow) {
  367. optimizer.can_skip_carry = false;
  368. }
  369. }
  370. if (op.operation == Macro::Operation::Branch) {
  371. if (!op.branch_annul) {
  372. optimizer.has_delayed_pc = true;
  373. }
  374. }
  375. }
  376. }
  377. void MacroJITx64Impl::Compile() {
  378. MICROPROFILE_SCOPE(MacroJitCompile);
  379. labels.fill(Xbyak::Label());
  380. Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  381. // JIT state
  382. mov(STATE, Common::X64::ABI_PARAM1);
  383. mov(PARAMETERS, Common::X64::ABI_PARAM2);
  384. xor_(RESULT, RESULT);
  385. xor_(METHOD_ADDRESS, METHOD_ADDRESS);
  386. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  387. mov(dword[STATE + offsetof(JITState, registers) + 4], Compile_FetchParameter());
  388. // Track get register for zero registers and mark it as no-op
  389. optimizer.zero_reg_skip = true;
  390. // AddImmediate tends to be used as a NOP instruction, if we detect this we can
  391. // completely skip the entire code path and no emit anything
  392. optimizer.skip_dummy_addimmediate = true;
  393. // SMO tends to emit a lot of unnecessary method moves, we can mitigate this by only emitting
  394. // one if our register isn't "dirty"
  395. optimizer.optimize_for_method_move = true;
  396. // Enable run-time assertions in JITted code
  397. optimizer.enable_asserts = false;
  398. // Check to see if we can skip emitting certain instructions
  399. Optimizer_ScanFlags();
  400. const u32 op_count = static_cast<u32>(code.size());
  401. for (u32 i = 0; i < op_count; i++) {
  402. if (i < op_count - 1) {
  403. pc = i + 1;
  404. next_opcode = GetOpCode();
  405. } else {
  406. next_opcode = {};
  407. }
  408. pc = i;
  409. Compile_NextInstruction();
  410. }
  411. L(end_of_code);
  412. Common::X64::ABI_PopRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  413. ret();
  414. ready();
  415. program = getCode<ProgramType>();
  416. }
  417. bool MacroJITx64Impl::Compile_NextInstruction() {
  418. const auto opcode = GetOpCode();
  419. if (labels[pc].getAddress()) {
  420. return false;
  421. }
  422. L(labels[pc]);
  423. switch (opcode.operation) {
  424. case Macro::Operation::ALU:
  425. Compile_ALU(opcode);
  426. break;
  427. case Macro::Operation::AddImmediate:
  428. Compile_AddImmediate(opcode);
  429. break;
  430. case Macro::Operation::ExtractInsert:
  431. Compile_ExtractInsert(opcode);
  432. break;
  433. case Macro::Operation::ExtractShiftLeftImmediate:
  434. Compile_ExtractShiftLeftImmediate(opcode);
  435. break;
  436. case Macro::Operation::ExtractShiftLeftRegister:
  437. Compile_ExtractShiftLeftRegister(opcode);
  438. break;
  439. case Macro::Operation::Read:
  440. Compile_Read(opcode);
  441. break;
  442. case Macro::Operation::Branch:
  443. Compile_Branch(opcode);
  444. break;
  445. default:
  446. UNIMPLEMENTED_MSG("Unimplemented opcode {}", opcode.operation.Value());
  447. break;
  448. }
  449. if (optimizer.has_delayed_pc) {
  450. if (opcode.is_exit) {
  451. mov(rax, end_of_code);
  452. test(BRANCH_HOLDER, BRANCH_HOLDER);
  453. cmove(BRANCH_HOLDER, rax);
  454. // Jump to next instruction to skip delay slot check
  455. je(labels[pc + 1], T_NEAR);
  456. } else {
  457. // TODO(ogniK): Optimize delay slot branching
  458. Xbyak::Label no_delay_slot{};
  459. test(BRANCH_HOLDER, BRANCH_HOLDER);
  460. je(no_delay_slot, T_NEAR);
  461. mov(rax, BRANCH_HOLDER);
  462. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  463. jmp(rax);
  464. L(no_delay_slot);
  465. }
  466. L(delay_skip[pc]);
  467. if (opcode.is_exit) {
  468. return false;
  469. }
  470. } else {
  471. test(BRANCH_HOLDER, BRANCH_HOLDER);
  472. jne(end_of_code, T_NEAR);
  473. if (opcode.is_exit) {
  474. inc(BRANCH_HOLDER);
  475. return false;
  476. }
  477. }
  478. return true;
  479. }
  480. Xbyak::Reg32 Tegra::MacroJITx64Impl::Compile_FetchParameter() {
  481. mov(eax, dword[PARAMETERS]);
  482. add(PARAMETERS, sizeof(u32));
  483. return eax;
  484. }
  485. Xbyak::Reg32 MacroJITx64Impl::Compile_GetRegister(u32 index, Xbyak::Reg32 dst) {
  486. if (index == 0) {
  487. // Register 0 is always zero
  488. xor_(dst, dst);
  489. } else {
  490. mov(dst, dword[STATE + offsetof(JITState, registers) + index * sizeof(u32)]);
  491. }
  492. return dst;
  493. }
  494. void MacroJITx64Impl::Compile_ProcessResult(Macro::ResultOperation operation, u32 reg) {
  495. const auto SetRegister = [this](u32 reg, const Xbyak::Reg32& result) {
  496. // Register 0 is supposed to always return 0. NOP is implemented as a store to the zero
  497. // register.
  498. if (reg == 0) {
  499. return;
  500. }
  501. mov(dword[STATE + offsetof(JITState, registers) + reg * sizeof(u32)], result);
  502. };
  503. const auto SetMethodAddress = [this](const Xbyak::Reg32& reg) { mov(METHOD_ADDRESS, reg); };
  504. switch (operation) {
  505. case Macro::ResultOperation::IgnoreAndFetch:
  506. SetRegister(reg, Compile_FetchParameter());
  507. break;
  508. case Macro::ResultOperation::Move:
  509. SetRegister(reg, RESULT);
  510. break;
  511. case Macro::ResultOperation::MoveAndSetMethod:
  512. SetRegister(reg, RESULT);
  513. SetMethodAddress(RESULT);
  514. break;
  515. case Macro::ResultOperation::FetchAndSend:
  516. // Fetch parameter and send result.
  517. SetRegister(reg, Compile_FetchParameter());
  518. Compile_Send(RESULT);
  519. break;
  520. case Macro::ResultOperation::MoveAndSend:
  521. // Move and send result.
  522. SetRegister(reg, RESULT);
  523. Compile_Send(RESULT);
  524. break;
  525. case Macro::ResultOperation::FetchAndSetMethod:
  526. // Fetch parameter and use result as Method Address.
  527. SetRegister(reg, Compile_FetchParameter());
  528. SetMethodAddress(RESULT);
  529. break;
  530. case Macro::ResultOperation::MoveAndSetMethodFetchAndSend:
  531. // Move result and use as Method Address, then fetch and send parameter.
  532. SetRegister(reg, RESULT);
  533. SetMethodAddress(RESULT);
  534. Compile_Send(Compile_FetchParameter());
  535. break;
  536. case Macro::ResultOperation::MoveAndSetMethodSend:
  537. // Move result and use as Method Address, then send bits 12:17 of result.
  538. SetRegister(reg, RESULT);
  539. SetMethodAddress(RESULT);
  540. shr(RESULT, 12);
  541. and_(RESULT, 0b111111);
  542. Compile_Send(RESULT);
  543. break;
  544. default:
  545. UNIMPLEMENTED_MSG("Unimplemented macro operation {}", static_cast<std::size_t>(operation));
  546. }
  547. }
  548. Macro::Opcode MacroJITx64Impl::GetOpCode() const {
  549. ASSERT(pc < code.size());
  550. return {code[pc]};
  551. }
  552. std::bitset<32> MacroJITx64Impl::PersistentCallerSavedRegs() const {
  553. return PERSISTENT_REGISTERS & Common::X64::ABI_ALL_CALLER_SAVED;
  554. }
  555. } // namespace Tegra