| 759 | } |
| 760 | |
| 761 | void OpDispatchBuilder::CondJUMPRCXOp(OpcodeArgs) { |
| 762 | // Calculate flags early. |
| 763 | CalculateDeferredFlags(); |
| 764 | |
| 765 | BlockSetRIP = true; |
| 766 | auto JcxGPRSize = GetGPROpSize(); |
| 767 | JcxGPRSize = (Op->Flags & X86Tables::DecodeFlags::FLAG_ADDRESS_SIZE) ? (JcxGPRSize >> 1) : JcxGPRSize; |
| 768 | |
| 769 | uint64_t Target = Op->PC + Op->InstSize + Op->Src[0].Literal(); |
| 770 | |
| 771 | Ref CondReg = LoadGPRRegister(X86State::REG_RCX, JcxGPRSize); |
| 772 | |
| 773 | auto TrueBlock = JumpTargets.find(Target); |
| 774 | auto FalseBlock = JumpTargets.find(Op->PC + Op->InstSize); |
| 775 | |
| 776 | auto CurrentBlock = GetCurrentBlock(); |
| 777 | |
| 778 | { |
| 779 | auto CondJump_ = CondJump(CondReg, {COND_EQ}); |
| 780 | |
| 781 | // Taking branch block |
| 782 | if (TrueBlock != JumpTargets.end()) { |
| 783 | SetTrueJumpTarget(CondJump_, TrueBlock->second.BlockEntry); |
| 784 | } else { |
| 785 | // Make sure to start a new block after ending this one |
| 786 | auto JumpTarget = CreateNewCodeBlockAtEnd(); |
| 787 | SetTrueJumpTarget(CondJump_, JumpTarget); |
| 788 | SetCurrentCodeBlock(JumpTarget); |
| 789 | StartNewBlock(); |
| 790 | |
| 791 | // Store the new RIP |
| 792 | ExitRelocatedPC(Op, Op->Src[0].Data.Literal.Value); |
| 793 | } |
| 794 | |
| 795 | // Failure to take branch |
| 796 | if (FalseBlock != JumpTargets.end()) { |
| 797 | SetFalseJumpTarget(CondJump_, FalseBlock->second.BlockEntry); |
| 798 | } else { |
| 799 | // Make sure to start a new block after ending this one |
| 800 | // Place it after the current block for fallthrough behavior |
| 801 | auto JumpTarget = CreateNewCodeBlockAfter(CurrentBlock); |
| 802 | SetFalseJumpTarget(CondJump_, JumpTarget); |
| 803 | SetCurrentCodeBlock(JumpTarget); |
| 804 | StartNewBlock(); |
| 805 | |
| 806 | // Leave block & store the new RIP |
| 807 | ExitRelocatedPC(Op); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | void OpDispatchBuilder::LoopOp(OpcodeArgs) { |
| 813 | // Calculate flags early. |