From patchwork Mon Feb 20 18:40:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655116 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp1552233wrc; Mon, 20 Feb 2023 10:45:03 -0800 (PST) X-Google-Smtp-Source: AK7set8XA5pNVry54ixXINqQJFZ58lHrgIIAtJteX+wEL/xH7kqjRMTIWyA9kCwZXZy62dGNdv5w X-Received: by 2002:a05:6214:ac6:b0:570:ccb9:a4d0 with SMTP id g6-20020a0562140ac600b00570ccb9a4d0mr2581684qvi.16.1676918703438; Mon, 20 Feb 2023 10:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676918703; cv=none; d=google.com; s=arc-20160816; b=P/kaSk4NrAj/dcsDG4ye8iAuQE6/madXoMu86R5nf49bfeaFptb3sbAvyFx3m8UkUp o/R0qb1dNCmD2k6xb86CHiZft1sCRH7hthnpbdTNtg7VU9Fok6FO84UM2xgnT0k9lMHj KmfNBUYmtjhgspDGchitZBWSeGqVEWd0XdLkYkILhDOWWf10Ib6sZjuvrmHeJqwN5ntf jKFlID+u1WEgWw0vhuCpUi27GO0KMdJCDTjTRJVTg3WcbXtubqRB9657DKMYzpD0FHY4 zJI/Q63yItWkwG9L7xovbeT/0lu+EQlrKxAejKaczx7RumD3JOWibnvuI+uNppbpET10 pmVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=KFZlwHO4prWAnCAMSFhTLLBR8p62EDJKLKSzIIGOyMU=; b=XqLI+n/XEXYGMXIPftj9gcwKIb3Q9mj36ezD9WFIvj11WRBdf7c9LyCBsqY3M480gQ XaWdkJ+jZFVyYc7UodRYCBDtxHtAeDz4At8JcDWg+Z/GkmgndvVN7C0IWH6YbvTVnivZ RH/UvODBGZ68Jh26aJjkAz3BBhX32c/ePJ4XGA0yL7AlbzWrXoL8Mqj3Bv1UXZEtMOCw leImLi6tW+VkXbhaCkW+H+vwej/Ai8xSMkH7wQZHRPwbsJZdfGRciOgkpLHxkxlQrg+R lLuawKHbGN0OucoDNOFxvoAe+cbfmgjMyeqGvwjdw2D1K9NDS+EitgAZ2DR96cO5n1Bm xqFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cQVpIT2K; 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=pass (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 q11-20020a0cf5cb000000b0056c23bb1597si1292032qvm.88.2023.02.20.10.45.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Feb 2023 10:45:03 -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=pass header.i=@linaro.org header.s=google header.b=cQVpIT2K; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUB87-0005nE-GQ; Mon, 20 Feb 2023 13:43:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUB6d-0004et-52 for qemu-devel@nongnu.org; Mon, 20 Feb 2023 13:41:47 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUB6a-0004DU-3o for qemu-devel@nongnu.org; Mon, 20 Feb 2023 13:41:42 -0500 Received: by mail-pl1-x62b.google.com with SMTP id u17so2574163plh.6 for ; Mon, 20 Feb 2023 10:41:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KFZlwHO4prWAnCAMSFhTLLBR8p62EDJKLKSzIIGOyMU=; b=cQVpIT2K3kOstQbR4hJGNvQdEJEKl24vzLdXWvcTxi1sY1/W73pI3rPIcuTGHfL6n/ RHPa0888LqYAbCefA7SfhVEtd+JtU6600HqskkfXDkNw0kBDTsI02fDd0Ri+GVQGj1fU q9maHmbYURgJkO2C4L2+cPTYhMHJhXTSn/P1W0Bhpy1fKnZGyVbBzlMtmPl240dpjD0q FUXJfS/1AuqD99lHrixLXc/6mguKyOg1q52wINzKQZQ9J1HHMZpduJDf4ID5TL8wR65R qFtALQunQW/WK95DI9ptZH40O4QM3mNFJ4KZiOjkhsrrZIO7IFp19ua7Z79qb3Kmzie9 EU+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KFZlwHO4prWAnCAMSFhTLLBR8p62EDJKLKSzIIGOyMU=; b=DoZQ/T9qsm17EheTZrUA4uC1sn8Ak4kgqPdo587gg/St69xbwU/h58lxWYngf/Gz6J DQqxtMgLWjjFK0QXJLyfjKp62dV6Mj24CQmaaT1w9Tx+xmAhxpn6RZEZdPMLsJO7OvsR bVnkhSlVfVh2Ld5RiMq4ICuOXwUsC7MXYiiXRq4F9J5RtJK/fV1aQkSzBrLERgMNIJ1F J3sXQMpxFYs4Wa+AWSIVqk+lRUGvT5zkXtRace1+FTCmZZriAJsGnIBINhyRjQT7rSoo Ijcaex6NxhXm/QGz4Nr57TJc0XhwAcsK00MjHkew7RAAWbP80YRnJCi/RPE6ShV+jcsY Sqrw== X-Gm-Message-State: AO0yUKVebnBSIlS4SObHg+SegL71dvt5QDxaZIfXwJ0uzwRzud9tms5F TiE1+14FNE1C8yrMI3tgScYgg5ZM6yypVQRwdU8= X-Received: by 2002:a17:903:5cf:b0:19a:b664:78d with SMTP id kf15-20020a17090305cf00b0019ab664078dmr3128932plb.60.1676918494666; Mon, 20 Feb 2023 10:41:34 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id jk20-20020a170903331400b0019258bcf3ffsm1911676plb.56.2023.02.20.10.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 10:41:34 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: thuth@redhat.com, qemu-s390x@nongnu.org, Ilya Leoshkevich Subject: [PATCH v4 21/27] target/s390x: Simplify help_branch Date: Mon, 20 Feb 2023 08:40:46 -1000 Message-Id: <20230220184052.163465-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220184052.163465-1-richard.henderson@linaro.org> References: <20230220184052.163465-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Always use a tcg branch, instead of movcond. The movcond was not a bad idea before PER was added, but since then we have either 2 or 3 actions to perform on each leg of the branch, and multiple movcond is inefficient. Reorder the taken branch to be fallthrough of the tcg branch. This will be helpful later with TARGET_TB_PCREL. Reviewed-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- target/s390x/tcg/translate.c | 154 ++++++++++------------------------- 1 file changed, 44 insertions(+), 110 deletions(-) diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 878b220bf6..4e39cf1646 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -385,28 +385,6 @@ static void per_branch_disp(DisasContext *s, int64_t disp) #endif } -static void per_branch_cond(DisasContext *s, TCGCond cond, - TCGv_i64 arg1, TCGv_i64 arg2) -{ -#ifndef CONFIG_USER_ONLY - if (per_enabled(s)) { - TCGLabel *lab = gen_new_label(); - tcg_gen_brcond_i64(tcg_invert_cond(cond), arg1, arg2, lab); - - gen_psw_addr_disp(s, gbea, 0); - gen_helper_per_branch(cpu_env, gbea, psw_addr); - - gen_set_label(lab); - } else { - TCGv_i64 pc = tcg_temp_new_i64(); - - gen_psw_addr_disp(s, pc, 0); - tcg_gen_movcond_i64(cond, gbea, arg1, arg2, gbea, pc); - tcg_temp_free_i64(pc); - } -#endif -} - static void per_breaking_event(DisasContext *s) { #ifndef CONFIG_USER_ONLY @@ -1221,7 +1199,6 @@ static DisasJumpType help_branch(DisasContext *s, DisasCompare *c, { DisasJumpType ret; int64_t disp = (int64_t)imm * 2; - uint64_t dest = s->base.pc_next + disp; TCGLabel *lab; /* Take care of the special cases first. */ @@ -1251,96 +1228,53 @@ static DisasJumpType help_branch(DisasContext *s, DisasCompare *c, } } - if (use_goto_tb(s, s->base.pc_next + s->ilen)) { - if (is_imm && use_goto_tb(s, dest)) { - /* Both exits can use goto_tb. */ - update_cc_op(s); + update_cc_op(s); - lab = gen_new_label(); - if (c->is_64) { - tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab); - } else { - tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab); - } - - /* Branch not taken. */ - tcg_gen_goto_tb(0); - gen_psw_addr_disp(s, psw_addr, s->ilen); - tcg_gen_exit_tb(s->base.tb, 0); - - /* Branch taken. */ - gen_set_label(lab); - per_breaking_event(s); - tcg_gen_goto_tb(1); - gen_psw_addr_disp(s, psw_addr, disp); - tcg_gen_exit_tb(s->base.tb, 1); - - ret = DISAS_NORETURN; - } else { - /* Fallthru can use goto_tb, but taken branch cannot. */ - /* Store taken branch destination before the brcond. This - avoids having to allocate a new local temp to hold it. - We'll overwrite this in the not taken case anyway. */ - if (!is_imm) { - tcg_gen_mov_i64(psw_addr, cdest); - } - - lab = gen_new_label(); - if (c->is_64) { - tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab); - } else { - tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab); - } - - /* Branch not taken. */ - update_cc_op(s); - tcg_gen_goto_tb(0); - gen_psw_addr_disp(s, psw_addr, s->ilen); - tcg_gen_exit_tb(s->base.tb, 0); - - gen_set_label(lab); - if (is_imm) { - gen_psw_addr_disp(s, psw_addr, disp); - } - per_breaking_event(s); - ret = DISAS_PC_UPDATED; - } - } else { - /* Fallthru cannot use goto_tb. This by itself is vanishingly rare. - Most commonly we're single-stepping or some other condition that - disables all use of goto_tb. Just update the PC and exit. */ - - TCGv_i64 next = tcg_temp_new_i64(); - - gen_psw_addr_disp(s, next, s->ilen); - if (is_imm) { - cdest = tcg_temp_new_i64(); - gen_psw_addr_disp(s, cdest, disp); - } - - if (c->is_64) { - tcg_gen_movcond_i64(c->cond, psw_addr, c->u.s64.a, c->u.s64.b, - cdest, next); - per_branch_cond(s, c->cond, c->u.s64.a, c->u.s64.b); - } else { - TCGv_i32 t0 = tcg_temp_new_i32(); - TCGv_i64 t1 = tcg_temp_new_i64(); - TCGv_i64 z = tcg_constant_i64(0); - tcg_gen_setcond_i32(c->cond, t0, c->u.s32.a, c->u.s32.b); - tcg_gen_extu_i32_i64(t1, t0); - tcg_temp_free_i32(t0); - tcg_gen_movcond_i64(TCG_COND_NE, psw_addr, t1, z, cdest, next); - per_branch_cond(s, TCG_COND_NE, t1, z); - tcg_temp_free_i64(t1); - } - - tcg_temp_free_i64(next); - if (is_imm) { - tcg_temp_free_i64(cdest); - } - ret = DISAS_PC_UPDATED; + /* + * Store taken branch destination before the brcond. This + * avoids having to allocate a new local temp to hold it. + * We'll overwrite this in the not taken case anyway. + */ + if (!is_imm) { + tcg_gen_mov_i64(psw_addr, cdest); } + lab = gen_new_label(); + if (c->is_64) { + tcg_gen_brcond_i64(tcg_invert_cond(c->cond), + c->u.s64.a, c->u.s64.b, lab); + } else { + tcg_gen_brcond_i32(tcg_invert_cond(c->cond), + c->u.s32.a, c->u.s32.b, lab); + } + + /* Branch taken. */ + if (is_imm) { + gen_psw_addr_disp(s, psw_addr, disp); + } + per_branch_dest(s, psw_addr); + + if (is_imm && use_goto_tb(s, s->base.pc_next + disp)) { + tcg_gen_goto_tb(0); + tcg_gen_exit_tb(s->base.tb, 0); + } else { + tcg_gen_lookup_and_goto_ptr(); + } + + gen_set_label(lab); + + /* Branch not taken. */ + if (use_goto_tb(s, s->base.pc_next + s->ilen)) { + tcg_gen_goto_tb(1); + gen_psw_addr_disp(s, psw_addr, s->ilen); + tcg_gen_exit_tb(s->base.tb, 1); + } else { + gen_psw_addr_disp(s, psw_addr, s->ilen); + tcg_gen_lookup_and_goto_ptr(); + } + + ret = DISAS_NORETURN; + egress: free_compare(c); return ret;