From patchwork Sat Oct 22 21:05:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 685467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t1bKc2SVNz9t17 for ; Sun, 23 Oct 2016 08:29:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=hbQtRp1Z; dkim-atps=neutral Received: from localhost ([::1]:38787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1by3rF-0008CC-Px for incoming@patchwork.ozlabs.org; Sat, 22 Oct 2016 17:29:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1by3U7-0005AU-Bs for qemu-devel@nongnu.org; Sat, 22 Oct 2016 17:05:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1by3U3-0001tj-Eg for qemu-devel@nongnu.org; Sat, 22 Oct 2016 17:05:43 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33144) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1by3U3-0001tJ-46 for qemu-devel@nongnu.org; Sat, 22 Oct 2016 17:05:39 -0400 Received: by mail-pf0-x243.google.com with SMTP id i85so12089197pfa.0 for ; Sat, 22 Oct 2016 14:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Iu38dlQFEePmFKZeU2HuWdnuP2PZv3nA8Ftdf+bjTJs=; b=hbQtRp1ZvLIS52LviCRXIFP0ZTXnfEPmGzaF/1r4NZnIh2hC5foLpfCMnbEISN2kUH qcRxr09nfUfbUVEN+DlV6/tAmjvusJulqYAylfY1V0MX0s+VQyRS5gsyPCG+hCvwcq+Q SAEOtBTufMANlluvLLWRpXGLF/i4r72v3/jb9208Zd6WktMJObjMLFcN/AkqEdYQZch1 9t2IOYIJVidoj4+3l/NOCEky81LKwkNcweMrJvCWdQ6EvxNHY70lX07iDH65a72mUkB4 VoAsEIaCMpLkO4X957zzbKadr/0pisMRZJi90ahOsC4jGMSFGcgNnnE+IMAJuHv4MZQ8 WF1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Iu38dlQFEePmFKZeU2HuWdnuP2PZv3nA8Ftdf+bjTJs=; b=J0oA61otjAuExvVJUNopnXFZwHgGo4USO1raCJmgv1GqawgD2Q7na+YvPfcED5tW3z L9x0zSK+i5yN46pbXiwOYF5VpZ+TRCnlL8o9lO6osxItrUsMpp7L1tdBWWgWeCQV6m8w hIJPmpTYJ4tWecW1X4W4u7SmVxuHfE0LoOfAoF6+h8Li0ReOpmj0o6JApTdklp45Eqq0 Y0SyIQRFsl4nFqLb4WqAhgHCd7CKEdR0su6WMb5TdtzgvcW/Qa/3YBQEMtQEXmHfHC7r uWygT5fG53VcPwZ9F1TPCa+yT7dk3fzwoNN7sryO/daBOfAU5Eq4IKOg9be7zsv4g4KP qz1Q== X-Gm-Message-State: ABUngvfnE/OdCOkQBDIUMi+K0t5nWlFKm5oo7nOMO5dW8WB2VlcHQYuE7CIX4lS0f70fjQ== X-Received: by 10.98.147.218 with SMTP id r87mr14143080pfk.108.1477170338052; Sat, 22 Oct 2016 14:05:38 -0700 (PDT) Received: from bigtime.twiddle.net (174-24-157-40.tukw.qwest.net. [174.24.157.40]) by smtp.gmail.com with ESMTPSA id f129sm14300679pfc.3.2016.10.22.14.05.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Oct 2016 14:05:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 22 Oct 2016 14:05:07 -0700 Message-Id: <1477170324-17783-19-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477170324-17783-1-git-send-email-rth@twiddle.net> References: <1477170324-17783-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PULL 18/35] target-i386: emulate LOCK'ed OP instructions using atomic helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" [rth: Eliminate some unnecessary temporaries.] Signed-off-by: Emilio G. Cota Message-Id: <1467054136-10430-13-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- target-i386/translate.c | 76 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 18 deletions(-) diff --git a/target-i386/translate.c b/target-i386/translate.c index 5d9790a..b5c7791 100644 --- a/target-i386/translate.c +++ b/target-i386/translate.c @@ -1258,55 +1258,95 @@ static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d) { if (d != OR_TMP0) { gen_op_mov_v_reg(ot, cpu_T0, d); - } else { + } else if (!(s1->prefix & PREFIX_LOCK)) { gen_op_ld_v(s1, ot, cpu_T0, cpu_A0); } switch(op) { case OP_ADCL: gen_compute_eflags_c(s1, cpu_tmp4); - tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_T1); - tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_tmp4); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_add_tl(cpu_T0, cpu_tmp4, cpu_T1); + tcg_gen_atomic_add_fetch_tl(cpu_T0, cpu_A0, cpu_T0, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_T1); + tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_tmp4); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update3_cc(cpu_tmp4); set_cc_op(s1, CC_OP_ADCB + ot); break; case OP_SBBL: gen_compute_eflags_c(s1, cpu_tmp4); - tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_T1); - tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_tmp4); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_add_tl(cpu_T0, cpu_T1, cpu_tmp4); + tcg_gen_neg_tl(cpu_T0, cpu_T0); + tcg_gen_atomic_add_fetch_tl(cpu_T0, cpu_A0, cpu_T0, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_T1); + tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_tmp4); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update3_cc(cpu_tmp4); set_cc_op(s1, CC_OP_SBBB + ot); break; case OP_ADDL: - tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_T1); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_atomic_add_fetch_tl(cpu_T0, cpu_A0, cpu_T1, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_add_tl(cpu_T0, cpu_T0, cpu_T1); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update2_cc(); set_cc_op(s1, CC_OP_ADDB + ot); break; case OP_SUBL: - tcg_gen_mov_tl(cpu_cc_srcT, cpu_T0); - tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_T1); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_neg_tl(cpu_T0, cpu_T1); + tcg_gen_atomic_fetch_add_tl(cpu_cc_srcT, cpu_A0, cpu_T0, + s1->mem_index, ot | MO_LE); + tcg_gen_sub_tl(cpu_T0, cpu_cc_srcT, cpu_T1); + } else { + tcg_gen_mov_tl(cpu_cc_srcT, cpu_T0); + tcg_gen_sub_tl(cpu_T0, cpu_T0, cpu_T1); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update2_cc(); set_cc_op(s1, CC_OP_SUBB + ot); break; default: case OP_ANDL: - tcg_gen_and_tl(cpu_T0, cpu_T0, cpu_T1); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_atomic_and_fetch_tl(cpu_T0, cpu_A0, cpu_T1, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_and_tl(cpu_T0, cpu_T0, cpu_T1); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update1_cc(); set_cc_op(s1, CC_OP_LOGICB + ot); break; case OP_ORL: - tcg_gen_or_tl(cpu_T0, cpu_T0, cpu_T1); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_atomic_or_fetch_tl(cpu_T0, cpu_A0, cpu_T1, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_or_tl(cpu_T0, cpu_T0, cpu_T1); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update1_cc(); set_cc_op(s1, CC_OP_LOGICB + ot); break; case OP_XORL: - tcg_gen_xor_tl(cpu_T0, cpu_T0, cpu_T1); - gen_op_st_rm_T0_A0(s1, ot, d); + if (s1->prefix & PREFIX_LOCK) { + tcg_gen_atomic_xor_fetch_tl(cpu_T0, cpu_A0, cpu_T1, + s1->mem_index, ot | MO_LE); + } else { + tcg_gen_xor_tl(cpu_T0, cpu_T0, cpu_T1); + gen_op_st_rm_T0_A0(s1, ot, d); + } gen_op_update1_cc(); set_cc_op(s1, CC_OP_LOGICB + ot); break;