From patchwork Tue Apr 2 21:42:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 233149 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 131F82C0164 for ; Wed, 3 Apr 2013 08:43:32 +1100 (EST) Received: from localhost ([::1]:47646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN8zK-00006u-2o for incoming@patchwork.ozlabs.org; Tue, 02 Apr 2013 17:43:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN8z0-0008U7-Er for qemu-devel@nongnu.org; Tue, 02 Apr 2013 17:43:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UN8yx-0005l5-Ts for qemu-devel@nongnu.org; Tue, 02 Apr 2013 17:43:10 -0400 Received: from mail-qe0-f46.google.com ([209.85.128.46]:61618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN8yx-0005l1-Q4 for qemu-devel@nongnu.org; Tue, 02 Apr 2013 17:43:07 -0400 Received: by mail-qe0-f46.google.com with SMTP id a11so516889qen.19 for ; Tue, 02 Apr 2013 14:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer; bh=GdSw8/XuAZ1josVhDDbI6l6C0QfloeEqeaZtGxFXpM4=; b=I8KuTOn5ACBRzkBcfrfzvbCn8QvGFesxl3p6qSxlIFz1611utvDBfU8cNNu2lJf5T0 r2ThSTaFeqzOh1mMVU2ARbhg6UmGTwfObCWWinXcEi2oluCIlo30BoqPc87PDc0wodqM ZNLvSdTyARFrYw8bNuUanTZ3QYCzmwJzfwFyhvNijR5s8A1mfD3/qGjtRerwghyhzt24 /QIyuGKWuo/sPioCPKHs/XzBrWapLtyAfAhzwUYPFYdUnrmP9KcQEtX2mKIQjQR4sXQ6 FqmsZnscT8KH9ONiYyWHOPjpN9TXv2cr4YBTWtZliVr/nEXR8rnUN6PtFMKASrsbxHEB KvYw== X-Received: by 10.224.33.141 with SMTP id h13mr17387739qad.34.1364938987304; Tue, 02 Apr 2013 14:43:07 -0700 (PDT) Received: from pebble.com ([12.236.175.36]) by mx.google.com with ESMTPS id e3sm3607453qeo.0.2013.04.02.14.43.05 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 02 Apr 2013 14:43:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 2 Apr 2013 14:42:34 -0700 Message-Id: <1364938954-1825-1-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.46 Cc: Aurelien Jarno Subject: [Qemu-devel] [CFT] target-ppc: Fix narrow-mode add/sub carry output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Broken in b5a73f8d8a57e940f9bbeb399a9e47897522ee9a, the carry itself was fixed in 79482e5ab38a05ca8869040b0d8b8f451f16ff62. But we still need to produce the full 64-bit addition. Cc: Aurelien Jarno Signed-off-by: Richard Henderson --- Aurelien, you reported this bug, but I'm unable to reproduce it at the moment. That test program you sent along is broken, attempting to run insns in pages without the execute bit set. I don't have time to fix that today. But per IRC, I think we know what the problem is. And at least this runs the linux-user-0.3 ppc binaries properly. Hopefully it'll solve the real problem with your guest openssl. r~ --- target-ppc/translate.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/target-ppc/translate.c b/target-ppc/translate.c index 5e741d1..1feadca 100644 --- a/target-ppc/translate.c +++ b/target-ppc/translate.c @@ -775,15 +775,19 @@ static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, if (compute_ca) { if (NARROW_MODE(ctx)) { + /* Caution: a non-obvious corner case of the spec is that we + must produce the *entire* 64-bit addition, but produce the + carry into bit 32. */ TCGv t1 = tcg_temp_new(); - tcg_gen_ext32u_tl(t1, arg2); - tcg_gen_ext32u_tl(t0, arg1); - tcg_gen_add_tl(t0, t0, t1); - tcg_temp_free(t1); + tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */ + tcg_gen_add_tl(t0, arg1, arg2); if (add_ca) { tcg_gen_add_tl(t0, t0, cpu_ca); } - tcg_gen_shri_tl(cpu_ca, t0, 32); + tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */ + tcg_temp_free(t1); + tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ + tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); } else { TCGv zero = tcg_const_tl(0); if (add_ca) { @@ -1129,17 +1133,23 @@ static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, if (compute_ca) { /* dest = ~arg1 + arg2 [+ ca]. */ if (NARROW_MODE(ctx)) { + /* Caution: a non-obvious corner case of the spec is that we + must produce the *entire* 64-bit addition, but produce the + carry into bit 32. */ TCGv inv1 = tcg_temp_new(); + TCGv t1 = tcg_temp_new(); tcg_gen_not_tl(inv1, arg1); - tcg_gen_ext32u_tl(t0, arg2); - tcg_gen_ext32u_tl(inv1, inv1); if (add_ca) { - tcg_gen_add_tl(t0, t0, cpu_ca); + tcg_gen_add_tl(t0, arg2, cpu_ca); } else { - tcg_gen_addi_tl(t0, t0, 1); + tcg_gen_addi_tl(t0, arg2, 1); } + tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */ tcg_gen_add_tl(t0, t0, inv1); - tcg_gen_shri_tl(cpu_ca, t0, 32); + tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */ + tcg_temp_free(t1); + tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ + tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); } else if (add_ca) { TCGv zero, inv1 = tcg_temp_new(); tcg_gen_not_tl(inv1, arg1);