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) : maxwell3d(maxwell3d) {}
  27. std::unique_ptr<CachedMacro> MacroJITx64::Compile(const std::vector<u32>& code) {
  28. return std::make_unique<MacroJITx64Impl>(maxwell3d, code);
  29. }
  30. MacroJITx64Impl::MacroJITx64Impl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code)
  31. : Xbyak::CodeGenerator(MAX_CODE_SIZE), code(code), maxwell3d(maxwell3d) {
  32. Compile();
  33. }
  34. MacroJITx64Impl::~MacroJITx64Impl() = default;
  35. void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) {
  36. MICROPROFILE_SCOPE(MacroJitExecute);
  37. ASSERT_OR_EXECUTE(program != nullptr, { return; });
  38. JITState state{};
  39. state.maxwell3d = &maxwell3d;
  40. state.registers = {};
  41. program(&state, parameters.data());
  42. }
  43. void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) {
  44. const bool is_a_zero = opcode.src_a == 0;
  45. const bool is_b_zero = opcode.src_b == 0;
  46. const bool valid_operation = !is_a_zero && !is_b_zero;
  47. const bool is_move_operation = !is_a_zero && is_b_zero;
  48. const bool has_zero_register = is_a_zero || is_b_zero;
  49. const bool no_zero_reg_skip = opcode.alu_operation == Macro::ALUOperation::AddWithCarry ||
  50. opcode.alu_operation == Macro::ALUOperation::SubtractWithBorrow;
  51. Xbyak::Reg32 src_a;
  52. Xbyak::Reg32 src_b;
  53. if (!optimizer.zero_reg_skip || no_zero_reg_skip) {
  54. src_a = Compile_GetRegister(opcode.src_a, RESULT);
  55. src_b = Compile_GetRegister(opcode.src_b, eax);
  56. } else {
  57. if (!is_a_zero) {
  58. src_a = Compile_GetRegister(opcode.src_a, RESULT);
  59. }
  60. if (!is_b_zero) {
  61. src_b = Compile_GetRegister(opcode.src_b, eax);
  62. }
  63. }
  64. Xbyak::Label skip_carry{};
  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. auto dst = Compile_GetRegister(opcode.src_a, eax);
  224. auto src = Compile_GetRegister(opcode.src_b, RESULT);
  225. shr(src, al);
  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. auto dst = Compile_GetRegister(opcode.src_a, eax);
  240. 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, al);
  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. bool keep_executing = true;
  380. labels.fill(Xbyak::Label());
  381. Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  382. // JIT state
  383. mov(STATE, Common::X64::ABI_PARAM1);
  384. mov(PARAMETERS, Common::X64::ABI_PARAM2);
  385. xor_(RESULT, RESULT);
  386. xor_(METHOD_ADDRESS, METHOD_ADDRESS);
  387. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  388. mov(dword[STATE + offsetof(JITState, registers) + 4], Compile_FetchParameter());
  389. // Track get register for zero registers and mark it as no-op
  390. optimizer.zero_reg_skip = true;
  391. // AddImmediate tends to be used as a NOP instruction, if we detect this we can
  392. // completely skip the entire code path and no emit anything
  393. optimizer.skip_dummy_addimmediate = true;
  394. // SMO tends to emit a lot of unnecessary method moves, we can mitigate this by only emitting
  395. // one if our register isn't "dirty"
  396. optimizer.optimize_for_method_move = true;
  397. // Enable run-time assertions in JITted code
  398. optimizer.enable_asserts = false;
  399. // Check to see if we can skip emitting certain instructions
  400. Optimizer_ScanFlags();
  401. const u32 op_count = static_cast<u32>(code.size());
  402. for (u32 i = 0; i < op_count; i++) {
  403. if (i < op_count - 1) {
  404. pc = i + 1;
  405. next_opcode = GetOpCode();
  406. } else {
  407. next_opcode = {};
  408. }
  409. pc = i;
  410. Compile_NextInstruction();
  411. }
  412. L(end_of_code);
  413. Common::X64::ABI_PopRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  414. ret();
  415. ready();
  416. program = getCode<ProgramType>();
  417. }
  418. bool MacroJITx64Impl::Compile_NextInstruction() {
  419. const auto opcode = GetOpCode();
  420. if (labels[pc].getAddress()) {
  421. return false;
  422. }
  423. L(labels[pc]);
  424. switch (opcode.operation) {
  425. case Macro::Operation::ALU:
  426. Compile_ALU(opcode);
  427. break;
  428. case Macro::Operation::AddImmediate:
  429. Compile_AddImmediate(opcode);
  430. break;
  431. case Macro::Operation::ExtractInsert:
  432. Compile_ExtractInsert(opcode);
  433. break;
  434. case Macro::Operation::ExtractShiftLeftImmediate:
  435. Compile_ExtractShiftLeftImmediate(opcode);
  436. break;
  437. case Macro::Operation::ExtractShiftLeftRegister:
  438. Compile_ExtractShiftLeftRegister(opcode);
  439. break;
  440. case Macro::Operation::Read:
  441. Compile_Read(opcode);
  442. break;
  443. case Macro::Operation::Branch:
  444. Compile_Branch(opcode);
  445. break;
  446. default:
  447. UNIMPLEMENTED_MSG("Unimplemented opcode {}", opcode.operation.Value());
  448. break;
  449. }
  450. if (optimizer.has_delayed_pc) {
  451. if (opcode.is_exit) {
  452. mov(rax, end_of_code);
  453. test(BRANCH_HOLDER, BRANCH_HOLDER);
  454. cmove(BRANCH_HOLDER, rax);
  455. // Jump to next instruction to skip delay slot check
  456. je(labels[pc + 1], T_NEAR);
  457. } else {
  458. // TODO(ogniK): Optimize delay slot branching
  459. Xbyak::Label no_delay_slot{};
  460. test(BRANCH_HOLDER, BRANCH_HOLDER);
  461. je(no_delay_slot, T_NEAR);
  462. mov(rax, BRANCH_HOLDER);
  463. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  464. jmp(rax);
  465. L(no_delay_slot);
  466. }
  467. L(delay_skip[pc]);
  468. if (opcode.is_exit) {
  469. return false;
  470. }
  471. } else {
  472. test(BRANCH_HOLDER, BRANCH_HOLDER);
  473. jne(end_of_code, T_NEAR);
  474. if (opcode.is_exit) {
  475. inc(BRANCH_HOLDER);
  476. return false;
  477. }
  478. }
  479. return true;
  480. }
  481. Xbyak::Reg32 Tegra::MacroJITx64Impl::Compile_FetchParameter() {
  482. mov(eax, dword[PARAMETERS]);
  483. add(PARAMETERS, sizeof(u32));
  484. return eax;
  485. }
  486. Xbyak::Reg32 MacroJITx64Impl::Compile_GetRegister(u32 index, Xbyak::Reg32 dst) {
  487. if (index == 0) {
  488. // Register 0 is always zero
  489. xor_(dst, dst);
  490. } else {
  491. mov(dst, dword[STATE + offsetof(JITState, registers) + index * sizeof(u32)]);
  492. }
  493. return dst;
  494. }
  495. void MacroJITx64Impl::Compile_ProcessResult(Macro::ResultOperation operation, u32 reg) {
  496. auto SetRegister = [=](u32 reg, Xbyak::Reg32 result) {
  497. // Register 0 is supposed to always return 0. NOP is implemented as a store to the zero
  498. // register.
  499. if (reg == 0) {
  500. return;
  501. }
  502. mov(dword[STATE + offsetof(JITState, registers) + reg * sizeof(u32)], result);
  503. };
  504. auto SetMethodAddress = [=](Xbyak::Reg32 reg) { mov(METHOD_ADDRESS, reg); };
  505. switch (operation) {
  506. case Macro::ResultOperation::IgnoreAndFetch:
  507. SetRegister(reg, Compile_FetchParameter());
  508. break;
  509. case Macro::ResultOperation::Move:
  510. SetRegister(reg, RESULT);
  511. break;
  512. case Macro::ResultOperation::MoveAndSetMethod:
  513. SetRegister(reg, RESULT);
  514. SetMethodAddress(RESULT);
  515. break;
  516. case Macro::ResultOperation::FetchAndSend:
  517. // Fetch parameter and send result.
  518. SetRegister(reg, Compile_FetchParameter());
  519. Compile_Send(RESULT);
  520. break;
  521. case Macro::ResultOperation::MoveAndSend:
  522. // Move and send result.
  523. SetRegister(reg, RESULT);
  524. Compile_Send(RESULT);
  525. break;
  526. case Macro::ResultOperation::FetchAndSetMethod:
  527. // Fetch parameter and use result as Method Address.
  528. SetRegister(reg, Compile_FetchParameter());
  529. SetMethodAddress(RESULT);
  530. break;
  531. case Macro::ResultOperation::MoveAndSetMethodFetchAndSend:
  532. // Move result and use as Method Address, then fetch and send parameter.
  533. SetRegister(reg, RESULT);
  534. SetMethodAddress(RESULT);
  535. Compile_Send(Compile_FetchParameter());
  536. break;
  537. case Macro::ResultOperation::MoveAndSetMethodSend:
  538. // Move result and use as Method Address, then send bits 12:17 of result.
  539. SetRegister(reg, RESULT);
  540. SetMethodAddress(RESULT);
  541. shr(RESULT, 12);
  542. and_(RESULT, 0b111111);
  543. Compile_Send(RESULT);
  544. break;
  545. default:
  546. UNIMPLEMENTED_MSG("Unimplemented macro operation {}", static_cast<std::size_t>(operation));
  547. }
  548. }
  549. Macro::Opcode MacroJITx64Impl::GetOpCode() const {
  550. ASSERT(pc < code.size());
  551. return {code[pc]};
  552. }
  553. std::bitset<32> MacroJITx64Impl::PersistentCallerSavedRegs() const {
  554. return PERSISTENT_REGISTERS & Common::X64::ABI_ALL_CALLER_SAVED;
  555. }
  556. } // namespace Tegra