macro_jit_x64.cpp 19 KB

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