From patchwork Tue Dec 25 20:54:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 154482 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5214270ljp; Tue, 25 Dec 2018 13:05:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN4pgSFEj5t9Qd97CHJmM1SwUm0vxlndY9jgsVycMj5u5KfWwK2bTpav9pqRenxlze82XbNC X-Received: by 2002:a0c:cc8c:: with SMTP id f12mr16622497qvl.102.1545771940836; Tue, 25 Dec 2018 13:05:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545771940; cv=none; d=google.com; s=arc-20160816; b=Nyg113rGqzuPt4WfJdmvI8W4VQwRw0OjvwmY5oTveBw1+Y48wz9/iGTcgAZMizwBnN pMgV3Azz3hg/86JEA0qHQ5IGDB1Odj5Bu35r/CRx1Qe4rgNZ6NDDAyNdlvxuldLcL8R9 IPa2Du7vh2ccl6XHtgBYH0EBGNlMes2CMaqUrTUlSFhtCDeoU5rL53YSmS1/jZZcBZ2V YO8r6h2tHy1i7gvJDEW8agh1g/gV+w0XuNMj1/2DaVKZyjjYatppLaDEO1ax5vQos2SV iNSFBwWz5pLg0ZMQegu4S++zCONZpnSQoHmKiaSpvMrIn9AYaHUaDpwjmd5y+UpSp0gK Ccng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=tzGjnIw1cASb7ypX0n1KQ8i7Nh+q+RBdVYFISRi2ZVY=; b=kCZee+JKTSity0pM8UaN0ztj5xEKcH2Yv12XrJJxDRKBSte5R0HriJZf3kYP4c3Ll7 xsWOAnmRwTBi+IJiOiayfaPzZjOLETFIPIXNRQviyf9WyWpXTImx0kRPBDKzGdNhAqvr 9GnWbJOZqS8eUKKlOmx44d0WSNIGuXdrtkRDc8Ht/P73GTulhuaHQWeX54foepI9lZxE jZTVn4k5XCWQy7emlRf7kL2uSPAy4DmUzXtjRSwx4CZhe2xwJMkmICIHkj1I01hyh4Cs G03T8+EeqEL0mZdPdX+OQ13wNgAkx081IIii0aCQCzYa1rOcPA+TVdgwrqh83fvOvxQL 3jfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D0zT1ynj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id l82si11307584qki.89.2018.12.25.13.05.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 25 Dec 2018 13:05:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D0zT1ynj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:43090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbttU-0006Ow-9Q for patch@linaro.org; Tue, 25 Dec 2018 16:05:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtkp-0004Ro-NG for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbtko-0007Ap-U4 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:43 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbtko-0007A0-NH for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:42 -0500 Received: by mail-pl1-x642.google.com with SMTP id e11so6796824plt.11 for ; Tue, 25 Dec 2018 12:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tzGjnIw1cASb7ypX0n1KQ8i7Nh+q+RBdVYFISRi2ZVY=; b=D0zT1ynj98h9/CW5rEPLG31rlDCihLkAYAaRx95WNHWgNHP/35OI0HKz+Yqcr3p3BK jdJpLBN9kHn9F6cxFP8zNXYTdn9cwjFk4uSP2xNTCu0HEZb+yEQGlIxkSoIHZRTJtRVW Hjs0h5/qbnwEOSFPC3uWmB2paxEH1PLNkzLd0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tzGjnIw1cASb7ypX0n1KQ8i7Nh+q+RBdVYFISRi2ZVY=; b=arjmOUGJrrM4gmohgELK5UzDnCtjBRV7FVYcRYJE/MLs9N05xx4snaej1tcnu6JyPJ rQr7JsNfeX2ZAUo5x1L955rsY1mcOJxIgtcK44SeddM0+M+U1CMeFj5tJi9cAPJa7nMo NNBekeH7TIqjGdl7xAYauGvN1cZAphiu8wXt2wY6s4h9fh/1pwPPq8GhzNut86t3VPPO AdVBCOxazVailU32K8eAQYmPH+CNJPemlCpiuDLFzO9eDq+OlzpRb9Uj+eZM7lWmvuqD nhm6TtIPozva8i6QYccTjZH7P+CXXp76eewM3GiFXdIHqBkDAb3sxVOmI2FDgNRaEIis T5iA== X-Gm-Message-State: AJcUuke47cNe49CfM/8eUFgNr18dS3u1nFUBGrShMUKUhLHJ4mvcNhlN ejmJrLR4RCx0Xj7HWsE4SAMAm8UQhOk= X-Received: by 2002:a17:902:622:: with SMTP id 31mr17121986plg.171.1545771401418; Tue, 25 Dec 2018 12:56:41 -0800 (PST) Received: from cloudburst.home (c211-28-135-144.sunsh3.vic.optusnet.com.au. [211.28.135.144]) by smtp.gmail.com with ESMTPSA id t21sm48501628pgg.24.2018.12.25.12.56.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Dec 2018 12:56:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2018 07:54:55 +1100 Message-Id: <20181225205529.10874-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181225205529.10874-1-richard.henderson@linaro.org> References: <20181225205529.10874-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PULL 08/42] tcg/riscv: 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: peter.maydell@linaro.org, Michael Clark , Alistair Francis Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Signed-off-by: Alistair Francis Signed-off-by: Michael Clark Reviewed-by: Richard Henderson Message-Id: Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.inc.c | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) -- 2.17.2 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); +}