From patchwork Tue Nov 27 21:08:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10701467 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 B5AFE14D6 for ; Tue, 27 Nov 2018 21:26:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A04A52C2B7 for ; Tue, 27 Nov 2018 21:26:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 921732C42C; Tue, 27 Nov 2018 21:26:52 +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 F25932C2B7 for ; Tue, 27 Nov 2018 21:26:51 +0000 (UTC) Received: from localhost ([::1]:44589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRksd-0005ps-56 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Nov 2018 16:26:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRkal-00055A-II for qemu-devel@nongnu.org; Tue, 27 Nov 2018 16:08:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRkai-0004EU-Cv for qemu-devel@nongnu.org; Tue, 27 Nov 2018 16:08:23 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:13571) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gRkai-0004Dy-4K; Tue, 27 Nov 2018 16:08:20 -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=1543352900; x=1574888900; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=4O8cCIcIoB+r1qlanjPGyCNQCuRovZFWhSZsWpsByNw=; b=H9wBwI9/jvb+MBGEoRGaac/wvEQ7kScR80biVpfPTLC/x8gZAwfkjeLD u1IZ+46HwOtMJ4RVvWEEIPRShAgemj2mziLQZoHbEnHYOh0JorjD+ythk LBviFhgtTSE8Swd6MzcbrFZemWaWaCoklI7hwzXwpU9WZVNK/GO2XUrAM tE42M1bSWjNqxjy7LOYXNwM9UssUeWU9XL4vUVhHSqADTPPFnLGyzkkur CTP8yXvBNx0KcCp/XzDJNxdpr7h4iE3QiWC2Jl6uC60msGamRajaRK9js KyM0W5XID8dt2okJegRW/Eo2co5ROAXK4dBUo004RhOYez33s4NHZF+pU w==; X-IronPort-AV: E=Sophos;i="5.56,287,1539619200"; d="scan'208";a="199812232" Received: from mail-sn1nam01lp0115.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.115]) by ob1.hgst.iphmx.com with ESMTP; 28 Nov 2018 05:08:18 +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=fpFseMVfEdh1wMPg/f1SN0jOOTDO42FbQ+odUEqXNE8=; b=Wk3hiUB1cgyFFmoGBG7QCItEVVGMPZvQMxKH9BXVhCQn+eFMDukqBOuBBqPH013QbP2r130te8G5vtYZmBcycIAmAbR6D0/BHRIKvoo9+0oN9lQjpfI3c0M59/pUTiKxz828C/65EaHptjz+H4fRf6icu+U5f6ccyfqH/703jcw= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0993.namprd04.prod.outlook.com (10.174.250.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.14; Tue, 27 Nov 2018 21:08:16 +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.1361.019; Tue, 27 Nov 2018 21:08:16 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [RFC v2 11/24] riscv: tcg-target: Add the mov and movi instruction Thread-Index: AQHUhpVQwXainwMUpE2PB1hrnNnoPg== Date: Tue, 27 Nov 2018 21:08:16 +0000 Message-ID: <51221791beb40b25309805b1c76db0004f26f64e.1543352682.git.alistair.francis@wdc.com> 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: BYAPR03CA0004.namprd03.prod.outlook.com (2603:10b6:a02:a8::17) 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.171] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0993; 6:Ua7PonV529ZNYc/WP081SP+Z9v9OQ6sOedwQaks3BtRKm3NlWO0GKiJjYhEajndc7CIBP1zmVGrWvEJXxpIOk691UMVZa2WGJ2mHu8UgyCyX8lPZF1F2m51CREpya5fLYZvcguG8Uac6wj09Cm/ZSS40GXzDjKT18I6bbGnNetZj1p4513MYiEXNt/rScketUjuwwyQMJJ8kEKsf8ZEZg5JnywNziLWCObtZvrE3xhzyrceBMKVIRCNq7cwqh7AXPTvmMFqsEKPxFb/mfh0vmuLSfirUCY0itiU9RmXlyvoEde3kwNh4mS9YCapJKNT6easyyY3jdEX0UazIUBjFt32Za6H6nPsxt/4quZlQzHimy3Mfm5aY0QEkt/lN91jazEyPSX2OzktRW8xTN0BbqU7eo9kpcTF8rgkbncHzrEmz6Rm5TCMcl6b7+Cr6zt6hXu3ptYKaYcDutGuNlbh6AQ==; 5:meZL/rkNq3dUiAkNQIZDmyJeytAPf5qu2Sn9cl50XacHKjHjL69NQ2QN0i+M0MWbrBnWYql0SDLqxYFMue78kgHkdezjVUdL7ReZTc4LuZW6cBFGSxxBdKtFBd8zVrW7Y+nMNf2hRHcX6vwvJ5iHUWLCPzG/Yph25d2C3p8wl+I=; 7:/F7R2fYaqNVIqxMJ+MpllHlJrmaZBG3LZqv2nwKeXjdXu6AgR5/u9Dp1Gcsf734KS9Dwf1hRTY2n/Ut4gmFIYL0pnvm1DE5NF5/fH/vmZ7B28RtldoL20tPdn+sCuDgYMssNRdHgfEKmdprPGJb5ww== x-ms-office365-filtering-correlation-id: 3aee63e3-77ce-4509-100a-08d654ac7331 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0993; x-ms-traffictypediagnostic: MWHPR04MB0993: 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)(8121501046)(5005006)(3231443)(944501410)(52105112)(93006095)(93001095)(10201501046)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:MWHPR04MB0993; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0993; x-forefront-prvs: 086943A159 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(346002)(396003)(136003)(366004)(189003)(199004)(7736002)(97736004)(305945005)(54906003)(316002)(110136005)(8676002)(50226002)(3846002)(6116002)(81166006)(81156014)(8936002)(6512007)(478600001)(39060400002)(6436002)(72206003)(6486002)(53936002)(105586002)(25786009)(118296001)(106356001)(2501003)(5660300001)(66066001)(4326008)(76176011)(68736007)(486006)(6506007)(476003)(99286004)(386003)(44832011)(26005)(11346002)(446003)(2616005)(14454004)(2906002)(86362001)(186003)(256004)(52116002)(71200400001)(36756003)(71190400001)(102836004); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0993; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-microsoft-antispam-message-info: B72H2aVvJdLRStcJhKLbvjlBaAU5U8MmzlWb/nZSzoDC3TahHc/Juu7sbVbcH8V05/XsKy9Wf/wOiU4ZNkWLOPGKgzspuWdDc4ctvXIuaiczvS/HpXE9hqX5xLMq8sXvUiyBqFcWh0+s0q3dYeX9afoVNS5fH5EzTZnSsoxFqV9af98G1EcJnTMLQEKEm5SSWyzz0U0Q7OvrlCEqT3FFY7H0AlfGXdM+XQieGlIfypOyr+xrvCn0Rh4MQdH95sRAQbQpYaAdgjSZTzIn+Vr6EbgTGq8k0RUkHgDQfkleWIpiB4wPrczTykn3Skr7RsRVmgxnKdcNnoFuqhIZtJhNJuCVhNRhnCZxGEkrcCqMQdg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3aee63e3-77ce-4509-100a-08d654ac7331 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2018 21:08:16.6801 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0993 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 68.232.141.245 Subject: [Qemu-devel] [RFC v2 11/24] riscv: tcg-target: Add the mov and movi instruction 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 Signed-off-by: Michael Clark --- tcg/riscv/tcg-target.inc.c | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index 9c48679f11..e5a07b146f 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -434,6 +434,84 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, } } +/* + * TCG intrinsics + */ + +static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) +{ + if (ret == arg) { + return; + } + switch (type) { + case TCG_TYPE_I32: + case TCG_TYPE_I64: + tcg_out_opc_imm(s, OPC_ADDI, ret, arg, 0); + break; + default: + g_assert_not_reached(); + } +} + +static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, + tcg_target_long val) +{ +#if TCG_TARGET_REG_BITS == 64 + tcg_target_long lo = sextract64(val, 0, 12); +#else + tcg_target_long lo = sextract32(val, 0, 12); +#endif + tcg_target_long hi = val - lo; + int shift; + tcg_target_long tmp; + + RISCVInsn add32_op = TCG_TARGET_REG_BITS == 64 ? OPC_ADDIW : OPC_ADDI; + +#if TCG_TARGET_REG_BITS == 64 + ptrdiff_t offset = tcg_pcrel_diff(s, (void *)val); +#endif + + if (TCG_TARGET_REG_BITS == 32 || val == (int32_t)val) { + tcg_out_opc_upper(s, OPC_LUI, rd, hi); + if (lo != 0) { + tcg_out_opc_imm(s, add32_op, rd, rd, lo); + } + + return; + } + + /* We can only be here if TCG_TARGET_REG_BITS != 32 */ + if (offset == sextract64(offset, 1, 31) << 1) { + tcg_out_opc_upper(s, OPC_AUIPC, rd, 0); + tcg_out_opc_imm(s, OPC_ADDI, rd, rd, 0); + reloc_call(s->code_ptr - 2, (tcg_insn_unit *)val); + return; + } + + shift = ctz64(val); + tmp = val >> shift; + + if (tmp == sextract64(tmp, 0, 12)) { + tcg_out_opc_imm(s, OPC_ADDI, rd, TCG_REG_ZERO, 1); + tcg_out_opc_imm(s, OPC_SLLI, rd, rd, ctz64(val)); + } else if (!(val >> 31 == 0 || val >> 31 == -1)) { + shift = ctz64(hi); + hi >>= shift; + tcg_out_movi(s, type, rd, hi); + tcg_out_opc_imm(s, OPC_SLLI, rd, rd, shift); + if (lo != 0) { + tcg_out_opc_imm(s, OPC_ADDI, rd, rd, lo); + } + } else { + if (hi != 0) { + tcg_out_opc_upper(s, OPC_LUI, rd, hi); + } + if (lo != 0) { + tcg_out_opc_imm(s, add32_op, rd, hi == 0 ? TCG_REG_ZERO : rd, lo); + } + } +} + void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, uintptr_t addr) {