From patchwork Tue Dec 19 05:38:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10122373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2663B60390 for ; Tue, 19 Dec 2017 05:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16D7829029 for ; Tue, 19 Dec 2017 05:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B6A529047; Tue, 19 Dec 2017 05:41: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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 45F3629029 for ; Tue, 19 Dec 2017 05:41:09 +0000 (UTC) Received: from localhost ([::1]:50595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRAeK-00026r-Gw for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Dec 2017 00:41:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRAct-0000iA-Oq for qemu-devel@nongnu.org; Tue, 19 Dec 2017 00:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRAcr-0001lr-S5 for qemu-devel@nongnu.org; Tue, 19 Dec 2017 00:39:39 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:39465) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eRAcr-0001lH-JG for qemu-devel@nongnu.org; Tue, 19 Dec 2017 00:39:37 -0500 Received: by mail-wr0-x243.google.com with SMTP id a41so16966374wra.6 for ; Mon, 18 Dec 2017 21:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0Sw5UopAOxYWnl2/mNJRTce2ZH4nM0MvS7IpzBJ0P8k=; b=OQImgC5K9BZMilTvmkDQk2Rw8JvE6PkCMSv4ELfQW3qVE0Ma4YIq/ZAduE9QGPhjvt gTE+ESuuUDnaH4PbZyLg4zJpMshWbZ/JP8ZtxR3c/Ztd9dERAfZd/US5SX1Pm/qjAM5h IC9PA1BbQ3CbUVG374rdfJl8fOcGvk9Uq5PRCx1Y1YZsw/qD2R3HatTlm0YzX2gJ+X9w Z3+GLqwS/bZCETSUeO3vYHVBPShrPEZkelxmu1h2ayN0UJImVDODZBURNDEyvvWO+7Rb W7MEYOSKUHbG65cvYjVN8QBlZFNmgLiMIDM8heHU+VrdkzjlI4UZ/zNNw75MUv86i4zl 0+4A== 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=0Sw5UopAOxYWnl2/mNJRTce2ZH4nM0MvS7IpzBJ0P8k=; b=e8rUWMG44oC7Dx2lfKshTg79+RXQvCKLQNwx+/jHcT9UpH/La5SFdvD7pP76enPYLd UtmelxMdRcY8iAMFTK+VxxlUkVRCw9CBS0y/rdj8tDzkD6P4vIveU8eWm47fj1nPnXeC OsV8oN03QuTfAtCMwYrGBW0vrjMQmPGLjrpQ2uvFiI1xgSu7IENmB8B9ug+p3BjBWmfq O7xbVvhH9hasm+s/BobDbHswUqwuGmvHcHsOgThuQSz0+5xYHaOkwjg3dgw1kf3coy+K eXieUxX/JC4TNBlYDjrDbGCGzLscE0etJ1+RoLKna7ghpDf97bXfT9TctHc8ZkU7eZhd MaRw== X-Gm-Message-State: AKGB3mIcgJVwpGceI1qjT4X1zOC7YhkY7TS/SmhlV6UfFNkFxaRPRHsP AnWi+D2J7RkjeEtUOL3UHcbYcw== X-Google-Smtp-Source: ACJfBou/nP1+2KFv5noiBxTyBYrdd1NXwlTjFO+E4tcZXueD6EaQxx0pqETeGhdGOqSfd9p2a0MqbQ== X-Received: by 10.25.225.143 with SMTP id l15mr1335037lfk.38.1513661976283; Mon, 18 Dec 2017 21:39:36 -0800 (PST) Received: from octofox.net (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id f67sm673187lfb.83.2017.12.18.21.39.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Dec 2017 21:39:35 -0800 (PST) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 21:38:40 -0800 Message-Id: <1513661932-6849-5-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1513661932-6849-1-git-send-email-jcmvbkbc@gmail.com> References: <1513661932-6849-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v2 04/16] target/xtensa: extract FPU2000 opcode translators 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: Max Filippov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP FPU2000 implements basic single-precision floating point operations and can be replaced with a different implementation, like DFPU or HiFi. Move FPU2000 opcode translators into separate functions and list them in a separate array. Signed-off-by: Max Filippov --- target/xtensa/cpu.h | 1 + target/xtensa/translate.c | 374 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 375 insertions(+) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index d8f40346269d..9a34cc825e96 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -349,6 +349,7 @@ typedef struct XtensaOpcodeTranslators { } XtensaOpcodeTranslators; extern const XtensaOpcodeTranslators xtensa_core_opcodes; +extern const XtensaOpcodeTranslators xtensa_fpu2000_opcodes; struct XtensaConfig { const char *name; diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 1c227380a64d..f6a53cdfc28f 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -6433,3 +6433,377 @@ const XtensaOpcodeTranslators xtensa_core_opcodes = { .num_opcodes = ARRAY_SIZE(core_ops), .opcode = core_ops, }; + + +static void translate_abs_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_abs_s(cpu_FR[arg[0]], cpu_FR[arg[1]]); + } +} + +static void translate_add_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_add_s(cpu_FR[arg[0]], cpu_env, + cpu_FR[arg[1]], cpu_FR[arg[2]]); + } +} + +enum { + COMPARE_UN, + COMPARE_OEQ, + COMPARE_UEQ, + COMPARE_OLT, + COMPARE_ULT, + COMPARE_OLE, + COMPARE_ULE, +}; + +static void translate_compare_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + static void (* const helper[])(TCGv_env env, TCGv_i32 bit, + TCGv_i32 s, TCGv_i32 t) = { + [COMPARE_UN] = gen_helper_un_s, + [COMPARE_OEQ] = gen_helper_oeq_s, + [COMPARE_UEQ] = gen_helper_ueq_s, + [COMPARE_OLT] = gen_helper_olt_s, + [COMPARE_ULT] = gen_helper_ult_s, + [COMPARE_OLE] = gen_helper_ole_s, + [COMPARE_ULE] = gen_helper_ule_s, + }; + + if (gen_check_cpenable(dc, 0)) { + TCGv_i32 bit = tcg_const_i32(1 << arg[0]); + + helper[par[0]](cpu_env, bit, cpu_FR[arg[1]], cpu_FR[arg[2]]); + tcg_temp_free(bit); + } +} + +static void translate_float_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[1]) && gen_check_cpenable(dc, 0)) { + TCGv_i32 scale = tcg_const_i32(-arg[2]); + + if (par[0]) { + gen_helper_uitof(cpu_FR[arg[0]], cpu_env, cpu_R[arg[1]], scale); + } else { + gen_helper_itof(cpu_FR[arg[0]], cpu_env, cpu_R[arg[1]], scale); + } + tcg_temp_free(scale); + } +} + +static void translate_ftoi_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[0]) && gen_check_cpenable(dc, 0)) { + TCGv_i32 rounding_mode = tcg_const_i32(par[0]); + TCGv_i32 scale = tcg_const_i32(arg[2]); + + if (par[1]) { + gen_helper_ftoui(cpu_R[arg[0]], cpu_FR[arg[1]], + rounding_mode, scale); + } else { + gen_helper_ftoi(cpu_R[arg[0]], cpu_FR[arg[1]], + rounding_mode, scale); + } + tcg_temp_free(rounding_mode); + tcg_temp_free(scale); + } +} + +static void translate_ldsti(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[1]) && gen_check_cpenable(dc, 0)) { + TCGv_i32 addr = tcg_temp_new_i32(); + + tcg_gen_addi_i32(addr, cpu_R[arg[1]], arg[2]); + gen_load_store_alignment(dc, 2, addr, false); + if (par[0]) { + tcg_gen_qemu_st32(cpu_FR[arg[0]], addr, dc->cring); + } else { + tcg_gen_qemu_ld32u(cpu_FR[arg[0]], addr, dc->cring); + } + if (par[1]) { + tcg_gen_mov_i32(cpu_R[arg[1]], addr); + } + tcg_temp_free(addr); + } +} + +static void translate_ldstx(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check2(dc, arg[1], arg[2]) && gen_check_cpenable(dc, 0)) { + TCGv_i32 addr = tcg_temp_new_i32(); + + tcg_gen_add_i32(addr, cpu_R[arg[1]], cpu_R[arg[2]]); + gen_load_store_alignment(dc, 2, addr, false); + if (par[0]) { + tcg_gen_qemu_st32(cpu_FR[arg[0]], addr, dc->cring); + } else { + tcg_gen_qemu_ld32u(cpu_FR[arg[0]], addr, dc->cring); + } + if (par[1]) { + tcg_gen_mov_i32(cpu_R[arg[1]], addr); + } + tcg_temp_free(addr); + } +} + +static void translate_madd_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_madd_s(cpu_FR[arg[0]], cpu_env, + cpu_FR[arg[0]], cpu_FR[arg[1]], cpu_FR[arg[2]]); + } +} + +static void translate_mov_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + tcg_gen_mov_i32(cpu_FR[arg[0]], cpu_FR[arg[1]]); + } +} + +static void translate_movcond_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[2]) && gen_check_cpenable(dc, 0)) { + TCGv_i32 zero = tcg_const_i32(0); + + tcg_gen_movcond_i32(par[0], cpu_FR[arg[0]], + cpu_R[arg[2]], zero, + cpu_FR[arg[1]], cpu_FR[arg[2]]); + tcg_temp_free(zero); + } +} + +static void translate_movp_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + TCGv_i32 zero = tcg_const_i32(0); + TCGv_i32 tmp = tcg_temp_new_i32(); + + tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << arg[2]); + tcg_gen_movcond_i32(par[0], + cpu_FR[arg[0]], tmp, zero, + cpu_FR[arg[1]], cpu_FR[arg[0]]); + tcg_temp_free(tmp); + tcg_temp_free(zero); + } +} + +static void translate_mul_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_mul_s(cpu_FR[arg[0]], cpu_env, + cpu_FR[arg[1]], cpu_FR[arg[2]]); + } +} + +static void translate_msub_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_msub_s(cpu_FR[arg[0]], cpu_env, + cpu_FR[arg[0]], cpu_FR[arg[1]], cpu_FR[arg[2]]); + } +} + +static void translate_neg_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_neg_s(cpu_FR[arg[0]], cpu_FR[arg[1]]); + } +} + +static void translate_rfr_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[0]) && + gen_check_cpenable(dc, 0)) { + tcg_gen_mov_i32(cpu_R[arg[0]], cpu_FR[arg[1]]); + } +} + +static void translate_sub_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_check_cpenable(dc, 0)) { + gen_helper_sub_s(cpu_FR[arg[0]], cpu_env, + cpu_FR[arg[1]], cpu_FR[arg[2]]); + } +} + +static void translate_wfr_s(DisasContext *dc, const uint32_t arg[], + const uint32_t par[]) +{ + if (gen_window_check1(dc, arg[1]) && + gen_check_cpenable(dc, 0)) { + tcg_gen_mov_i32(cpu_FR[arg[0]], cpu_R[arg[1]]); + } +} + +static const XtensaOpcodeOps fpu2000_ops[] = { + { + .name = "abs.s", + .translate = translate_abs_s, + }, { + .name = "add.s", + .translate = translate_add_s, + }, { + .name = "ceil.s", + .translate = translate_ftoi_s, + .par = (const uint32_t[]){float_round_up, false}, + }, { + .name = "float.s", + .translate = translate_float_s, + .par = (const uint32_t[]){false}, + }, { + .name = "floor.s", + .translate = translate_ftoi_s, + .par = (const uint32_t[]){float_round_down, false}, + }, { + .name = "lsi", + .translate = translate_ldsti, + .par = (const uint32_t[]){false, false}, + }, { + .name = "lsiu", + .translate = translate_ldsti, + .par = (const uint32_t[]){false, true}, + }, { + .name = "lsx", + .translate = translate_ldstx, + .par = (const uint32_t[]){false, false}, + }, { + .name = "lsxu", + .translate = translate_ldstx, + .par = (const uint32_t[]){false, true}, + }, { + .name = "madd.s", + .translate = translate_madd_s, + }, { + .name = "mov.s", + .translate = translate_mov_s, + }, { + .name = "moveqz.s", + .translate = translate_movcond_s, + .par = (const uint32_t[]){TCG_COND_EQ}, + }, { + .name = "movf.s", + .translate = translate_movp_s, + .par = (const uint32_t[]){TCG_COND_EQ}, + }, { + .name = "movgez.s", + .translate = translate_movcond_s, + .par = (const uint32_t[]){TCG_COND_GE}, + }, { + .name = "movltz.s", + .translate = translate_movcond_s, + .par = (const uint32_t[]){TCG_COND_LT}, + }, { + .name = "movnez.s", + .translate = translate_movcond_s, + .par = (const uint32_t[]){TCG_COND_NE}, + }, { + .name = "movt.s", + .translate = translate_movp_s, + .par = (const uint32_t[]){TCG_COND_NE}, + }, { + .name = "msub.s", + .translate = translate_msub_s, + }, { + .name = "mul.s", + .translate = translate_mul_s, + }, { + .name = "neg.s", + .translate = translate_neg_s, + }, { + .name = "oeq.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_OEQ}, + }, { + .name = "ole.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_OLE}, + }, { + .name = "olt.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_OLT}, + }, { + .name = "rfr.s", + .translate = translate_rfr_s, + }, { + .name = "round.s", + .translate = translate_ftoi_s, + .par = (const uint32_t[]){float_round_nearest_even, false}, + }, { + .name = "ssi", + .translate = translate_ldsti, + .par = (const uint32_t[]){true, false}, + }, { + .name = "ssiu", + .translate = translate_ldsti, + .par = (const uint32_t[]){true, true}, + }, { + .name = "ssx", + .translate = translate_ldstx, + .par = (const uint32_t[]){true, false}, + }, { + .name = "ssxu", + .translate = translate_ldstx, + .par = (const uint32_t[]){true, true}, + }, { + .name = "sub.s", + .translate = translate_sub_s, + }, { + .name = "trunc.s", + .translate = translate_ftoi_s, + .par = (const uint32_t[]){float_round_to_zero, false}, + }, { + .name = "ueq.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_UEQ}, + }, { + .name = "ufloat.s", + .translate = translate_float_s, + .par = (const uint32_t[]){true}, + }, { + .name = "ule.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_ULE}, + }, { + .name = "ult.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_ULT}, + }, { + .name = "un.s", + .translate = translate_compare_s, + .par = (const uint32_t[]){COMPARE_UN}, + }, { + .name = "utrunc.s", + .translate = translate_ftoi_s, + .par = (const uint32_t[]){float_round_to_zero, true}, + }, { + .name = "wfr.s", + .translate = translate_wfr_s, + }, +}; + +const XtensaOpcodeTranslators xtensa_fpu2000_opcodes = { + .num_opcodes = ARRAY_SIZE(fpu2000_ops), + .opcode = fpu2000_ops, +};