From nobody Thu Oct 2 10:15:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.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 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545772535626645.3649765042254; Tue, 25 Dec 2018 13:15:35 -0800 (PST) Received: from localhost ([127.0.0.1]:43182 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbu34-0003NA-4A for importer@patchew.org; Tue, 25 Dec 2018 16:15:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtlY-0005Hd-Jf for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:57:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbtlX-0007yp-M9 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:57:28 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:40551) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbtlX-0007xa-Fr for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:57:27 -0500 Received: by mail-pl1-x62f.google.com with SMTP id u18so6802375plq.7 for ; Tue, 25 Dec 2018 12:57:27 -0800 (PST) Received: from cloudburst.home (c211-28-135-144.sunsh3.vic.optusnet.com.au. [211.28.135.144]) by smtp.gmail.com with ESMTPSA id t21sm48501628pgg.24.2018.12.25.12.57.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Dec 2018 12:57:25 -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=KUc9v+Ru1eDzqwn+K2rvDvA/PhdW6+ZauYMdOioBePY=; b=jJ9avXuKJ1vH3jUN+3hHA/va2CwFXqvsH4gqQSGDLuWQQFv0LaVP97LxWEtHJXdoty K+ys/vPFBGJJlKJoItkxuzi7VCLzr4eQPqTBKuD65m1ss3Y1hRHe8WdaHEL3JLie3b6P WWSiv0LtJy2xULwtDnBiTXEJX/8fs7RXZcepk= 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=KUc9v+Ru1eDzqwn+K2rvDvA/PhdW6+ZauYMdOioBePY=; b=URjuB2kZlr9MGgKZzRQYZYTrduHr9aHd3N8msgnr/jWreb+/WymQtwFzl3oWCaV2gQ qK88cASn1/9agY7fLTViGb/dsq9i5hcArgIhxUk5ggOGg6WUn/4QsKgB3cyggXJeE6/U UbQ1Y/vqnVSD0j4pr1r1A63fcIc8pLhakqkjclI3RgayvBfVOkk4O+AnoWDXMjQnj5i0 lANrgie5l3pdDfu4IYnX6XNGqMB8X3VpTWshH/vRSyS8FYEjXb8BB6bLWF7Fs056Guh6 1/VswEmSseYoQ6+ytku8rd6lvxnBfHZlZaLOUzCOqbDJUPCbZIn+Uu9syeVF1mvOergI A/kA== X-Gm-Message-State: AJcUukdXER7qCtm3OiiSEnQ7yOomx14ROzJ+wqHRT/HVOwea18lNiYCQ TjsCZH/qIEMg3XI9xWUCVSyjqoaxh6w= X-Google-Smtp-Source: ALg8bN7USiaFpnXRzywcJABXAgJPKgcnytG8fn5FHADDt9WzGWwOaxdE5gTzfIP5VwHMobTvcojN0A== X-Received: by 2002:a17:902:622:: with SMTP id 31mr17123223plg.171.1545771445927; Tue, 25 Dec 2018 12:57:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2018 07:55:01 +1100 Message-Id: <20181225205529.10874-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181225205529.10874-1-richard.henderson@linaro.org> References: <20181225205529.10874-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::62f Subject: [Qemu-devel] [PULL 14/42] tcg/riscv: Add the add2 and sub2 instructions 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, Alistair Francis 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: Alistair Francis Signed-off-by: Alistair Francis Reviewed-by: Richard Henderson Message-Id: <5665a57809e32b35775e8e98fdab898853af37b8.1545246859.git.alista= ir.francis@wdc.com> Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.inc.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index 65718df7ad..5da850b957 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -695,3 +695,58 @@ static bool tcg_out_sti(TCGContext *s, TCGType type, T= CGArg val, } return false; } + +static void tcg_out_addsub2(TCGContext *s, + TCGReg rl, TCGReg rh, + TCGReg al, TCGReg ah, + TCGArg bl, TCGArg bh, + bool cbl, bool cbh, bool is_sub, bool is32bit) +{ + const RISCVInsn opc_add =3D is32bit ? OPC_ADDW : OPC_ADD; + const RISCVInsn opc_addi =3D is32bit ? OPC_ADDIW : OPC_ADDI; + const RISCVInsn opc_sub =3D is32bit ? OPC_SUBW : OPC_SUB; + TCGReg th =3D TCG_REG_TMP1; + + /* If we have a negative constant such that negating it would + make the high part zero, we can (usually) eliminate one insn. */ + if (cbl && cbh && bh =3D=3D -1 && bl !=3D 0) { + bl =3D -bl; + bh =3D 0; + is_sub =3D !is_sub; + } + + /* By operating on the high part first, we get to use the final + carry operation to move back from the temporary. */ + if (!cbh) { + tcg_out_opc_reg(s, (is_sub ? opc_sub : opc_add), th, ah, bh); + } else if (bh !=3D 0 || ah =3D=3D rl) { + tcg_out_opc_imm(s, opc_addi, th, ah, (is_sub ? -bh : bh)); + } else { + th =3D ah; + } + + /* Note that tcg optimization should eliminate the bl =3D=3D 0 case. = */ + if (is_sub) { + if (cbl) { + tcg_out_opc_imm(s, OPC_SLTIU, TCG_REG_TMP0, al, bl); + tcg_out_opc_imm(s, opc_addi, rl, al, -bl); + } else { + tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_TMP0, al, bl); + tcg_out_opc_reg(s, opc_sub, rl, al, bl); + } + tcg_out_opc_reg(s, opc_sub, rh, th, TCG_REG_TMP0); + } else { + if (cbl) { + tcg_out_opc_imm(s, opc_addi, rl, al, bl); + tcg_out_opc_imm(s, OPC_SLTIU, TCG_REG_TMP0, rl, bl); + } else if (rl =3D=3D al && rl =3D=3D bl) { + tcg_out_opc_imm(s, OPC_SLTI, TCG_REG_TMP0, al, 0); + tcg_out_opc_reg(s, opc_addi, rl, al, bl); + } else { + tcg_out_opc_reg(s, opc_add, rl, al, bl); + tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_TMP0, + rl, (rl =3D=3D bl ? al : bl)); + } + tcg_out_opc_reg(s, opc_add, rh, th, TCG_REG_TMP0); + } +} --=20 2.17.2