From patchwork Wed Dec 19 19:17:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10738051 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 9D84814DE for ; Wed, 19 Dec 2018 19:29:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E56027F9F for ; Wed, 19 Dec 2018 19:29:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82B2D27FA3; Wed, 19 Dec 2018 19:29:32 +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 04EB427F9F for ; Wed, 19 Dec 2018 19:29:32 +0000 (UTC) Received: from localhost ([::1]:33789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhX9-0002k3-7p for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Dec 2018 14:29:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZhLq-0001Ky-PM for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:17:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZhLm-0000HU-Rs for qemu-devel@nongnu.org; Wed, 19 Dec 2018 14:17:50 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:43402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZhLm-0000Gq-IC; Wed, 19 Dec 2018 14:17:46 -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=1545247067; x=1576783067; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=MTgOhhUMsT7aZraYP6giKW6HdnX3J1wQteJiYuppo6I=; b=rBl1vv+2ZDt5qN1Nj25ykcsMivgAZMAlE0MbRge+ugn35BmbPtFN7I4M zCRQqHTgqDH/8R3U4pnkmisJDuJVH9eS0Egv6EwnM5czV6TFNWuvVOceQ DL1Bm2egRlh55POJuRram2YgJlWv5vLUVgevCu4Mn6VNfr7BIjUD03SaF TynXhBeQjSdj3yv4Q7HQXh5Tfy8pvyB3bdvcJGzc91hXS4h/cQpxkdtH7 mvSjRPPsH97gokZutT1UzKsEjmLmTz1W1hwBG0+B3WNi+Rnn0smQoa1cQ fhb7FFT/Wwhs1BSO+e8AhDI3xwhTOVB+jdLtCj8dkKNeDwlVeKsHmAe+A w==; X-IronPort-AV: E=Sophos;i="5.56,373,1539619200"; d="scan'208";a="98234202" Received: from mail-dm3nam03lp2056.outbound.protection.outlook.com (HELO NAM03-DM3-obe.outbound.protection.outlook.com) ([104.47.41.56]) by ob1.hgst.iphmx.com with ESMTP; 20 Dec 2018 03:17:45 +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=QDpXuK5hgy3y2w3yrwwpoZTyy72ju0uVWl+Nz7aBGYE=; b=dQRjnFR4iQGHLxcInntptvdGu5Piv+McoS1RFmc/1fla2djYsUN4Y6E1iTK5p8c/gHKucoQhK9fUA5gSPZv/utZ2SMSj3agSASg3vh9gTtoZYjcfowQGjnedbN3+NKZc1piIblJ3Q0wnltJFj2XpA8x/MWJnUdjESpXeZ5sGpPE= 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:43 +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:43 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [PATCH v2 08/23] riscv: tcg-target: Add the immediate encoders Thread-Index: AQHUl8+EBljUZ+BLu0OVMUCz1MlsmQ== Date: Wed, 19 Dec 2018 19:17:43 +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: BYAPR05CA0049.namprd05.prod.outlook.com (2603:10b6:a03:74::26) 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:7xZNZGznaw2+0mT4Rd+XbwZbVGB0YvA7ylZUKeKetsBV4y3/JniGVqeni00EFCGqfBbSuTfzJSHJO3qqhvZx0l7IetvTKio1SEZ66pAZ9ad6JeBz9rHg3UqVKMrQ3bpctENKy2qkZy9oY/yDdHVcRhQgtjlDs2Zol6ndoCLICITir+g6Yknu+VwNLRLbG5+1dVulVTr9UBTlwVA5jrQeol38Z0nn7hh2pIkHazmQ1+Cmby6boVuYnibndlvuvIAPZhB6vvLSA1h4idbHilpyNZDYES7z3R0d9JOOQAivaBa9n0ELqaAyAmc4l7lBDzneqvgNQc4y0ssmnMxeP9ywZyO/FJ/4V32t8F89P5UxntvXt1JkvLWKdx70+WzCZmLYG0F71/MokJ1nMj8IFOBlJJT86D32TwiGHb9yLVQEXvUdXCzZbNaPbPrg6cExqJUouajpVZUgXqfBGSiHjD3lTg==; 5:1FJG1uvS29XeAIKhD/DS0ffxpvxJ70FWceiFg0570gwXKhz6mtISdgXRyUUf4sr6rj+IDZqhP5A/Ki0aVYNO5kS/XJhOcVFGSyRAJOJlaadl8k3Ps/TiVuWisZoqZdlYfT0pKlDa1v0njgroRgRP/BdrEz0hw2n4iGfLbiSldAY=; 7:WY55dkba4gJCqDyzIv5GlQGVL04gCTwE8nfHdDDb/QD3nrCkZjNXoMokbXObjfVM3VRkhMSFA88pRu/LjRgit/5jWUKJY4xJS0eMPXw9v0+8O6y+XRxezUrknmqRGS8gVGGwB4gNUR8MzTbv3UOK0g== x-ms-office365-filtering-correlation-id: 3107c2eb-8758-406a-6d78-08d665e6a6c9 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)(575784001)(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)(14773001); 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: S3fyvPdriZMa6m3esF5Pdyd1UF1TCT4Qbh4gCEJpqO0CH0a9IKl9DKaw0nM/95b46EnPlc0RaZpGPlPQrNi8wqxTONNiw09t6tzHC+22BMtSIiAijCVG5y+8r3eN8dFH0pjrAFUITkqVInORY3nt00QmP29gE5cjlz0nTwt5pKx+xVybclBpuUeI5eTVFzmzZQWehBlW8ukeB+kMv+x3qPKJ8d+k2ADfACjbflrK65vqK7/lejUcxzBQVrCKpMpG5Wfo1enB7GqPTFuvSU61qLXi1AW6ATBraY9McfJuf5zMqfSQPIJyXaNdp89sIn9h spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3107c2eb-8758-406a-6d78-08d665e6a6c9 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2018 19:17:43.7268 (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 08/23] riscv: tcg-target: Add the immediate encoders 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 | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index f853d01803..08838027cd 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -284,3 +284,93 @@ typedef enum { OPC_FENCE = 0x0000000f, } RISCVInsn; + +/* + * RISC-V immediate and instruction encoders (excludes 16-bit RVC) + */ + +/* Type-R */ + +static int32_t encode_r(RISCVInsn opc, TCGReg rd, TCGReg rs1, TCGReg rs2) +{ + return opc | (rd & 0x1f) << 7 | (rs1 & 0x1f) << 15 | (rs2 & 0x1f) << 20; +} + +/* Type-I */ + +static int32_t encode_imm12(uint32_t imm) +{ + return (imm & 0xfff) << 20; +} + +static int32_t encode_i(RISCVInsn opc, TCGReg rd, TCGReg rs1, uint32_t imm) +{ + return opc | (rd & 0x1f) << 7 | (rs1 & 0x1f) << 15 | encode_imm12(imm); +} + +/* Type-S */ + +static int32_t encode_simm12(uint32_t imm) +{ + int32_t ret = 0; + + ret |= (imm & 0xFE0) << 20; + ret |= (imm & 0x1F) << 7; + + return ret; +} + +static int32_t encode_s(RISCVInsn opc, TCGReg rs1, TCGReg rs2, uint32_t imm) +{ + return opc | (rs1 & 0x1f) << 15 | (rs2 & 0x1f) << 20 | encode_simm12(imm); +} + +/* Type-SB */ + +static int32_t encode_sbimm12(uint32_t imm) +{ + int32_t ret = 0; + + ret |= (imm & 0x1000) << 19; + ret |= (imm & 0x7e0) << 20; + ret |= (imm & 0x1e) << 7; + ret |= (imm & 0x800) >> 4; + + return ret; +} + +static int32_t encode_sb(RISCVInsn opc, TCGReg rs1, TCGReg rs2, uint32_t imm) +{ + return opc | (rs1 & 0x1f) << 15 | (rs2 & 0x1f) << 20 | encode_sbimm12(imm); +} + +/* Type-U */ + +static int32_t encode_uimm20(uint32_t imm) +{ + return imm & 0xfffff000; +} + +static int32_t encode_u(RISCVInsn opc, TCGReg rd, uint32_t imm) +{ + return opc | (rd & 0x1f) << 7 | encode_uimm20(imm); +} + +/* Type-UJ */ + +static int32_t encode_ujimm20(uint32_t imm) +{ + int32_t ret = 0; + + ret |= (imm & 0x0007fe) << (21 - 1); + ret |= (imm & 0x000800) << (20 - 11); + ret |= (imm & 0x0ff000) << (12 - 12); + ret |= (imm & 0x100000) << (31 - 20); + + return ret; +} + +static int32_t encode_uj(RISCVInsn opc, TCGReg rd, uint32_t imm) +{ + return opc | (rd & 0x1f) << 7 | encode_ujimm20(imm); +}