Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kzaMd-0007SB-HW for mharc-qemu-riscv@gnu.org; Wed, 13 Jan 2021 02:14:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzaMb-0007MM-23 for qemu-riscv@nongnu.org; Wed, 13 Jan 2021 02:14:41 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:53070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kzaMZ-0003zq-8v for qemu-riscv@nongnu.org; Wed, 13 Jan 2021 02:14:40 -0500 Received: by mail-pj1-x1033.google.com with SMTP id v1so562716pjr.2 for ; Tue, 12 Jan 2021 23:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aEip5Hk2/fjLfGZXwReicQlq3aDOOOt574rHluS0oAk=; b=ELmy/UVulmvm7jsn0Ai5jpmTQ4UY/zASOWbG1G46BJwf2bhDHpVaSklRhuxZunO3CV D/Z5nXlpt6iE3jBami3JeQoYwHTasOEPALhdMYp+2+KNRQq1v+6nLUMD8Y8qD1wEfFHU VXE3RZXkezzG90ZEFlIdoWr36x9PyxpkumLAFZ7pIrdo0s4tOmM2nq0282q66p5fLQtZ 1RI0EwXypOUS/OmyUCxCcrY2+VIJOR8QpsNAded457OGCTgPdLhQph4JDsF2hMtNN/W1 giXFPgxVRRiY9obNMy0zIWx4ZA6R5GMu0Jd2imSOwK8wnpGVCig7ctU3hhTjZbHsOQDh vYtQ== 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=aEip5Hk2/fjLfGZXwReicQlq3aDOOOt574rHluS0oAk=; b=TAnTqwIpqTlcjbvwUh/P4CSfSc8hbw3K3nvx570dhzyleTlhBoV+U0jtFh5nzgmU8k jjv56FjmjkBs3vNG5ISvNDsPDR3roGbNRf34tJ0CaPViFr8ZDaat+qjFLEE/yo8Tb8nY R2oGzRRClLXRVCm5cQ2lq27xwSquKLj76Xpe6ALtm7LjK91dj5dDilNNIKXVSWBIdD0B 5npu8c1YH8x6jrl6gGWuVkBhhHSTyTe81ulYlrIdpaID6KheLOYtC8wfVx+D9a8c9/yn CLGNZ4UbQw/SDSREtWgnQqLxpiRbsoWhF61+LwIvMvAGF+WWtRK9AUB7KiZHmqxM8giH TbzQ== X-Gm-Message-State: AOAM533z9r5ZfYXGeyrexuyIKLFo3z+4XDr+gaATAc1iLaFlXmwb01bh PU73Sg4LMCg82mRZAuPncyO6Yg== X-Google-Smtp-Source: ABdhPJxO5/7RNxR1qK0Y7EJuh+odqt1AZIFRlyu4lOmFaat8B6Gq9yDYgw0/qFqzOXHQPiuoU4rZGw== X-Received: by 2002:a17:90a:cc0a:: with SMTP id b10mr808814pju.59.1610522078049; Tue, 12 Jan 2021 23:14:38 -0800 (PST) Received: from frankchang-ThinkPad-T490.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id l7sm1361888pjy.29.2021.01.12.23.14.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 23:14:37 -0800 (PST) From: frank.chang@sifive.com To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Frank Chang , Palmer Dabbelt , Alistair Francis , Sagar Karandikar , Bastian Koppelmann , Paolo Bonzini Subject: [RFC v4 08/16] target/riscv: add gen_shifti() and gen_shiftiw() helper functions Date: Wed, 13 Jan 2021 15:13:40 +0800 Message-Id: <20210113071350.24852-9-frank.chang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210113071350.24852-1-frank.chang@sifive.com> References: <20210113071350.24852-1-frank.chang@sifive.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=frank.chang@sifive.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-riscv@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2021 07:14:41 -0000 From: Frank Chang Add gen_shifti() and gen_shiftiw() helper functions to reuse the same interfaces for immediate shift instructions. Signed-off-by: Frank Chang --- target/riscv/insn_trans/trans_rvi.c.inc | 54 ++----------------------- target/riscv/translate.c | 43 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 50 deletions(-) diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc index d04ca0394cf..7b894201840 100644 --- a/target/riscv/insn_trans/trans_rvi.c.inc +++ b/target/riscv/insn_trans/trans_rvi.c.inc @@ -261,54 +261,17 @@ static bool trans_andi(DisasContext *ctx, arg_andi *a) } static bool trans_slli(DisasContext *ctx, arg_slli *a) { - if (a->shamt >= TARGET_LONG_BITS) { - return false; - } - - if (a->rd != 0) { - TCGv t = tcg_temp_new(); - gen_get_gpr(t, a->rs1); - - tcg_gen_shli_tl(t, t, a->shamt); - - gen_set_gpr(a->rd, t); - tcg_temp_free(t); - } /* NOP otherwise */ - return true; + return gen_shifti(ctx, a, tcg_gen_shl_tl); } static bool trans_srli(DisasContext *ctx, arg_srli *a) { - if (a->shamt >= TARGET_LONG_BITS) { - return false; - } - - if (a->rd != 0) { - TCGv t = tcg_temp_new(); - gen_get_gpr(t, a->rs1); - - tcg_gen_shri_tl(t, t, a->shamt); - gen_set_gpr(a->rd, t); - tcg_temp_free(t); - } /* NOP otherwise */ - return true; + return gen_shifti(ctx, a, tcg_gen_shr_tl); } static bool trans_srai(DisasContext *ctx, arg_srai *a) { - if (a->shamt >= TARGET_LONG_BITS) { - return false; - } - - if (a->rd != 0) { - TCGv t = tcg_temp_new(); - gen_get_gpr(t, a->rs1); - - tcg_gen_sari_tl(t, t, a->shamt); - gen_set_gpr(a->rd, t); - tcg_temp_free(t); - } /* NOP otherwise */ - return true; + return gen_shifti(ctx, a, tcg_gen_sar_tl); } static bool trans_add(DisasContext *ctx, arg_add *a) @@ -369,16 +332,7 @@ static bool trans_addiw(DisasContext *ctx, arg_addiw *a) static bool trans_slliw(DisasContext *ctx, arg_slliw *a) { - TCGv source1; - source1 = tcg_temp_new(); - gen_get_gpr(source1, a->rs1); - - tcg_gen_shli_tl(source1, source1, a->shamt); - tcg_gen_ext32s_tl(source1, source1); - gen_set_gpr(a->rd, source1); - - tcg_temp_free(source1); - return true; + return gen_shiftiw(ctx, a, tcg_gen_shl_tl); } static bool trans_srliw(DisasContext *ctx, arg_srliw *a) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 53c0c34ce16..8459b6bcf54 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -810,6 +810,49 @@ static bool gen_shift(DisasContext *ctx, arg_r *a, return true; } +static bool gen_shifti(DisasContext *ctx, arg_shift *a, + void(*func)(TCGv, TCGv, TCGv)) +{ + if (a->shamt >= TARGET_LONG_BITS) { + return false; + } + + TCGv source1 = tcg_temp_new(); + TCGv source2 = tcg_temp_new(); + + gen_get_gpr(source1, a->rs1); + + tcg_gen_movi_tl(source2, a->shamt); + (*func)(source1, source1, source2); + + gen_set_gpr(a->rd, source1); + tcg_temp_free(source1); + tcg_temp_free(source2); + return true; +} + +#ifdef TARGET_RISCV64 + +static bool gen_shiftiw(DisasContext *ctx, arg_shift *a, + void(*func)(TCGv, TCGv, TCGv)) +{ + TCGv source1 = tcg_temp_new(); + TCGv source2 = tcg_temp_new(); + + gen_get_gpr(source1, a->rs1); + tcg_gen_movi_tl(source2, a->shamt); + + (*func)(source1, source1, source2); + tcg_gen_ext32s_tl(source1, source1); + + gen_set_gpr(a->rd, source1); + tcg_temp_free(source1); + tcg_temp_free(source2); + return true; +} + +#endif + static void gen_ctz(TCGv ret, TCGv arg1) { tcg_gen_ctzi_tl(ret, arg1, TARGET_LONG_BITS); -- 2.17.1