Skip to content

Commit

Permalink
Optimize repeated division in CMPXCHG8B (#1501)
Browse files Browse the repository at this point in the history
arcz authored and Eric Hennenfent committed Aug 6, 2019
1 parent d06d5aa commit 2be827e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions manticore/native/cpu/x86.py
Original file line number Diff line number Diff line change
@@ -1479,6 +1479,7 @@ def CMPXCHG8B(cpu, dest):
:param dest: destination operand.
"""
size = dest.size
half_size = size // 2
cmp_reg_name_l = {64: "EAX", 128: "RAX"}[size]
cmp_reg_name_h = {64: "EDX", 128: "RDX"}[size]
src_reg_name_l = {64: "EBX", 128: "RBX"}[size]
@@ -1499,12 +1500,12 @@ def CMPXCHG8B(cpu, dest):
dest.write(Operators.ITEBV(size, cpu.ZF, Operators.CONCAT(size, srch, srcl), arg_dest))
cpu.write_register(
cmp_reg_name_l,
Operators.ITEBV(size // 2, cpu.ZF, cmpl, Operators.EXTRACT(arg_dest, 0, size // 2)),
Operators.ITEBV(half_size, cpu.ZF, cmpl, Operators.EXTRACT(arg_dest, 0, half_size)),
)
cpu.write_register(
cmp_reg_name_h,
Operators.ITEBV(
size // 2, cpu.ZF, cmph, Operators.EXTRACT(arg_dest, size // 2, size // 2)
half_size, cpu.ZF, cmph, Operators.EXTRACT(arg_dest, half_size, half_size)
),
)

0 comments on commit 2be827e

Please sign in to comment.