|
3 | 3 |
|
4 | 4 | #include "Emulator/Misc/bit_cast.hpp" |
5 | 5 |
|
| 6 | +class HyperCPU::CPU::CPU_InstrImpl { |
| 7 | +public: |
| 8 | + constexpr CPU_InstrImpl() { } |
| 9 | + |
| 10 | + /* R_R implementation */ |
| 11 | + template<typename T1, typename T2, typename T3> |
| 12 | + static constexpr T3 __hcpu_cmp_rr_impl(HyperCPU::OperandContainer& op1, HyperCPU::OperandContainer& op2, CPU& cpu) { |
| 13 | + static_assert(std::is_same_v<T1, T2>); // Locked by current CPU specification |
| 14 | + |
| 15 | + return HyperALU::__hcpu_cmp( |
| 16 | + HyperCPU::bit_cast_from<T1>(op1.ptr<T1>()), |
| 17 | + HyperCPU::bit_cast_from<T2>(op2.ptr<T2>()) |
| 18 | + ); |
| 19 | + } |
| 20 | + |
| 21 | + /* R_RM implementation */ |
| 22 | + template<typename T1, typename T2, typename T3> |
| 23 | + static constexpr T3 __hcpu_cmp_rrm_impl(HyperCPU::OperandContainer& op1, HyperCPU::OperandContainer& op2, CPU& cpu) { |
| 24 | + static_assert(std::is_same_v<T2, std::uint64_t>); // Locked by current CPU specification |
| 25 | + |
| 26 | + return HyperALU::__hcpu_cmp( |
| 27 | + HyperCPU::bit_cast_from<T1>(op1.ptr<T1>()), |
| 28 | + HyperCPU::bit_cast_from<T2>(op2.ptr<T2>()) |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + /* R_M implementation */ |
| 33 | + template<typename T1, typename T2, typename T3> |
| 34 | + static constexpr T3 __hcpu_cmp_rm_impl(HyperCPU::OperandContainer& op1, HyperCPU::OperandContainer& op2, CPU& cpu) { |
| 35 | + static_assert(std::is_same_v<T2, std::uint64_t>); // Locked by current CPU specification |
| 36 | + |
| 37 | + T2 ptr = HyperCPU::bit_cast<T2>(op2); |
| 38 | + T1 val = cpu.mem_controller->Read8(ptr); |
| 39 | + |
| 40 | + op1.deref<T1>() = HyperALU::__hcpu_and(op1.deref<T1>(), val); |
| 41 | + } |
| 42 | + |
| 43 | + /* R_IMM implementation */ |
| 44 | + template<typename T1, typename T2, typename T3> |
| 45 | + static constexpr T3 __hcpu_cmp_rimm_impl(HyperCPU::OperandContainer& op1, HyperCPU::OperandContainer& op2, CPU& cpu) { |
| 46 | + static_assert(std::is_same_v<T1, T2>); // Locked by current CPU specification |
| 47 | + |
| 48 | + T1 val = HyperCPU::bit_cast<T1>(op2); |
| 49 | + |
| 50 | + op1.deref<T1>() = HyperALU::__hcpu_and(op1.deref<T1>(), val); |
| 51 | + } |
| 52 | +}; |
| 53 | + |
6 | 54 | void HyperCPU::CPU::ExecCMP(const IInstruction& instr, OperandContainer op1, OperandContainer op2) { |
7 | 55 | std::int8_t res = 0; |
8 | 56 | switch (instr.m_op_types) { |
|
0 commit comments