From 2be827e4573f341bc3b21ade2d6d13c359c271fa Mon Sep 17 00:00:00 2001 From: Artur Cygan Date: Tue, 6 Aug 2019 16:43:11 +0200 Subject: [PATCH] Optimize repeated division in CMPXCHG8B (#1501) --- manticore/native/cpu/x86.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manticore/native/cpu/x86.py b/manticore/native/cpu/x86.py index 14d6b91a1..0f13766ee 100644 --- a/manticore/native/cpu/x86.py +++ b/manticore/native/cpu/x86.py @@ -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) ), )