MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / emit_muldiv

Method emit_muldiv

src/cgenerator.cpp:512–543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510}
511
512void N64Recomp::CGenerator::emit_muldiv(InstrId instr_id, int reg1, int reg2) const {
513 switch (instr_id) {
514 case InstrId::cpu_mult:
515 fmt::print(output_file, "result = S64(S32({})) * S64(S32({})); lo = S32(result >> 0); hi = S32(result >> 32);\n", gpr_to_string(reg1), gpr_to_string(reg2));
516 break;
517 case InstrId::cpu_dmult:
518 fmt::print(output_file, "DMULT(S64({}), S64({}), &lo, &hi);\n", gpr_to_string(reg1), gpr_to_string(reg2));
519 break;
520 case InstrId::cpu_multu:
521 fmt::print(output_file, "result = U64(U32({})) * U64(U32({})); lo = S32(result >> 0); hi = S32(result >> 32);\n", gpr_to_string(reg1), gpr_to_string(reg2));
522 break;
523 case InstrId::cpu_dmultu:
524 fmt::print(output_file, "DMULTU(U64({}), U64({}), &lo, &hi);\n", gpr_to_string(reg1), gpr_to_string(reg2));
525 break;
526 case InstrId::cpu_div:
527 // Cast to 64-bits before division to prevent artihmetic exception for s32(0x80000000) / -1
528 fmt::print(output_file, "lo = S32(S64(S32({0})) / S64(S32({1}))); hi = S32(S64(S32({0})) % S64(S32({1})));\n", gpr_to_string(reg1), gpr_to_string(reg2));
529 break;
530 case InstrId::cpu_ddiv:
531 fmt::print(output_file, "DDIV(S64({}), S64({}), &lo, &hi);\n", gpr_to_string(reg1), gpr_to_string(reg2));
532 break;
533 case InstrId::cpu_divu:
534 fmt::print(output_file, "lo = S32(U32({0}) / U32({1})); hi = S32(U32({0}) % U32({1}));\n", gpr_to_string(reg1), gpr_to_string(reg2));
535 break;
536 case InstrId::cpu_ddivu:
537 fmt::print(output_file, "DDIVU(U64({}), U64({}), &lo, &hi);\n", gpr_to_string(reg1), gpr_to_string(reg2));
538 break;
539 default:
540 assert(false);
541 break;
542 }
543}
544
545void N64Recomp::CGenerator::emit_syscall(uint32_t instr_vram) const {
546 fmt::print(output_file, "recomp_syscall_handler(rdram, ctx, 0x{:08X});\n", instr_vram);

Callers 1

process_instructionFunction · 0.45

Calls 1

gpr_to_stringFunction · 0.85

Tested by

no test coverage detected