From patchwork Sat Dec 8 00:48:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10719079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B2E861750 for ; Sat, 8 Dec 2018 01:00:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A264A2DD7B for ; Sat, 8 Dec 2018 01:00:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96A842DD98; Sat, 8 Dec 2018 01:00:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 204ED2DD7B for ; Sat, 8 Dec 2018 01:00:44 +0000 (UTC) Received: from localhost ([::1]:48595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVQz5-0005nc-8l for patchwork-qemu-devel@patchwork.kernel.org; Fri, 07 Dec 2018 20:00:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVQnP-0002wQ-JK for qemu-devel@nongnu.org; Fri, 07 Dec 2018 19:48:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVQnM-00012b-CM for qemu-devel@nongnu.org; Fri, 07 Dec 2018 19:48:39 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:41965) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gVQnM-00012L-31; Fri, 07 Dec 2018 19:48:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1544230117; x=1575766117; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=CzvW7mcRtXKr6q8Kmlz0alSjMiU4Z9NX6WPfNdgIDqY=; b=F/3jgv0EXMi8d6nFVQ8vAPItV+/0o2+uwqE6BMOmX8YQoofsl7hGLqod UqTA6+ipMGu+2bvt2chmQrP1mRuf6cKbcGjyDmiyxCa3mD2mKQu6C0zJM yD17aU+nh/k8pGphvm3+bJYFkyxjVM0ZEPS1/js2yJ1XR3U6eAhgRKIwk nMCAVS4jPZ7bp9QVFi11slx8pRRCYy9WhCYz/p4AxIQUXKefHkkR2rZeL X+RhgzUv2UUlL+diRObsPtRHssadlzUP1cXHBgplgpECNcBsKN+BbV9tV rRDhxQsHykAtymD4xJaAOh0ewYa9xyAtGgwL9mvXS/FyfZamOODx5vX6c g==; X-IronPort-AV: E=Sophos;i="5.56,328,1539619200"; d="scan'208";a="97343869" Received: from mail-sn1nam01lp2050.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([104.47.32.50]) by ob1.hgst.iphmx.com with ESMTP; 08 Dec 2018 08:48:35 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OccawXRfKz+SNz4sVEbwWf6enUtmIT0qSMeedXP9S2g=; b=MUdUg6zWb5Kjvv5fIjpOCDfWhpsdyK+cjHlwIlaPQIl1+L/BVrykBlIW9+iRtOsWKbH56sO///h2MbGH3CHXvwZJ/6n4DHbg+ZugGSd2j2xuRX9XWlhFoYvK8XFM7M5GoJhKOBo6M+c/YJOdeW6KBO0WRnXrlE2p/AE4pYU/7fg= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0304.namprd04.prod.outlook.com (10.169.202.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.20; Sat, 8 Dec 2018 00:48:33 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::d13d:19d3:fc93:2ec5]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::d13d:19d3:fc93:2ec5%9]) with mapi id 15.20.1404.021; Sat, 8 Dec 2018 00:48:33 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [RFC v3 15/24] riscv: tcg-target: Add the add2 and sub2 instructions Thread-Index: AQHUjo++AZsqsf1IFUC0cksiTPwMvw== Date: Sat, 8 Dec 2018 00:48:33 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.19.1 x-clientproxiedby: BYAPR11CA0081.namprd11.prod.outlook.com (2603:10b6:a03:f4::22) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0304; 6:qMJlAT9TJPRDh8EQDPgWsTzxdlzS9+yNyngheOXl5BBfCDoplm5aiftlfxgenlCwAY05hgYUrHoUImE6DwDypaFuU/NM+d7DZlC2o6gucwPu0g5SOG5gIH33ZutWSaXcO4m8MXJhn5ZUpI2rMyfVZBob1TdwXyQRHCzEs4BE+ptOt/htTIvweubPPuuaci2JthG9MYJtkNJWHny3dGWYZf1HUlXo32VhrEL+AWk1jojjpTnAixsFd2ow2oPB4EKWoE8uwyztY4ljjmGleslF5EoEydb1jasL3qDxx3kPomVGbx5GTucMnfJKl1spKSE1NOYmQroMpeI5oH/CdBNUQKtKUFcFuQYPw+XGk+If0NKiQvGLKRfF0Gga5g7rPOU3D8Dg++5uNlvBCN5gNvqkiS9LS36BzkWBTVxo00AFhOoCUE2MTHLl8nWCFr4x5B9BqO/Vl1bbycB4TyQojw2g4g==; 5:3sx2IL62Eu9wb43PQuOyqlldGcUGuvrDRRANHqXuliaf4uuU+k/dI5A9FSvGU7M9uRXwscWRg3Fe34HahR1Albie5XcvhYTh4R8kygmJS3JZsmpNI/VJNjq5Mg2C+ZyheN/EFj++BRQNzLNlgBiprSgtStGk6JYZFiIQbgmLbzQ=; 7:2z4fnKvpQWwYbewJNHfVVNMHG0HU3mDG096d5AuEB32H9Mawz/Qr6jXcv811DK2Im2FiW64k6K51KU8ZUnCdxc05FWw5YcEaVhaKxsxAfTe6KQ4swoLa8MsrNvsG6jrYO3iI/OqUcn6lq1MFpnYf4w== x-ms-office365-filtering-correlation-id: 3f1457c9-37aa-48a8-0763-08d65ca6e106 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0304; x-ms-traffictypediagnostic: MWHPR04MB0304: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231455)(999002)(944501520)(52105112)(3002001)(10201501046)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(201708071742011)(7699051)(76991095); SRVR:MWHPR04MB0304; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0304; x-forefront-prvs: 0880FB6EC1 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(396003)(39860400002)(366004)(376002)(136003)(189003)(199004)(54906003)(110136005)(44832011)(386003)(6506007)(5660300001)(68736007)(2906002)(71190400001)(25786009)(71200400001)(86362001)(316002)(99286004)(14454004)(66066001)(102836004)(2501003)(6512007)(53936002)(4326008)(11346002)(6116002)(478600001)(81166006)(81156014)(3846002)(72206003)(8936002)(105586002)(256004)(118296001)(106356001)(14444005)(39060400002)(446003)(6436002)(36756003)(6486002)(486006)(76176011)(186003)(2616005)(305945005)(26005)(97736004)(52116002)(476003)(50226002)(7736002)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0304; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-microsoft-antispam-message-info: QZkLTRoAEJ/Cl+SGtBRxyt6n6HRNkWcCO1zctbUHAmf54rkqTiB4WbwqcMsIXRq9G3StwLI4JSjcQmDyTjLkuTZ05cm8U0m2WE6hHkDE3zV1lkAUQGHHjxnZvZ2N/o18KdIrYsTKfrGwTGlF+mdYpEIUOtj0QKyPpPBaALi4s/r4NYXHM5C1mBe9Bkt3ctZdjuRzhMnBjM2jgaOzTHSUiP7taLyEtB0cG0lFOxRlrl5N6fk5Bf4OuFn+Hl6ofXtU03VrGkkzXUIlajtBNGVkUq9VANhEYRnviklifknesruulDwyiiFnjoUMAv1sJz0aGp0q0Z+mZA7Uv6Z7bDkBEggXjD1tGZ8w8T+PGdcnWUY= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f1457c9-37aa-48a8-0763-08d65ca6e106 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2018 00:48:33.1210 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0304 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [RFC v3 15/24] riscv: tcg-target: 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: "alistair23@gmail.com" , "richard.henderson@linaro.org" , Alistair Francis Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Alistair Francis Reviewed-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 04e81f811a..10bd007cd4 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -681,3 +681,58 @@ static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, } return false; } + +static void tcg_out_addsub2(TCGContext *s, + TCGReg rl, TCGReg rh, + TCGReg al, TCGReg ah, + TCGReg bl, TCGReg bh, + bool cbl, bool cbh, bool is_sub, bool is32bit) +{ + const RISCVInsn opc_add = is32bit ? OPC_ADDW : OPC_ADD; + const RISCVInsn opc_addi = is32bit ? OPC_ADDIW : OPC_ADDI; + const RISCVInsn opc_sub = is32bit ? OPC_SUBW : OPC_SUB; + TCGReg th = 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 == -1 && bl != 0) { + bl = -bl; + bh = 0; + is_sub = !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 != 0 || ah == rl) { + tcg_out_opc_imm(s, opc_addi, th, ah, (is_sub ? -bh : bh)); + } else { + th = ah; + } + + /* Note that tcg optimization should eliminate the bl == 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 == al && rl == 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 == bl ? al : bl)); + } + tcg_out_opc_reg(s, opc_add, rh, th, TCG_REG_TMP0); + } +}