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::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. static u32 Read(Engines::Maxwell3D* maxwell3d, u32 method) {
  251. return maxwell3d->GetRegisterValue(method);
  252. }
  253. static void Send(Engines::Maxwell3D* maxwell3d, Macro::MethodAddress method_address, u32 value) {
  254. maxwell3d->CallMethodFromMME(method_address.address, value);
  255. }
  256. void MacroJITx64Impl::Compile_Read(Macro::Opcode opcode) {
  257. if (optimizer.zero_reg_skip && opcode.src_a == 0) {
  258. if (opcode.immediate == 0) {
  259. xor_(RESULT, RESULT);
  260. } else {
  261. mov(RESULT, opcode.immediate);
  262. }
  263. } else {
  264. auto result = Compile_GetRegister(opcode.src_a, RESULT);
  265. if (opcode.immediate > 2) {
  266. add(result, opcode.immediate);
  267. } else if (opcode.immediate == 1) {
  268. inc(result);
  269. } else if (opcode.immediate < 0) {
  270. sub(result, opcode.immediate * -1);
  271. }
  272. }
  273. Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  274. mov(Common::X64::ABI_PARAM1, qword[STATE]);
  275. mov(Common::X64::ABI_PARAM2, RESULT);
  276. Common::X64::CallFarFunction(*this, &Read);
  277. Common::X64::ABI_PopRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  278. mov(RESULT, Common::X64::ABI_RETURN.cvt32());
  279. Compile_ProcessResult(opcode.result_operation, opcode.dst);
  280. }
  281. void Tegra::MacroJITx64Impl::Compile_Send(Xbyak::Reg32 value) {
  282. Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  283. mov(Common::X64::ABI_PARAM1, qword[STATE]);
  284. mov(Common::X64::ABI_PARAM2, METHOD_ADDRESS);
  285. mov(Common::X64::ABI_PARAM3, value);
  286. Common::X64::CallFarFunction(*this, &Send);
  287. Common::X64::ABI_PopRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0);
  288. Xbyak::Label dont_process{};
  289. // Get increment
  290. test(METHOD_ADDRESS, 0x3f000);
  291. // If zero, method address doesn't update
  292. je(dont_process);
  293. mov(ecx, METHOD_ADDRESS);
  294. and_(METHOD_ADDRESS, 0xfff);
  295. shr(ecx, 12);
  296. and_(ecx, 0x3f);
  297. lea(eax, ptr[rcx + METHOD_ADDRESS.cvt64()]);
  298. sal(ecx, 12);
  299. or_(eax, ecx);
  300. mov(METHOD_ADDRESS, eax);
  301. L(dont_process);
  302. }
  303. void Tegra::MacroJITx64Impl::Compile_Branch(Macro::Opcode opcode) {
  304. ASSERT_MSG(!is_delay_slot, "Executing a branch in a delay slot is not valid");
  305. const s32 jump_address =
  306. static_cast<s32>(pc) + static_cast<s32>(opcode.GetBranchTarget() / sizeof(s32));
  307. Xbyak::Label end;
  308. auto value = Compile_GetRegister(opcode.src_a, eax);
  309. test(value, value);
  310. if (optimizer.has_delayed_pc) {
  311. switch (opcode.branch_condition) {
  312. case Macro::BranchCondition::Zero:
  313. jne(end, T_NEAR);
  314. break;
  315. case Macro::BranchCondition::NotZero:
  316. je(end, T_NEAR);
  317. break;
  318. }
  319. if (opcode.branch_annul) {
  320. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  321. jmp(labels[jump_address], T_NEAR);
  322. } else {
  323. Xbyak::Label handle_post_exit{};
  324. Xbyak::Label skip{};
  325. jmp(skip, T_NEAR);
  326. if (opcode.is_exit) {
  327. L(handle_post_exit);
  328. // Execute 1 instruction
  329. mov(BRANCH_HOLDER, end_of_code);
  330. // Jump to next instruction to skip delay slot check
  331. jmp(labels[jump_address], T_NEAR);
  332. } else {
  333. L(handle_post_exit);
  334. xor_(BRANCH_HOLDER, BRANCH_HOLDER);
  335. jmp(labels[jump_address], T_NEAR);
  336. }
  337. L(skip);
  338. mov(BRANCH_HOLDER, handle_post_exit);
  339. jmp(delay_skip[pc], T_NEAR);
  340. }
  341. } else {
  342. switch (opcode.branch_condition) {
  343. case Macro::BranchCondition::Zero:
  344. je(labels[jump_address], T_NEAR);
  345. break;
  346. case Macro::BranchCondition::NotZero:
  347. jne(labels[jump_address], T_NEAR);
  348. break;
  349. }
  350. }
  351. L(end);
  352. }
  353. void Tegra::MacroJITx64Impl::Optimizer_ScanFlags() {
  354. optimizer.can_skip_carry = true;
  355. optimizer.has_delayed_pc = false;
  356. for (auto raw_op : code) {
  357. Macro::Opcode op{};
  358. op.raw = raw_op;
  359. if (op.operation == Macro::Operation::ALU) {
  360. // Scan for any ALU operations which actually use the carry flag, if they don't exist in
  361. // our current code we can skip emitting the carry flag handling operations
  362. if (op.alu_operation == Macro::ALUOperation::AddWithCarry ||
  363. op.alu_operation == Macro::ALUOperation::SubtractWithBorrow) {
  364. optimizer.can_skip_carry = false;
  365. }
  366. }
  367. if (op.operation == Macro::Operation::Branch) {
  368. if (!op.branch_annul) {
  369. optimizer.has_delayed_pc = true;
  370. }
  371. }
  372. }
  373. }
  374. void MacroJITx64Impl::Compile() {
  375. MICROPROFILE_SCOPE(MacroJitCompile);
  376. bool keep_executing = true;
  377. labels.fill(Xbyak::Label());
  378. Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
  379. // JIT state
  380. mov(STATE, Common::X64::ABI_PARAM1);
  381. mov(PARAMETERS, Common::X64::ABI_PARAM2);
  382. xor_(RESULT, RESULT);
  383. xor_(METHOD_ADDRESS, METHOD_ADDRESS);
  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_PopRegistersAndAdjustStack(*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]);
  478. add(PARAMETERS, sizeof(u32));
  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. const auto SetRegister = [this](u32 reg, const 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. const auto SetMethodAddress = [this](const 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