From patchwork Sat Dec 8 00:47:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10719053 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 574A913BF for ; Sat, 8 Dec 2018 00:52:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4240E2DE84 for ; Sat, 8 Dec 2018 00:52:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 337962DEC5; Sat, 8 Dec 2018 00:52:10 +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 A46282DE84 for ; Sat, 8 Dec 2018 00:52:09 +0000 (UTC) Received: from localhost ([::1]:48531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVQqm-0005fD-QY for patchwork-qemu-devel@patchwork.kernel.org; Fri, 07 Dec 2018 19:52:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVQmU-0000KH-Ms for qemu-devel@nongnu.org; Fri, 07 Dec 2018 19:47:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVQmQ-0000k2-Ix for qemu-devel@nongnu.org; Fri, 07 Dec 2018 19:47:42 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:52393) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gVQmQ-0000jK-8L; Fri, 07 Dec 2018 19:47:38 -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=1544230067; x=1575766067; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=9tbAH7zUjUK0UWCIDYnjapyrphnFegBfBsvLK6FcLOs=; b=TKsn7rHp19jsL5D2eUB5xgTSMKe3Lkxg6LpW1oKHaICVQZz+YOzdev3p Wzafcmq9CGlOvy7mK/1XGCDqDNZPGrfppST7a60/3P35S0Qgyq5hUr3PN 7izyHI0O4qMzXHJqcHaRbvR1PVzFYW14l06SgdMbcTBPujMHdkUkty62+ 32RZ8zRy97O5Oqc9N/pkV3hF7b6xadjFYQci3qvmWCmN9I+Gf/yNOYG0h 4ACEc73RAnOenbZ7JgI+zA0/vl5rBX13xk+EbjzQoDiM+aGPNw4tLjD3v rfmQtkzuq2XsYqCrbSmHygEv3nNhKPX4v9j2B28pPsil9eobb8iWEYThU g==; X-IronPort-AV: E=Sophos;i="5.56,328,1539619200"; d="scan'208";a="194003425" Received: from mail-sn1nam04lp2053.outbound.protection.outlook.com (HELO NAM04-SN1-obe.outbound.protection.outlook.com) ([104.47.44.53]) by ob1.hgst.iphmx.com with ESMTP; 08 Dec 2018 08:47:44 +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=U7b1Y0L8GK2oyN5rM93wUVjtWX6OOQjDTYbpA4nyr54=; b=EA0QNsHxkaGxla1IdPDLtHPnly6H/jd7Q9MJk1lHfY+mQLaze88CJUN/4NsYWHQjiFeCa5tVvvKETQhRm+Qb6jSexux5h5R2CIOQw2T99WxVvFIIk14kUNf7dsbfovMCRrxlm3HBZGoqt20RxDD9OYJ+HeoTcjN2zZC/hVBIk7Q= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB3725.namprd04.prod.outlook.com (10.172.169.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1404.18; Sat, 8 Dec 2018 00:47:35 +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:47:35 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "qemu-riscv@nongnu.org" Thread-Topic: [RFC v3 09/24] riscv: tcg-target: Add the immediate encoders Thread-Index: AQHUjo+c3edfsf4vKkWw+I8KCVykeA== Date: Sat, 8 Dec 2018 00:47:35 +0000 Message-ID: <2e6df8dd71cfdc9391131548c483ef65fe858428.1544229872.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: BYAPR05CA0037.namprd05.prod.outlook.com (2603:10b6:a03:74::14) 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; MWHPR04MB3725; 6:h0QDFjeB85CX+hJV6oknRk1y0P0H5DRkDU0934ONxgn7S920F1J39wOe3hJbWXl0awCklhqf3Zjh8YnGS+8XKK87jvZYX0NePTiI2MH3XAfkUVuNPi8vEE+hrVp/tLwLhzzG22Cc5llLLaCp8lZQxjOE9KvvTcX5G16J/Q62qZBgMqRpS15nXOXB5monqh5OKqIdjr/Li7dn2dRBomABNveubkhq80XQ/WaFGJg4hs+cozsNGOP7nU0da0IL3gteRE4wbib2ujE8PDUYLQwiNi8uMlMoJQw2UUsqklnNxrHFATERH1VdEUSYrqKMPL6o2C3bQxaeG5uE2pqHop47HkiZmpcG1VEv5EZaA6b8sCe/rwVxzWo2ftgp4Y5KpZcaeu+MQkS9CywspNBt+rtDhVkmrMAgqwru+sIxfC/MTHugny+6+DeS7bCnq7Gr7asBA3yCg0KQrxCM2UMO8X+nhA==; 5:5/Tz/hh4AY8w6lAY4IBfJbrbErGet0c826KvSjY3iFMzZNfAGz6qEGWDFiuIT5Lw5xg2oePtv0UwEPhBLt7BlZSYPtgbF7QLpWR36kPXwhyEfCCrjK+rFFKEnAOcRTgHYGD8EUYuJFco9gyZ1fRTMfz/cRlQqOx4vCB9LCFuOAg=; 7:S6ffLIw71bcnQspabqQslCV3UmCOGp0BCNAmNgSAQQBmUt+3o6zSQEzqJ0ZujPwqrDvPqRyZOXDizE9SHuxrfF4jmUit/+bUJxBTQAuv4AbQSis6KfxfXYs8eJnygn3fbCEbknVcvzT6iXnvPyKEpA== x-ms-office365-filtering-correlation-id: 2843d977-a129-47b2-99b9-08d65ca6be64 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:MWHPR04MB3725; x-ms-traffictypediagnostic: MWHPR04MB3725: 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)(10201501046)(3002001)(93006095)(93001095)(3231455)(999002)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991095); SRVR:MWHPR04MB3725; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB3725; x-forefront-prvs: 0880FB6EC1 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(346002)(136003)(39860400002)(396003)(189003)(199004)(68736007)(476003)(53936002)(71200400001)(8676002)(71190400001)(11346002)(44832011)(446003)(2616005)(106356001)(486006)(4326008)(66066001)(6512007)(39060400002)(5660300001)(86362001)(81156014)(118296001)(81166006)(575784001)(386003)(2906002)(8936002)(6506007)(14454004)(99286004)(3846002)(52116002)(478600001)(6116002)(25786009)(72206003)(305945005)(97736004)(6436002)(6486002)(76176011)(26005)(7736002)(186003)(36756003)(110136005)(105586002)(2501003)(50226002)(102836004)(54906003)(316002)(256004)(14773001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB3725; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-microsoft-antispam-message-info: cHFREYuxzpJLaje5cW6AqUxPvBdu6oeMUZ1detc6DC6Oun+nR3TIYP3MBdKVfOPtxQrxiQTYxDEOmPH6IoaCxeUai9sLjgdOMBBMl89fUVJR8nZ7fKvf/XrM53Kpvj8keYFLTBc6smrVpZSW5owJuR/IeLgB7fnAqyOL9bZxRo1eJfJ60i+W/tya3b53eWPOaRfxaNv3hevoFN64vPcylhloj6Pec43pHZA+HHTkEWtf5N+E5vqUO8hV80skmi6Z/Wead++s1iU5ffRlRobpfPJKJvLeZQPCv41u8wfFhzWIzig8T85SH5DRZx2499SCjN7sLgIjZ/VF4SoQhUJWmKark7bspm0ZdS2iab27RK8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2843d977-a129-47b2-99b9-08d65ca6be64 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2018 00:47:35.0576 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB3725 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [RFC v3 09/24] 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 af1d2c235a..c385ff68ae 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); +}