Set CF correctly on BLSR/BLSMSK patch (#724)

* Set CF correctly on BLSR patch

* Set CF correctly on BLSMSK patch
This commit is contained in:
Paris Oplopoios 2024-09-03 21:40:46 +03:00 committed by GitHub
parent d48836d5ae
commit 42ab101908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -345,9 +345,26 @@ static void GenerateBLSMSK(const ZydisDecodedOperand* operands, Xbyak::CodeGener
SaveRegisters(c, {scratch});
Xbyak::Label set_carry, clear_carry, end;
// BLSMSK sets CF to zero if source is NOT zero, otherwise it sets CF to one.
c.mov(scratch, *src);
c.test(scratch, scratch);
c.jz(set_carry);
c.jmp(clear_carry);
c.L(set_carry);
c.dec(scratch);
c.xor_(scratch, *src);
c.stc();
c.jmp(end);
c.L(clear_carry);
c.dec(scratch);
c.xor_(scratch, *src);
// We don't need to clear carry here since XOR does that for us
c.L(end);
c.mov(dst, scratch);
RestoreRegisters(c, {scratch});
@ -361,9 +378,26 @@ static void GenerateBLSR(const ZydisDecodedOperand* operands, Xbyak::CodeGenerat
SaveRegisters(c, {scratch});
Xbyak::Label set_carry, clear_carry, end;
// BLSR sets CF to zero if source is NOT zero, otherwise it sets CF to one.
c.mov(scratch, *src);
c.test(scratch, scratch);
c.jz(set_carry);
c.jmp(clear_carry);
c.L(set_carry);
c.dec(scratch);
c.and_(scratch, *src);
c.stc();
c.jmp(end);
c.L(clear_carry);
c.dec(scratch);
c.and_(scratch, *src);
// We don't need to clear carry here since AND does that for us
c.L(end);
c.mov(dst, scratch);
RestoreRegisters(c, {scratch});