Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86: Carry flag calculated incorrectly for LZCNT if source=dest #6556

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sleigh-InSPECtor
Copy link
Contributor

The carry flag for the LZCNT instruction should be calculated based on the input value of the source operand. However, if the destination operand is the same as the source operand (e.g., LZCNT EAX,EAX) then the carry flag is computed based the result of the LZCNT operation instead of the input value.

This PR fixes this by storing the input value into a temporary which is later used for computing the carry flag.

e.g.,

  • 66f30fbdc0 "LZCNT AX,AX" wwith AX=ffff

    • Hardware Reference (AMD CPU & Intel CPU): { AX=0x0, ZF=1, CF=0 }
    • x86:LE:64:default (Existing): { AX=0x0, ZF=1, CF=1 }
    • x86:LE:64:default (This patch): { AX=0x0, ZF=1, CF=0 }
  • f30fbdc0 "LZCNT EAX,EAX" with EAX=0xffff_ffff

    • Hardware Reference (AMD CPU & Intel CPU): { EAX=0x0, ZF=1, CF=0 }
    • x86:LE:64:default (Existing): { EAX=0x0, ZF=1, CF=1 }
    • x86:LE:64:default (This patch): { EAX=0x0, ZF=1, CF=0 }
  • f3480fbdc0 "LZCNT RAX,RAX" with RAX=0xffff_ffff_ffff_ffff

    • Hardware Reference (AMD CPU & Intel CPU): { RAX=0x0, ZF=1, CF=0 }
    • x86:LE:64:default (Existing): { RAX=0x0, ZF=1, CF=1 }
    • x86:LE:64:default (This patch): { RAX=0x0, ZF=1, CF=0 }

@GhidorahRex GhidorahRex self-assigned this May 22, 2024
@GhidorahRex GhidorahRex added Type: Bug Something isn't working Feature: Processor/x86 Status: Triage Information is being gathered labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Processor/x86 Status: Triage Information is being gathered Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants