From patchwork Wed Dec 19 19:17:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10738037 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 B3ACD6C2 for ; Wed, 19 Dec 2018 19:25:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A423627D29 for ; Wed, 19 Dec 2018 19:25:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9833F27E5A; Wed, 19 Dec 2018 19:25:50 +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 E307327D29 for ; Wed, 19 Dec 2018 19:25:49 +0000 (UTC) Received: from localhost ([::1]:33768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhTY-0007nI-Vl for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Dec 2018 14:25:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhLj-0001GV-2G for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:17:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZhLe-0000Db-2X for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:17:42 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:43386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZhLd-0000CF-OA; Wed, 19 Dec 2018 14:17:37 -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=1545247058; x=1576783058; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=eCU3eAPoHbz3xgMfFvlIgMT/7dtwd/EYG10IG5xnEVw=; b=PPltWqh8kqjV3H+XZB3bXzn6ThwX8zMx55KfsfAfwlFfa75rpJ0OWokJ Cqe0KQ4qqyadcDkhS3XrQ+0tMqMeKj4/3N7UNl0vmAqwJ9u/O8ZTgbwEc 51SRouNMvflm5csqdrpLjIPyreqnPc2n9saVNrruWf2R6Y24SU3SV0KZm ZizujD3iywRpWcdP5GO5OlmRyu8utToqMxHaxU/GDh47dfnpbkZh/sGTb OQCYlEDtva1+gaKl9csG1F+tmjjNBjtclJrdoK6TalZ0+wWcqISIk73RH bSLL2wf/yL5xCpYgjzR+JlOHYevHQ5V4R66/YEuNwkfS0Sn1ecdymnvtR g==; X-IronPort-AV: E=Sophos;i="5.56,373,1539619200"; d="scan'208";a="98234189" Received: from mail-dm3nam03lp2058.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) ([104.47.41.58]) by ob1.hgst.iphmx.com with ESMTP; 20 Dec 2018 03:17:33 +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=3AbETKu2PI+17kUHagSQCijIltf24uV2q63c5kIj6ak=; b=dCMBg+RXkKKf0eStUj1FVJ537h/QWCniGMEcFs+kQM2qQAjG/94CUA7viSxi3yCoZ8d3ZSEIG00gI1eDDOTWrvMyEk7FxiKX2LaMAzs6uev5UQu4xVstbE6hCAdbtsjngHTaCRfYdtM4V06L5iPkxykQastKHWlfojn1bTPwPsg= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB0271.namprd04.prod.outlook.com (10.169.202.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.20; Wed, 19 Dec 2018 19:17:32 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::9067:fb44:66b2:7604]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::9067:fb44:66b2:7604%4]) with mapi id 15.20.1446.018; Wed, 19 Dec 2018 19:17:32 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v2 07/23] riscv: tcg-target: Add support for the constraints Thread-Index: AQHUl899MTcXSK0z6EOz3F+jIxdL2w== Date: Wed, 19 Dec 2018 19:17:32 +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: BYAPR05CA0065.namprd05.prod.outlook.com (2603:10b6:a03:74::42) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0271; 6:T7v+HxsjqKnqvMIfL6kraI8oevRsomrm3DA2NpTiW5yLIffwbcMhPpYODyScC1vlE5sCWWVM8STNPhSm/oS/9tXgoD+E1iAP90BjZ17IaDrxOigFCw461OUlbiaiVCLHdRLRr31SaM0wPiIr1DqFcLTGSwyDW3Y5lj7xIeTfVZEZM6MicHmHSJ+zEnhRk1/rPqgi9lDag85ml42tazm1hTCk7YPO4V4Nv/RPZJ9t2aHrQ27MQpd6OMQ01J7Hm3G2C7mmw/UhCqtvpu6kvXd0YoJngzzJ/uhRepMNWvqotrYiFWZPVd8zmrzAT9bRZYGQxvYdyPc+2K+24bTr9/QkIFasE1owuUhePe9JrTRNFNIWj9EnJHl1yBZurbpdQKizYBcBBSR9HFkVhBLgqAu6xFjzyityfqeaBsrrxjgezFpfAo5102ljCyRfkW0i3sV54QwfV7RImW4SBP/HqJptgg==; 5:+pkwiE/hRgtIVJkIlckdXKVJ6r4r9qkwga34AaGrFQJjVZVQnNpJ/UX74zh8MruC1m5syZIPWFLR91Fnb6nLObK4wCUQcXtm1Bj69J8BSULf4H4lxORRl/jNDhC/EjWp4OmDQ7fFNEGby//DwWw8Pnz+9AoV190w1oAu3nUZf/s=; 7:OZdJ5cnMXrWC0VWROHfvHPWyvL4RiucqvQTzCamlqGZ1sdC7emdHoFpPMjYDVGSwIf19j948pwNt9Q8XSmzRy7V+a5AiKSueug7Kw5XNtcYMguySZJdNHdhVMz3WcDPL+n/UFGqOvh+l9lOZbD16PA== x-ms-office365-filtering-correlation-id: 228a8822-1435-40d4-c20e-08d665e69fd9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0271; x-ms-traffictypediagnostic: MWHPR04MB0271: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(5005020)(6040522)(2401047)(8121501046)(93006095)(93001095)(3231475)(944501520)(52105112)(10201501046)(3002001)(6055026)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:MWHPR04MB0271; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0271; x-forefront-prvs: 0891BC3F3D x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(136003)(376002)(346002)(39860400002)(396003)(189003)(199004)(26005)(186003)(36756003)(54906003)(3846002)(99286004)(110136005)(25786009)(6116002)(14454004)(97736004)(102836004)(256004)(71190400001)(7736002)(71200400001)(5660300001)(305945005)(6506007)(386003)(86362001)(105586002)(478600001)(52116002)(316002)(6512007)(8676002)(81166006)(81156014)(118296001)(66066001)(50226002)(53936002)(486006)(44832011)(39060400002)(2616005)(76176011)(446003)(72206003)(106356001)(8936002)(476003)(11346002)(6486002)(68736007)(2501003)(6436002)(4326008)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0271; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-microsoft-antispam-message-info: Rm1ZIsnD2Kl7Up/5OJJvYvZx6BwVklM7w9wlzyoNkK1VezNYjyojNdxwrQ1r9cipxtwfkvrOISIaxC7d7u4AJI0bYFqMucotxBYtwrOUPU5oCHv2RKKPBhdI3MG6eT8V+sEsuukK0jcPO8xAPZ9lKrwnqfy6+lK7oSMbrPArXd14iehVQGcBw8wqm+2WZbfXyD4PG5tjRcaTys1bsOINzxgKB0ZvFPB1H1iYw1u86Ws13v1VpGmj5g3IcNLAeHITj+r+0jiXUqpFAxN4ldagENd+3QWjrXdsDGly9C9XH0iIni7wQVh2MWsBvmXAI4Uc spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 228a8822-1435-40d4-c20e-08d665e69fd9 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 19:17:32.0677 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0271 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.153.144 Subject: [Qemu-devel] [PATCH v2 07/23] riscv: tcg-target: Add support for the constraints 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 Signed-off-by: Richard Henderson Reviewed-by: Richard Henderson --- tcg/riscv/tcg-target.inc.c | 168 +++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index 6c969e3973..f853d01803 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -116,3 +116,171 @@ static const int tcg_target_call_oarg_regs[] = { TCG_REG_A0, TCG_REG_A1, }; + +#define TCG_CT_CONST_ZERO 0x100 +#define TCG_CT_CONST_S12 0x200 +#define TCG_CT_CONST_N12 0x400 +#define TCG_CT_CONST_M12 0x800 + +static inline tcg_target_long sextreg(tcg_target_long val, int pos, int len) +{ + if (TCG_TARGET_REG_BITS == 32) { + return sextract32(val, pos, len); + } else { + return sextract64(val, pos, len); + } +} + +/* parse target specific constraints */ +static const char *target_parse_constraint(TCGArgConstraint *ct, + const char *ct_str, TCGType type) +{ + switch (*ct_str++) { + case 'r': + ct->ct |= TCG_CT_REG; + ct->u.regs = 0xffffffff; + break; + case 'L': + /* qemu_ld/qemu_st constraint */ + ct->ct |= TCG_CT_REG; + ct->u.regs = 0xffffffff; + /* qemu_ld/qemu_st uses TCG_REG_TMP0 */ +#if defined(CONFIG_SOFTMMU) + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[0]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[1]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[2]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[3]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[4]); +#endif + break; + case 'I': + ct->ct |= TCG_CT_CONST_S12; + break; + case 'N': + ct->ct |= TCG_CT_CONST_N12; + break; + case 'M': + ct->ct |= TCG_CT_CONST_M12; + break; + case 'Z': + /* we can use a zero immediate as a zero register argument. */ + ct->ct |= TCG_CT_CONST_ZERO; + break; + default: + return NULL; + } + return ct_str; +} + +/* test if a constant matches the constraint */ +static int tcg_target_const_match(tcg_target_long val, TCGType type, + const TCGArgConstraint *arg_ct) +{ + int ct = arg_ct->ct; + if (ct & TCG_CT_CONST) { + return 1; + } + if ((ct & TCG_CT_CONST_ZERO) && val == 0) { + return 1; + } + if ((ct & TCG_CT_CONST_S12) && val == sextreg(val, 0, 12)) { + return 1; + } + if ((ct & TCG_CT_CONST_N12) && -val == sextreg(-val, 0, 12)) { + return 1; + } + if ((ct & TCG_CT_CONST_M12) && val >= -0xfff && val <= 0xfff) { + return 1; + } + return 0; +} + +/* + * RISC-V Base ISA opcodes (IM) + */ + +typedef enum { + OPC_ADD = 0x33, + OPC_ADDI = 0x13, + OPC_AND = 0x7033, + OPC_ANDI = 0x7013, + OPC_AUIPC = 0x17, + OPC_BEQ = 0x63, + OPC_BGE = 0x5063, + OPC_BGEU = 0x7063, + OPC_BLT = 0x4063, + OPC_BLTU = 0x6063, + OPC_BNE = 0x1063, + OPC_DIV = 0x2004033, + OPC_DIVU = 0x2005033, + OPC_JAL = 0x6f, + OPC_JALR = 0x67, + OPC_LB = 0x3, + OPC_LBU = 0x4003, + OPC_LD = 0x3003, + OPC_LH = 0x1003, + OPC_LHU = 0x5003, + OPC_LUI = 0x37, + OPC_LW = 0x2003, + OPC_LWU = 0x6003, + OPC_MUL = 0x2000033, + OPC_MULH = 0x2001033, + OPC_MULHSU = 0x2002033, + OPC_MULHU = 0x2003033, + OPC_OR = 0x6033, + OPC_ORI = 0x6013, + OPC_REM = 0x2006033, + OPC_REMU = 0x2007033, + OPC_SB = 0x23, + OPC_SD = 0x3023, + OPC_SH = 0x1023, + OPC_SLL = 0x1033, + OPC_SLLI = 0x1013, + OPC_SLT = 0x2033, + OPC_SLTI = 0x2013, + OPC_SLTIU = 0x3013, + OPC_SLTU = 0x3033, + OPC_SRA = 0x40005033, + OPC_SRAI = 0x40005013, + OPC_SRL = 0x5033, + OPC_SRLI = 0x5013, + OPC_SUB = 0x40000033, + OPC_SW = 0x2023, + OPC_XOR = 0x4033, + OPC_XORI = 0x4013, + +#if TCG_TARGET_REG_BITS == 64 + OPC_ADDIW = 0x1b, + OPC_ADDW = 0x3b, + OPC_DIVUW = 0x200503b, + OPC_DIVW = 0x200403b, + OPC_MULW = 0x200003b, + OPC_REMUW = 0x200703b, + OPC_REMW = 0x200603b, + OPC_SLLIW = 0x101b, + OPC_SLLW = 0x103b, + OPC_SRAIW = 0x4000501b, + OPC_SRAW = 0x4000503b, + OPC_SRLIW = 0x501b, + OPC_SRLW = 0x503b, + OPC_SUBW = 0x4000003b, +#else + /* Simplify code throughout by defining aliases for RV32. */ + OPC_ADDIW = OPC_ADDI, + OPC_ADDW = OPC_ADD, + OPC_DIVUW = OPC_DIVU, + OPC_DIVW = OPC_DIV, + OPC_MULW = OPC_MUL, + OPC_REMUW = OPC_REMU, + OPC_REMW = OPC_REM, + OPC_SLLIW = OPC_SLLI, + OPC_SLLW = OPC_SLL, + OPC_SRAIW = OPC_SRAI, + OPC_SRAW = OPC_SRA, + OPC_SRLIW = OPC_SRLI, + OPC_SRLW = OPC_SRL, + OPC_SUBW = OPC_SUB, +#endif + + OPC_FENCE = 0x0000000f, +} RISCVInsn;