From nobody Mon Feb 9 16:52:27 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1632983570840569.9500444767447; Wed, 29 Sep 2021 23:32:50 -0700 (PDT) Received: from localhost ([::1]:59038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVpcf-0001sd-K4 for importer@patchew.org; Thu, 30 Sep 2021 02:32:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVot1-00025u-Jh; Thu, 30 Sep 2021 01:45:39 -0400 Received: from gandalf.ozlabs.org ([150.107.74.76]:36387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVosy-0003z1-PQ; Thu, 30 Sep 2021 01:45:38 -0400 Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4HKhyR3fcsz4xc4; Thu, 30 Sep 2021 15:44:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1632980671; bh=UMkMeBz0iXJHFhgjDKXhYopMYO6XHGmIApyz3w+uefE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBZgduBXUrY0dl/Vx+qAu/D2ujTHKsRwOt0dsQaV1ZG4PenEXDvbRS4O0SY2aONyg MC5lQxuD60Tb53AYtnPeip/2nkULiONF9Qja39Q2n/fzHzqc03aibKzlA46vBbgSJU gMLXAmTJLluf8XIzKouaT+8K3TabgYRpLERQzvaw= From: David Gibson To: peter.maydell@linaro.org Subject: [PULL 33/44] target/ppc: Fix 64-bit decrementer Date: Thu, 30 Sep 2021 15:44:15 +1000 Message-Id: <20210930054426.357344-34-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210930054426.357344-1-david@gibson.dropbear.id.au> References: <20210930054426.357344-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=150.107.74.76; envelope-from=dgibson@gandalf.ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: mark.cave-ayland@ilande.co.uk, qemu-devel@nongnu.org, groug@kaod.org, Luis Fernando Fujita Pires , hpoussin@reactos.org, clg@kaod.org, qemu-ppc@nongnu.org, philmd@redhat.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1632983572558100001 From: C=C3=A9dric Le Goater The current way the mask is built can overflow with a 64-bit decrementer. Use sextract64() to extract the signed values and remove the logic to handle negative values which has become useless. Cc: Luis Fernando Fujita Pires Fixes: a8dafa525181 ("target/ppc: Implement large decrementer support for T= CG") Signed-off-by: C=C3=A9dric Le Goater Message-Id: <20210920061203.989563-5-clg@kaod.org> Reviewed-by: Luis Pires Signed-off-by: David Gibson --- hw/ppc/ppc.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index b813ef732e..f5d012f860 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -821,14 +821,12 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uin= t64_t *nextp, CPUPPCState *env =3D &cpu->env; ppc_tb_t *tb_env =3D env->tb_env; uint64_t now, next; - bool negative; + int64_t signed_value; + int64_t signed_decr; =20 /* Truncate value to decr_width and sign extend for simplicity */ - value &=3D ((1ULL << nr_bits) - 1); - negative =3D !!(value & (1ULL << (nr_bits - 1))); - if (negative) { - value |=3D (0xFFFFFFFFULL << nr_bits); - } + signed_value =3D sextract64(value, 0, nr_bits); + signed_decr =3D sextract64(decr, 0, nr_bits); =20 trace_ppc_decr_store(nr_bits, decr, value); =20 @@ -850,16 +848,16 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uin= t64_t *nextp, * On MSB edge based DEC implementations the MSB going from 0 -> 1 tri= ggers * an edge interrupt, so raise it here too. */ - if ((value < 3) || - ((tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL) && negative) || - ((tb_env->flags & PPC_DECR_UNDERFLOW_TRIGGERED) && negative - && !(decr & (1ULL << (nr_bits - 1))))) { + if ((signed_value < 3) || + ((tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL) && signed_value < 0) || + ((tb_env->flags & PPC_DECR_UNDERFLOW_TRIGGERED) && signed_value < 0 + && signed_decr >=3D 0)) { (*raise_excp)(cpu); return; } =20 /* On MSB level based systems a 0 for the MSB stops interrupt delivery= */ - if (!negative && (tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL)) { + if (signed_value >=3D 0 && (tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL))= { (*lower_excp)(cpu); } =20 --=20 2.31.1