From nobody Tue Feb 10 08:31:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549948475039390.0702332161485; Mon, 11 Feb 2019 21:14:35 -0800 (PST) Received: from localhost ([127.0.0.1]:33317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtQOt-00079Z-S1 for importer@patchew.org; Tue, 12 Feb 2019 00:14:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtQ95-0002nO-JE for qemu-devel@nongnu.org; Mon, 11 Feb 2019 23:58:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtQ8q-00021j-G2 for qemu-devel@nongnu.org; Mon, 11 Feb 2019 23:58:07 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:45135) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtQ8m-0001nd-Qf for qemu-devel@nongnu.org; Mon, 11 Feb 2019 23:57:55 -0500 Received: by mail-pf1-x444.google.com with SMTP id j3so677251pfi.12 for ; Mon, 11 Feb 2019 20:57:52 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id a90sm22088923pfj.109.2019.02.11.20.57.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 20:57:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lHk8UdZ7obYSAkP93XP9UWC/ToRUibX5/UujKrCZnvA=; b=Sc9stnbUlRwYV73ekh6KeS2l35FpoJH+mgh7Q/Ty491kdSc6NpyOfz5I6qyjq+KfGg 55EYoY67R3ysCEGuP79NHz+hoQLpdZxjHa/A3mcgfRJVroBZ6e1zKIeD+uZIkNUn9XMS CQjs2GeYmy/1fauClztiSi7954/zCtEuv92iJeiKg0+oynPz7+NgLG3cYtfboSzTiGqU 7vodsWpDb2vndISjjJ9NRrWZBeL1I2UPirKCunbqpkNuh5JpADRKbjmTSuLFC/KOOZ+E /d+hDtaVVb/Wds6H0VVWU0ZAPIwaRyiTEtuD6KN/BpIEJnAx+ndEM7K2Q7Q4kzlFiHOT Leaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lHk8UdZ7obYSAkP93XP9UWC/ToRUibX5/UujKrCZnvA=; b=c2xjw8/rnbYeeVC2GU/ivQWwuqBCnAacfNqKQujvWuG6Hjdw0GCdYVe+/M91fU+haT 6eDbaZPVJmkcTeDw8rPmRRluhFMj2x0SJFp702CCmR6mnRmxVy7UBwANfQW6tQIVPHE7 YDlvdKsGbeU+3poSpKalD8f46jOKqQOBrlRXOVNF7goiU0JUXgiPCw3LAwJsqpRikDqO knFoyShtJmyplNCo6jiTIGV+JFZZzvhAZ869ag11VAa/QcXHH1nGDaRdgCtgRem0unog +zj+bYtQeX6Y6EAVMrUXXJK80ROiHQD8mcpef1BJN8iBYwrjv05fYhSdmneBxuzidyiy LwMg== X-Gm-Message-State: AHQUAuYkMsZY+nLvjunNMRr8uRIP4F+rad1pApoYTl/d1/AJcGGflNPW uFLmvQ1hiAbmoVKKVZMdL/PuEIP6icw= X-Google-Smtp-Source: AHgI3IZqnOLTX1DwYw7cJsb1M7eCqXllkoaGjti0UsbSy9AX5KJeLrvnbcHhA23jipC+2TBwS1ziKw== X-Received: by 2002:a63:4618:: with SMTP id t24mr1928053pga.316.1549947470579; Mon, 11 Feb 2019 20:57:50 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Feb 2019 20:57:19 -0800 Message-Id: <20190212045721.28041-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190212045721.28041-1-richard.henderson@linaro.org> References: <20190212045721.28041-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PULL 22/24] target/hppa: Fix addition ' List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Sven Schnelle Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Sven Schnelle These conditions include the signed overflow bit. See page 5-3 of the Parisc 1.1 Architecture Reference Manual for details. Signed-off-by: Sven Schnelle [rth: More changes for c =3D=3D 3, to compute (N^V)|Z properly.] Signed-off-by: Richard Henderson --- target/hppa/translate.c | 95 +++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 37 deletions(-) diff --git a/target/hppa/translate.c b/target/hppa/translate.c index aae5714235..026ba5cb3e 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -452,15 +452,19 @@ static DisasCond cond_make_n(void) }; } =20 +static DisasCond cond_make_0_tmp(TCGCond c, TCGv_reg a0) +{ + assert (c !=3D TCG_COND_NEVER && c !=3D TCG_COND_ALWAYS); + return (DisasCond){ + .c =3D c, .a0 =3D a0, .a1_is_0 =3D true + }; +} + static DisasCond cond_make_0(TCGCond c, TCGv_reg a0) { - DisasCond r =3D { .c =3D c, .a1 =3D NULL, .a1_is_0 =3D true }; - - assert (c !=3D TCG_COND_NEVER && c !=3D TCG_COND_ALWAYS); - r.a0 =3D tcg_temp_new(); - tcg_gen_mov_reg(r.a0, a0); - - return r; + TCGv_reg tmp =3D tcg_temp_new(); + tcg_gen_mov_reg(tmp, a0); + return cond_make_0_tmp(c, tmp); } =20 static DisasCond cond_make(TCGCond c, TCGv_reg a0, TCGv_reg a1) @@ -849,12 +853,20 @@ static void gen_goto_tb(DisasContext *ctx, int which, } } =20 -/* The parisc documentation describes only the general interpretation of - the conditions, without describing their exact implementation. The - interpretations do not stand up well when considering ADD,C and SUB,B. - However, considering the Addition, Subtraction and Logical conditions - as a whole it would appear that these relations are similar to what - a traditional NZCV set of flags would produce. */ +static bool cond_need_sv(int c) +{ + return c =3D=3D 2 || c =3D=3D 3 || c =3D=3D 6; +} + +static bool cond_need_cb(int c) +{ + return c =3D=3D 4 || c =3D=3D 5; +} + +/* + * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of + * the Parisc 1.1 Architecture Reference Manual for details. + */ =20 static DisasCond do_cond(unsigned cf, TCGv_reg res, TCGv_reg cb_msb, TCGv_reg sv) @@ -863,17 +875,32 @@ static DisasCond do_cond(unsigned cf, TCGv_reg res, TCGv_reg tmp; =20 switch (cf >> 1) { - case 0: /* Never / TR */ + case 0: /* Never / TR (0 / 1) */ cond =3D cond_make_f(); break; case 1: /* =3D / <> (Z / !Z) */ cond =3D cond_make_0(TCG_COND_EQ, res); break; - case 2: /* < / >=3D (N / !N) */ - cond =3D cond_make_0(TCG_COND_LT, res); + case 2: /* < / >=3D (N ^ V / !(N ^ V) */ + tmp =3D tcg_temp_new(); + tcg_gen_xor_reg(tmp, res, sv); + cond =3D cond_make_0_tmp(TCG_COND_LT, tmp); break; - case 3: /* <=3D / > (N | Z / !N & !Z) */ - cond =3D cond_make_0(TCG_COND_LE, res); + case 3: /* <=3D / > (N ^ V) | Z / !((N ^ V) | Z) */ + /* + * Simplify: + * (N ^ V) | Z + * ((res < 0) ^ (sv < 0)) | !res + * ((res ^ sv) < 0) | !res + * (~(res ^ sv) >=3D 0) | !res + * !(~(res ^ sv) >> 31) | !res + * !(~(res ^ sv) >> 31 & res) + */ + tmp =3D tcg_temp_new(); + tcg_gen_eqv_reg(tmp, res, sv); + tcg_gen_sari_reg(tmp, tmp, TARGET_REGISTER_BITS - 1); + tcg_gen_and_reg(tmp, tmp, res); + cond =3D cond_make_0_tmp(TCG_COND_EQ, tmp); break; case 4: /* NUV / UV (!C / C) */ cond =3D cond_make_0(TCG_COND_EQ, cb_msb); @@ -882,8 +909,7 @@ static DisasCond do_cond(unsigned cf, TCGv_reg res, tmp =3D tcg_temp_new(); tcg_gen_neg_reg(tmp, cb_msb); tcg_gen_and_reg(tmp, tmp, res); - cond =3D cond_make_0(TCG_COND_EQ, tmp); - tcg_temp_free(tmp); + cond =3D cond_make_0_tmp(TCG_COND_EQ, tmp); break; case 6: /* SV / NSV (V / !V) */ cond =3D cond_make_0(TCG_COND_LT, sv); @@ -891,8 +917,7 @@ static DisasCond do_cond(unsigned cf, TCGv_reg res, case 7: /* OD / EV */ tmp =3D tcg_temp_new(); tcg_gen_andi_reg(tmp, res, 1); - cond =3D cond_make_0(TCG_COND_NE, tmp); - tcg_temp_free(tmp); + cond =3D cond_make_0_tmp(TCG_COND_NE, tmp); break; default: g_assert_not_reached(); @@ -930,7 +955,7 @@ static DisasCond do_sub_cond(unsigned cf, TCGv_reg res, cond =3D cond_make(TCG_COND_LEU, in1, in2); break; default: - return do_cond(cf, res, sv, sv); + return do_cond(cf, res, NULL, sv); } if (cf & 1) { cond.c =3D tcg_invert_cond(cond.c); @@ -1129,7 +1154,7 @@ static void do_add(DisasContext *ctx, unsigned rt, TC= Gv_reg in1, in1 =3D tmp; } =20 - if (!is_l || c =3D=3D 4 || c =3D=3D 5) { + if (!is_l || cond_need_cb(c)) { TCGv_reg zero =3D tcg_const_reg(0); cb_msb =3D get_temp(ctx); tcg_gen_add2_reg(dest, cb_msb, in1, zero, in2, zero); @@ -1151,7 +1176,7 @@ static void do_add(DisasContext *ctx, unsigned rt, TC= Gv_reg in1, =20 /* Compute signed overflow if required. */ sv =3D NULL; - if (is_tsv || c =3D=3D 6) { + if (is_tsv || cond_need_sv(c)) { sv =3D do_add_sv(ctx, dest, in1, in2); if (is_tsv) { /* ??? Need to include overflow from shift. */ @@ -1242,7 +1267,7 @@ static void do_sub(DisasContext *ctx, unsigned rt, TC= Gv_reg in1, =20 /* Compute signed overflow if required. */ sv =3D NULL; - if (is_tsv || c =3D=3D 6) { + if (is_tsv || cond_need_sv(c)) { sv =3D do_sub_sv(ctx, dest, in1, in2); if (is_tsv) { gen_helper_tsv(cpu_env, sv); @@ -1314,7 +1339,7 @@ static void do_cmpclr(DisasContext *ctx, unsigned rt,= TCGv_reg in1, =20 /* Compute signed overflow if required. */ sv =3D NULL; - if ((cf >> 1) =3D=3D 6) { + if (cond_need_sv(cf >> 1)) { sv =3D do_sub_sv(ctx, dest, in1, in2); } =20 @@ -2781,7 +2806,7 @@ static bool trans_ds(DisasContext *ctx, arg_rrr_cf *a) /* Install the new nullification. */ if (a->cf) { TCGv_reg sv =3D NULL; - if (a->cf >> 1 =3D=3D 6) { + if (cond_need_sv(a->cf >> 1)) { /* ??? The lshift is supposed to contribute to overflow. */ sv =3D do_add_sv(ctx, dest, add1, add2); } @@ -2982,7 +3007,7 @@ static bool do_cmpb(DisasContext *ctx, unsigned r, TC= Gv_reg in1, tcg_gen_sub_reg(dest, in1, in2); =20 sv =3D NULL; - if (c =3D=3D 6) { + if (cond_need_sv(c)) { sv =3D do_sub_sv(ctx, dest, in1, in2); } =20 @@ -3013,19 +3038,15 @@ static bool do_addb(DisasContext *ctx, unsigned r, = TCGv_reg in1, sv =3D NULL; cb_msb =3D NULL; =20 - switch (c) { - default: - tcg_gen_add_reg(dest, in1, in2); - break; - case 4: case 5: + if (cond_need_cb(c)) { cb_msb =3D get_temp(ctx); tcg_gen_movi_reg(cb_msb, 0); tcg_gen_add2_reg(dest, cb_msb, in1, cb_msb, in2, cb_msb); - break; - case 6: + } else { tcg_gen_add_reg(dest, in1, in2); + } + if (cond_need_sv(c)) { sv =3D do_add_sv(ctx, dest, in1, in2); - break; } =20 cond =3D do_cond(c * 2 + f, dest, cb_msb, sv); --=20 2.17.2