From patchwork Thu Feb 13 22:51:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 183450 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1093782ile; Thu, 13 Feb 2020 15:09:44 -0800 (PST) X-Google-Smtp-Source: APXvYqxIJQ41lRGHFgf+6JQI03ewTCHuWvlnjhQQkRH8OkRhArzlG916iYqGSEyfHzPeHUQwcrXb X-Received: by 2002:a0c:f98a:: with SMTP id t10mr14061812qvn.144.1581635383952; Thu, 13 Feb 2020 15:09:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581635383; cv=none; d=google.com; s=arc-20160816; b=GcId5BIce1h/TcnTS2EuJJrLXA4hJssKDGWEFD++EgWB1fSftjh/HrUo3xWYj+9Jj1 e/5N/bwTWndJ/Uk5jSt+kK1XbxOY5U6MdEHZL+UUcesL3+pNOhaBg9oc7cFi+zCQXhHc qToRF58JBRGTuU3+OEoUxzYxR9sxsRl/2c4MfrCYojdHVq7obhwR00kaNdPqE8g1a0fi jKiP4H0woIiy5EZ4/ad+uF0eNCwaLsQ3l/IlL1XqLmNvFPY3cOPGeEpmCW09zV+64MLo 6z19OalZ2q9ApYPMu5zGbSFmTXxhOxBHypDmyK0kQ4kRQKWa2c6LPSlJ+Jhtowc0Uxia zNJg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=eMpV6oHUHsBouYuIbNXi5ILIhk0UHtJDCsWgmHAo3NA=; b=rEl+mxsRG1MT00Hj4sGs0j579163uxehM6EHKpSwxoLrlim+gLPzbOht4UjhxAw4l2 KpkBPQRL59/DVxgHcMSgTpkruQTCkvwVwCXPeSGBD2uWcCpXpHf1iiDGgHKhhlcsymH6 vGHT0z7+fAkHADzJj/n6aDfCvX6CesjlfjASwIvBYtCbE40Hw/8dzOH+/wnoqUWuQiLt 1ciOib9yXGZaGcAEz/vIL6K9nOyvwH7oMKOSQftxgofhnL6Rs1w5LJnN3Vg/mKsmaSGP H9NhAhz/7k7mU3ypn/3s9dotIioRq1sHZUC9Qai0VMad6Rc6OZ+z2DcpZlujZI25vg/E b+lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yWYuM7YL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.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. [209.51.188.17]) by mx.google.com with ESMTPS id j15si2010830qkg.108.2020.02.13.15.09.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2020 15:09:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yWYuM7YL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.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 ([::1]:60736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2Nc7-0005Z5-Fn for patch@linaro.org; Thu, 13 Feb 2020 18:09:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55401) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2NTW-0002Rr-LU for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2NTU-0002UX-S0 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:50 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39525) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2NTU-0002SN-JA for qemu-devel@nongnu.org; Thu, 13 Feb 2020 18:00:48 -0500 Received: by mail-wm1-x343.google.com with SMTP id c84so8644677wme.4 for ; Thu, 13 Feb 2020 15:00:48 -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 :mime-version:content-transfer-encoding; bh=eMpV6oHUHsBouYuIbNXi5ILIhk0UHtJDCsWgmHAo3NA=; b=yWYuM7YLKyGrZb4442dJsx+3FP9M68tyeTgoIjDsy/KBHCLHqV5KYl2OB82ZG8T2z3 0irZnQLeJS0D71zNnIvuzHviUrfkUqRX538O+rbr6YTDR6XuoCGeBkNYmLc3WoOyshrp ydVvsSCAQyTSe3g0/skIhHY9ydPWVmFTlTGXutOFH+uo2ukrrP6z2EvWcOZawJd9ZAiL GhM3O62anngurZ8Fnea3fLmm1CRTyj/boxu5G3bjwogyTKh8CTOgryh3ApMOwg72jdbG HKy/bomz7fWgvyVK6bDmhG0lq1mSc7kwjYvaJUeToNAX+WiabNf9Z4r+rJ3SvHCQ+9D1 /V3w== 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:mime-version:content-transfer-encoding; bh=eMpV6oHUHsBouYuIbNXi5ILIhk0UHtJDCsWgmHAo3NA=; b=BEfLq2wBIc6LNvr10Z+JJUHkpo8TizEpLQx6Mmj5XZ3YXaQm7wjNXU7Ay2OGFmALMg XBUYOJjhtXqoSBb49ILygaVTEF7BUJ05Wzr8YWDvBEvQvYek3Hcoq2tsK4K8HE1W+T1I V1c1Uyb2IeMMe3nx9mprvqfDk3IrRDJDMD/3VoC1gVQk5vckeCu++QmyZvfEVli/sNZr epJnBAW0g4aAP+Zi3VJ0yc7KYgnN6Ug12gZA84/nJyNDrlIQC110JXGFResMCCFo16nE bjaTl6sgbDmQ3O5TxGyHjQyGLWPHHkpS0UKFWO/EUKLHlGF4MXjJK/FABByWR37ffC4m IExg== X-Gm-Message-State: APjAAAUA4zs67DTaQMjqNbJmTU+BYHM0NawON0NPwTVJ6ywLn3/ycbz6 EBW+yRMWTa4Fad7QNEDkFzhLVA== X-Received: by 2002:a1c:4c13:: with SMTP id z19mr322801wmf.75.1581634847347; Thu, 13 Feb 2020 15:00:47 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a8sm4904539wmc.20.2020.02.13.15.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 15:00:45 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D7EF01FF9E; Thu, 13 Feb 2020 22:51:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 14/19] target/riscv: progressively load the instruction during decode Date: Thu, 13 Feb 2020 22:51:04 +0000 Message-Id: <20200213225109.13120-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213225109.13120-1-alex.bennee@linaro.org> References: <20200213225109.13120-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, Sagar Karandikar , Alistair Francis , "open list:RISC-V TCG CPUs" , stefanb@linux.vnet.ibm.com, aaron@os.amperecomputing.com, cota@braap.org, marcandre.lureau@redhat.com, robert.foley@linaro.org, richard.henderson@linaro.org, stefanha@redhat.com, peter.puhov@linaro.org, kuhn.chenqun@huawei.com, =?utf-8?q?Alex_Benn=C3=A9e?= , berrange@redhat.com, Bastian Koppelmann , f4bug@amsat.org, robhenry@microsoft.com, Palmer Dabbelt , pbonzini@redhat.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The plugin system would throw up a harmless warning when it detected that a disassembly of an instruction didn't use all it's bytes. Fix the riscv decoder to only load the instruction bytes it needs as it needs them. This drops opcode from the ctx in favour if passing the appropriately sized opcode down a few levels of the decode. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - use extract16 for uint16_t opcodes squash! target/riscv: progressively load the instruction during decode --- target/riscv/instmap.h | 8 ++++---- target/riscv/translate.c | 40 +++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 23 deletions(-) -- 2.20.1 Reviewed-by: Alistair Francis Reviewed-by: Robert Foley diff --git a/target/riscv/instmap.h b/target/riscv/instmap.h index f8ad7d60fd5..40b6d2b64de 100644 --- a/target/riscv/instmap.h +++ b/target/riscv/instmap.h @@ -344,8 +344,8 @@ enum { #define GET_C_LW_IMM(inst) ((extract32(inst, 6, 1) << 2) \ | (extract32(inst, 10, 3) << 3) \ | (extract32(inst, 5, 1) << 6)) -#define GET_C_LD_IMM(inst) ((extract32(inst, 10, 3) << 3) \ - | (extract32(inst, 5, 2) << 6)) +#define GET_C_LD_IMM(inst) ((extract16(inst, 10, 3) << 3) \ + | (extract16(inst, 5, 2) << 6)) #define GET_C_J_IMM(inst) ((extract32(inst, 3, 3) << 1) \ | (extract32(inst, 11, 1) << 4) \ | (extract32(inst, 2, 1) << 5) \ @@ -363,7 +363,7 @@ enum { #define GET_C_RD(inst) GET_RD(inst) #define GET_C_RS1(inst) GET_RD(inst) #define GET_C_RS2(inst) extract32(inst, 2, 5) -#define GET_C_RS1S(inst) (8 + extract32(inst, 7, 3)) -#define GET_C_RS2S(inst) (8 + extract32(inst, 2, 3)) +#define GET_C_RS1S(inst) (8 + extract16(inst, 7, 3)) +#define GET_C_RS2S(inst) (8 + extract16(inst, 2, 3)) #endif diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 14dc71156be..d5de7f468a7 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -44,7 +44,6 @@ typedef struct DisasContext { /* pc_succ_insn points to the instruction following base.pc_next */ target_ulong pc_succ_insn; target_ulong priv_ver; - uint32_t opcode; uint32_t mstatus_fs; uint32_t misa; uint32_t mem_idx; @@ -492,45 +491,45 @@ static void gen_set_rm(DisasContext *ctx, int rm) tcg_temp_free_i32(t0); } -static void decode_RV32_64C0(DisasContext *ctx) +static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode) { - uint8_t funct3 = extract32(ctx->opcode, 13, 3); - uint8_t rd_rs2 = GET_C_RS2S(ctx->opcode); - uint8_t rs1s = GET_C_RS1S(ctx->opcode); + uint8_t funct3 = extract16(opcode, 13, 3); + uint8_t rd_rs2 = GET_C_RS2S(opcode); + uint8_t rs1s = GET_C_RS1S(opcode); switch (funct3) { case 3: #if defined(TARGET_RISCV64) /* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/ gen_load_c(ctx, OPC_RISC_LD, rd_rs2, rs1s, - GET_C_LD_IMM(ctx->opcode)); + GET_C_LD_IMM(opcode)); #else /* C.FLW (RV32) -> flw rd', offset[6:2](rs1')*/ gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s, - GET_C_LW_IMM(ctx->opcode)); + GET_C_LW_IMM(opcode)); #endif break; case 7: #if defined(TARGET_RISCV64) /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/ gen_store_c(ctx, OPC_RISC_SD, rs1s, rd_rs2, - GET_C_LD_IMM(ctx->opcode)); + GET_C_LD_IMM(opcode)); #else /* C.FSW (RV32) -> fsw rs2', offset[6:2](rs1')*/ gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2, - GET_C_LW_IMM(ctx->opcode)); + GET_C_LW_IMM(opcode)); #endif break; } } -static void decode_RV32_64C(DisasContext *ctx) +static void decode_RV32_64C(DisasContext *ctx, uint16_t opcode) { - uint8_t op = extract32(ctx->opcode, 0, 2); + uint8_t op = extract16(opcode, 0, 2); switch (op) { case 0: - decode_RV32_64C0(ctx); + decode_RV32_64C0(ctx, opcode); break; } } @@ -709,22 +708,25 @@ static bool gen_shift(DisasContext *ctx, arg_r *a, /* Include the auto-generated decoder for 16 bit insn */ #include "decode_insn16.inc.c" -static void decode_opc(DisasContext *ctx) +static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) { /* check for compressed insn */ - if (extract32(ctx->opcode, 0, 2) != 3) { + if (extract16(opcode, 0, 2) != 3) { if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { ctx->pc_succ_insn = ctx->base.pc_next + 2; - if (!decode_insn16(ctx, ctx->opcode)) { + if (!decode_insn16(ctx, opcode)) { /* fall back to old decoder */ - decode_RV32_64C(ctx); + decode_RV32_64C(ctx, opcode); } } } else { + uint32_t opcode32 = opcode; + opcode32 = deposit32(opcode32, 16, 16, + translator_lduw(env, ctx->base.pc_next + 2)); ctx->pc_succ_insn = ctx->base.pc_next + 4; - if (!decode_insn32(ctx, ctx->opcode)) { + if (!decode_insn32(ctx, opcode32)) { gen_exception_illegal(ctx); } } @@ -776,9 +778,9 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *ctx = container_of(dcbase, DisasContext, base); CPURISCVState *env = cpu->env_ptr; + uint16_t opcode16 = translator_lduw(env, ctx->base.pc_next); - ctx->opcode = translator_ldl(env, ctx->base.pc_next); - decode_opc(ctx); + decode_opc(env, ctx, opcode16); ctx->base.pc_next = ctx->pc_succ_insn; if (ctx->base.is_jmp == DISAS_NEXT) {