macro_jit_x64.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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::Reg64 NEXT_PARAMETER = Xbyak::util::r13;
  18. static const Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d;
  19. static const Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15;
  20. static const std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({
  21. STATE,
  22. RESULT,
  23. PARAMETERS,
  24. NEXT_PARAMETER,
  25. METHOD_ADDRESS,
  26. BRANCH_HOLDER,
  27. });
  28. MacroJITx64::MacroJITx64(Engines::Maxwell3D& maxwell3d) : maxwell3d(maxwell3d) {}
  29. std::unique_ptr<CachedMacro> MacroJITx64::Compile(const std::vector<u32>& code) {
  30. return std::make_unique<MacroJITx64Impl>(maxwell3d, code);
  31. }
  32. MacroJITx64Impl::MacroJITx64Impl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code)
  33. : Xbyak::CodeGenerator(MAX_CODE_SIZE), code(code), maxwell3d(maxwell3d) {
  34. Compile();
  35. }
  36. MacroJITx64Impl::~MacroJITx64Impl() = default;
  37. void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) {
  38. MICROPROFILE_SCOPE(MacroJitExecute);
  39. ASSERT_OR_EXECUTE(program != nullptr, { return; });
  40. JITState state{};
  41. state.maxwell3d = &maxwell3d;
  42. state.registers = {};
  43. program(&state, parameters.data());
  44. }
  45. void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) {
  46. const bool is_a_zero = opcode.src_a == 0;
  47. const bool is_b_zero = opcode.src_b == 0;
  48. const bool valid_operation = !is_a_zero && !is_b_zero;
  49. const bool is_move_operation = !is_a_zero && is_b_zero;
  50. const bool has_zero_register = is_a_zero || is_b_zero;
  51. Xbyak::Reg32 src_a;
  52. Xbyak::Reg32 src_b;
  53. if (!optimizer.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. return;
  174. }
  175. }
  176. }
  177. if (optimizer.zero_reg_skip && opcode.src_a == 0) {
  178. if (opcode.immediate == 0) {
  179. xor_(RESULT, RESULT);
  180. } else {
  181. mov(RESULT, opcode.immediate);
  182. }
  183. } else {
  184. auto result = Compile_GetRegister(opcode.src_a, RESULT);
  185. if (opcode.immediate > 2) {
  186. add(result, opcode.immediate);
  187. } else if (opcode.immediate == 1) {
  188. inc(result);
  189. } else if (opcode.immediate < 0) {
  190. sub(result, opcode.immediate * -1);
  191. }
  192. }
  193. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  194. }
  195. void MacroJITx64Impl::Compile_ExtractInsert(Macro::Opcode opcode) {
  196. auto dst = Compile_GetRegister(opcode.src_a, RESULT);
  197. auto src = Compile_GetRegister(opcode.src_b, eax);
  198. if (opcode.bf_src_bit != 0 && opcode.bf_src_bit != 31) {
  199. shr(src, opcode.bf_src_bit);
  200. } else if (opcode.bf_src_bit == 31) {
  201. xor_(src, src);
  202. }
  203. // Don't bother masking the whole register since we're using a 32 bit register
  204. if (opcode.bf_size != 31 && opcode.bf_size != 0) {
  205. and_(src, opcode.GetBitfieldMask());
  206. } else if (opcode.bf_size == 0) {
  207. xor_(src, src);
  208. }
  209. if (opcode.bf_dst_bit != 31 && opcode.bf_dst_bit != 0) {
  210. shl(src, opcode.bf_dst_bit);
  211. } else if (opcode.bf_dst_bit == 31) {
  212. xor_(src, src);
  213. }
  214. const u32 mask = ~(opcode.GetBitfieldMask() << opcode.bf_dst_bit);
  215. if (mask != 0xffffffff) {
  216. and_(dst, mask);
  217. }
  218. or_(dst, src);
  219. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  220. }
  221. void MacroJITx64Impl::Compile_ExtractShiftLeftImmediate(Macro::Opcode opcode) {
  222. auto dst = Compile_GetRegister(opcode.src_a, eax);
  223. auto src = Compile_GetRegister(opcode.src_b, RESULT);
  224. shr(src, al);
  225. if (opcode.bf_size != 0 && opcode.bf_size != 31) {
  226. and_(src, opcode.GetBitfieldMask());
  227. } else if (opcode.bf_size == 0) {
  228. xor_(src, src);
  229. }
  230. if (opcode.bf_dst_bit != 0 && opcode.bf_dst_bit != 31) {
  231. shl(src, opcode.bf_dst_bit);
  232. } else if (opcode.bf_dst_bit == 31) {
  233. xor_(src, src);
  234. }
  235. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  236. }
  237. void MacroJITx64Impl::Compile_ExtractShiftLeftRegister(Macro::Opcode opcode) {
  238. auto dst = Compile_GetRegister(opcode.src_a, eax);
  239. auto src = Compile_GetRegister(opcode.src_b, RESULT);
  240. if (opcode.bf_src_bit != 0) {
  241. shr(src, opcode.bf_src_bit);
  242. }
  243. if (opcode.bf_size != 31) {
  244. and_(src, opcode.GetBitfieldMask());
  245. }
  246. shl(src, al);
  247. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  248. }
  249. static u32 Read(Engines::Maxwell3D* maxwell3d, u32 method) {
  250. return maxwell3d->GetRegisterValue(method);
  251. }
  252. static void Send(Engines::Maxwell3D* maxwell3d, Macro::MethodAddress method_address, u32 value) {
  253. maxwell3d->CallMethodFromMME(method_address.address, value);
  254. }
  255. void MacroJITx64Impl::Compile_Read(Macro::Opcode opcode) {
  256. if (optimizer.zero_reg_skip && opcode.src_a == 0) {
  257. if (opcode.immediate == 0) {
  258. xor_(RESULT, RESULT);
  259. } else {
  260. mov(RESULT, opcode.immediate);
  261. }
  262. } else {
  263. auto result = Compile_GetRegister(opcode.src_a, RESULT);
  264. if (opcode.immediate > 2) {
  265. add(result, opcode.immediate);
  266. } else if (opcode.immediate == 1) {
  267. inc(result);
  268. } else if (opcode.immediate < 0) {
  269. sub(result, opcode.immediate * -1);
  270. }
  271. }
  272. Common::X64::ABI_PushRegistersAndAdjustStackGPS(*this, PersistentCallerSavedRegs(), 0);
  273. mov(Common::X64::ABI_PARAM1, qword[STATE]);
  274. mov(Common::X64::ABI_PARAM2, RESULT);
  275. Common::X64::CallFarFunction(*this, &Read);
  276. Common::X64::ABI_PopRegistersAndAdjustStackGPS(*this, PersistentCallerSavedRegs(), 0);
  277. mov(RESULT, Common::X64::ABI_RETURN.cvt32());
  278. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  279. }
  280. void Tegra::MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) {
  281. Common::X64::ABI_PushRegistersAndAdjustStackGPS(*this, PersistentCallerSavedRegs(), 0);
  282. mov(Common::X64::ABI_PARAM1, qword[STATE]);
  283. mov(Common::X64::ABI_PARAM2, METHOD_ADDRESS);
  284. mov(Common::X64::ABI_PARAM3, value);
  285. Common::X64::CallFarFunction(*this, &Send);
  286. Common::X64::ABI_PopRegistersAndAdjustStackGPS(*this, PersistentCallerSavedRegs(), 0);
  287. Xbyak::Label dont_process{};
  288. // Get increment
  289. test(METHOD_ADDRESS, 0x3f000);
  290. // If zero, method address doesn't update
  291. je(dont_process);
  292. mov(ecx, METHOD_ADDRESS);
  293. and_(METHOD_ADDRESS, 0xfff);
  294. shr(ecx, 12);
  295. and_(ecx, 0x3f);
  296. lea(eax, ptr[rcx + METHOD_ADDRESS.cvt64()]);
  297. sal(ecx, 12);
  298. or_(eax, ecx);
  299. mov(METHOD_ADDRESS, eax);
  300. L(dont_process);
  301. }
  302. void Tegra::MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
  303. ASSERT_MSG(!is_delay_slot, "Executing a branch in a delay slot is not valid");
  304. const s32 jump_address =
  305. static_cast<s32>(pc) + static_cast<s32>(opcode.GetBranchTarget() / sizeof(s32));
  306. Xbyak::Label end;
  307. auto value = Compile_GetRegister(opcode.src_a, eax);
  308. test(value, value);
  309. if (optimizer.has_delayed_pc) {
  310. switch (opcode.branch_condition) {
  311. case Macro::BranchCondition::Zero:
  312. jne(end, T_NEAR);
  313. break;
  314. case Macro::BranchCondition::NotZero:
  315. je(end, T_NEAR);
  316. break;
  317. }
  318. if (opcode.branch_annul) {
  319. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  320. jmp(labels[jump_address], T_NEAR);
  321. } else {
  322. Xbyak::Label handle_post_exit{};
  323. Xbyak::Label skip{};
  324. jmp(skip, T_NEAR);
  325. if (opcode.is_exit) {
  326. L(handle_post_exit);
  327. // Execute 1 instruction
  328. mov(BRANCH_HOLDER, end_of_code);
  329. // Jump to next instruction to skip delay slot check
  330. jmp(labels[jump_address], T_NEAR);
  331. } else {
  332. L(handle_post_exit);
  333. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  334. jmp(labels[jump_address], T_NEAR);
  335. }
  336. L(skip);
  337. mov(BRANCH_HOLDER, handle_post_exit);
  338. jmp(delay_skip[pc], T_NEAR);
  339. }
  340. } else {
  341. switch (opcode.branch_condition) {
  342. case Macro::BranchCondition::Zero:
  343. je(labels[jump_address], T_NEAR);
  344. break;
  345. case Macro::BranchCondition::NotZero:
  346. jne(labels[jump_address], T_NEAR);
  347. break;
  348. }
  349. }
  350. L(end);
  351. }
  352. void Tegra::MacroJITx64Impl::Optimizer_ScanFlags() {
  353. optimizer.can_skip_carry = true;
  354. optimizer.has_delayed_pc = false;
  355. for (auto raw_op : code) {
  356. Macro::Opcode op{};
  357. op.raw = raw_op;
  358. if (op.operation == Macro::Operation::ALU) {
  359. // Scan for any ALU operations which actually use the carry flag, if they don't exist in
  360. // our current code we can skip emitting the carry flag handling operations
  361. if (op.alu_operation == Macro::ALUOperation::AddWithCarry ||
  362. op.alu_operation == Macro::ALUOperation::SubtractWithBorrow) {
  363. optimizer.can_skip_carry = false;
  364. }
  365. }
  366. if (op.operation == Macro::Operation::Branch) {
  367. if (!op.branch_annul) {
  368. optimizer.has_delayed_pc = true;
  369. }
  370. }
  371. }
  372. }
  373. void MacroJITx64Impl::Compile() {
  374. MICROPROFILE_SCOPE(MacroJitCompile);
  375. bool keep_executing = true;
  376. labels.fill(Xbyak::Label());
  377. Common::X64::ABI_PushRegistersAndAdjustStackGPS(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  378. // JIT state
  379. mov(STATE, Common::X64::ABI_PARAM1);
  380. mov(PARAMETERS, Common::X64::ABI_PARAM2);
  381. xor_(RESULT, RESULT);
  382. xor_(METHOD_ADDRESS, METHOD_ADDRESS);
  383. xor_(NEXT_PARAMETER, NEXT_PARAMETER);
  384. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  385. mov(dword[STATE + offsetof(JITState, registers) + 4], Compile_FetchParameter());
  386. // Track get register for zero registers and mark it as no-op
  387. optimizer.zero_reg_skip = true;
  388. // AddImmediate tends to be used as a NOP instruction, if we detect this we can
  389. // completely skip the entire code path and no emit anything
  390. optimizer.skip_dummy_addimmediate = true;
  391. // SMO tends to emit a lot of unnecessary method moves, we can mitigate this by only emitting
  392. // one if our register isn't "dirty"
  393. optimizer.optimize_for_method_move = true;
  394. // Check to see if we can skip emitting certain instructions
  395. Optimizer_ScanFlags();
  396. const u32 op_count = static_cast<u32>(code.size());
  397. for (u32 i = 0; i < op_count; i++) {
  398. if (i < op_count - 1) {
  399. pc = i + 1;
  400. next_opcode = GetOpCode();
  401. } else {
  402. next_opcode = {};
  403. }
  404. pc = i;
  405. Compile_NextInstruction();
  406. }
  407. L(end_of_code);
  408. Common::X64::ABI_PopRegistersAndAdjustStackGPS(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  409. ret();
  410. ready();
  411. program = getCode<ProgramType>();
  412. }
  413. bool MacroJITx64Impl::Compile_NextInstruction() {
  414. const auto opcode = GetOpCode();
  415. if (labels[pc].getAddress()) {
  416. return false;
  417. }
  418. L(labels[pc]);
  419. switch (opcode.operation) {
  420. case Macro::Operation::ALU:
  421. Compile_ALU(opcode);
  422. break;
  423. case Macro::Operation::AddImmediate:
  424. Compile_AddImmediate(opcode);
  425. break;
  426. case Macro::Operation::ExtractInsert:
  427. Compile_ExtractInsert(opcode);
  428. break;
  429. case Macro::Operation::ExtractShiftLeftImmediate:
  430. Compile_ExtractShiftLeftImmediate(opcode);
  431. break;
  432. case Macro::Operation::ExtractShiftLeftRegister:
  433. Compile_ExtractShiftLeftRegister(opcode);
  434. break;
  435. case Macro::Operation::Read:
  436. Compile_Read(opcode);
  437. break;
  438. case Macro::Operation::Branch:
  439. Compile_Branch(opcode);
  440. break;
  441. default:
  442. UNIMPLEMENTED_MSG("Unimplemented opcode {}", opcode.operation.Value());
  443. break;
  444. }
  445. if (optimizer.has_delayed_pc) {
  446. if (opcode.is_exit) {
  447. mov(rax, end_of_code);
  448. test(BRANCH_HOLDER, BRANCH_HOLDER);
  449. cmove(BRANCH_HOLDER, rax);
  450. // Jump to next instruction to skip delay slot check
  451. je(labels[pc + 1], T_NEAR);
  452. } else {
  453. // TODO(ogniK): Optimize delay slot branching
  454. Xbyak::Label no_delay_slot{};
  455. test(BRANCH_HOLDER, BRANCH_HOLDER);
  456. je(no_delay_slot, T_NEAR);
  457. mov(rax, BRANCH_HOLDER);
  458. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  459. jmp(rax);
  460. L(no_delay_slot);
  461. }
  462. L(delay_skip[pc]);
  463. if (opcode.is_exit) {
  464. return false;
  465. }
  466. } else {
  467. test(BRANCH_HOLDER, BRANCH_HOLDER);
  468. jne(end_of_code, T_NEAR);
  469. if (opcode.is_exit) {
  470. inc(BRANCH_HOLDER);
  471. return false;
  472. }
  473. }
  474. return true;
  475. }
  476. Xbyak::Reg32 Tegra::MacroJITx64Impl::Compile_FetchParameter() {
  477. mov(eax, dword[PARAMETERS + NEXT_PARAMETER * sizeof(u32)]);
  478. inc(NEXT_PARAMETER);
  479. return eax;
  480. }
  481. Xbyak::Reg32 MacroJITx64Impl::Compile_GetRegister(u32 index, Xbyak::Reg32 dst) {
  482. if (index == 0) {
  483. // Register 0 is always zero
  484. xor_(dst, dst);
  485. } else {
  486. mov(dst, dword[STATE + offsetof(JITState, registers) + index * sizeof(u32)]);
  487. }
  488. return dst;
  489. }
  490. void MacroJITx64Impl::Compile_ProcessResult(Macro::ResultOperation operation, u32 reg) {
  491. auto SetRegister = [=](u32 reg, Xbyak::Reg32 result) {
  492. // Register 0 is supposed to always return 0. NOP is implemented as a store to the zero
  493. // register.
  494. if (reg == 0) {
  495. return;
  496. }
  497. mov(dword[STATE + offsetof(JITState, registers) + reg * sizeof(u32)], result);
  498. };
  499. auto SetMethodAddress = [=](Xbyak::Reg32 reg) { mov(METHOD_ADDRESS, reg); };
  500. switch (operation) {
  501. case Macro::ResultOperation::IgnoreAndFetch:
  502. SetRegister(reg, Compile_FetchParameter());
  503. break;
  504. case Macro::ResultOperation::Move:
  505. SetRegister(reg, RESULT);
  506. break;
  507. case Macro::ResultOperation::MoveAndSetMethod:
  508. SetRegister(reg, RESULT);
  509. SetMethodAddress(RESULT);
  510. break;
  511. case Macro::ResultOperation::FetchAndSend:
  512. // Fetch parameter and send result.
  513. SetRegister(reg, Compile_FetchParameter());
  514. Compile_Send(RESULT);
  515. break;
  516. case Macro::ResultOperation::MoveAndSend:
  517. // Move and send result.
  518. SetRegister(reg, RESULT);
  519. Compile_Send(RESULT);
  520. break;
  521. case Macro::ResultOperation::FetchAndSetMethod:
  522. // Fetch parameter and use result as Method Address.
  523. SetRegister(reg, Compile_FetchParameter());
  524. SetMethodAddress(RESULT);
  525. break;
  526. case Macro::ResultOperation::MoveAndSetMethodFetchAndSend:
  527. // Move result and use as Method Address, then fetch and send parameter.
  528. SetRegister(reg, RESULT);
  529. SetMethodAddress(RESULT);
  530. Compile_Send(Compile_FetchParameter());
  531. break;
  532. case Macro::ResultOperation::MoveAndSetMethodSend:
  533. // Move result and use as Method Address, then send bits 12:17 of result.
  534. SetRegister(reg, RESULT);
  535. SetMethodAddress(RESULT);
  536. shr(RESULT, 12);
  537. and_(RESULT, 0b111111);
  538. Compile_Send(RESULT);
  539. break;
  540. default:
  541. UNIMPLEMENTED_MSG("Unimplemented macro operation {}", static_cast<std::size_t>(operation));
  542. }
  543. }
  544. Macro::Opcode MacroJITx64Impl::GetOpCode() const {
  545. ASSERT(pc < code.size());
  546. return {code[pc]};
  547. }
  548. std::bitset<32> MacroJITx64Impl::PersistentCallerSavedRegs() const {
  549. return PERSISTENT_REGISTERS & Common::X64::ABI_ALL_CALLER_SAVED;
  550. }
  551. } // namespace Tegra