From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28DCDC47254 for ; Tue, 5 May 2020 08:23:38 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89E422068E for ; Tue, 5 May 2020 08:23:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="azveeUto" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89E422068E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49GXml4by6zDqQY for ; Tue, 5 May 2020 18:23:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::243; helo=mail-oi1-x243.google.com; envelope-from=jniethe5@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=azveeUto; dkim-atps=neutral Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49GWcc54m1zDqPR for ; Tue, 5 May 2020 17:31:28 +1000 (AEST) Received: by mail-oi1-x243.google.com with SMTP id o24so1210276oic.0 for ; Tue, 05 May 2020 00:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CROAVDaphBM0ZvcTotPO5LP8zXi9erwYvjqaiwQBdCc=; b=azveeUtoX4pP8ZWnShgr5SkcJtC3Od1a+71aTA+0QoQVF78YPy3a7odXu6V2Zl+Xxz z5zTJNqOr1kiGd7FixG9hRgdVXrIls5ZDEuH7p07Wg8yf5+jprSI1SMTkLU2b8yc9DES Kik5Ror8dlev9YWRqEUqGhws4BwD9PLknkxEN72yk0MHmCe70UBM/fDlh9EqZjmkx1zW x8P/PFpcPRR1FZQl5TDboUAzhndRwEPoC6PDx6jA8Fk/uHUvPbUDB9DFJa62grVgmhTa OhjZ1CBQdS56G/g+XbQGPOaXX/hzAdaxT547bsGNroOUenktNx577jFNVJF7uD2TGzA/ t32Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CROAVDaphBM0ZvcTotPO5LP8zXi9erwYvjqaiwQBdCc=; b=M6kzRyVXdk3myHpzVpgRgaEfqhi2/kBN3WRGjuZQZLfHVdo+zOdlzVZfuPtynPA5QW koIOAx8nxjlcdJ72od9IuuOuy1HE2hU5z09rW88lqkNc4n3z6ytE89xpGxtofQwFq9S9 3xglsz6/hI4Tnv4qBu5U05NWpYS0ENewQHjew7wyDPwxoAGeQ4hbBiUeG0vf+S/JLUHY PyOE6hUV63Oc8Nv8xj5j5B2HAYBM4gkKvkQzBq0QC5vZxEK09Fw+RTLzIv3paKxCqASq vA24o8NaXa6waN1z4TeZI+oqGkZpyM5SEOyhUjE0f5Z8aoauHBDCLKtKpw6Wl98cyDhr Rn3A== X-Gm-Message-State: AGi0Pub4x1CezpSUMEpHigBovjDL4UH71KNzI7BtS0O4cwm2BjqVk7/p 6wOvjvtX2x5HE7TsrRQ6VzlnwmbJRHxNPm4VpXM= X-Google-Smtp-Source: APiQypJ8sv0f+PkX17mg8iM9yX/nAib2VCOmKtD6DIHGxHrrK0WIq4Fc6ZOhZTqoR0Ei0Nl+h4InSc7p//fBR64Ecaw= X-Received: by 2002:aca:d6c1:: with SMTP id n184mr1521808oig.126.1588663884884; Tue, 05 May 2020 00:31:24 -0700 (PDT) MIME-Version: 1.0 References: <20200501034220.8982-1-jniethe5@gmail.com> <20200501034220.8982-5-jniethe5@gmail.com> <871rnyeu4t.fsf@mpe.ellerman.id.au> In-Reply-To: <871rnyeu4t.fsf@mpe.ellerman.id.au> From: Jordan Niethe Date: Tue, 5 May 2020 17:31:13 +1000 Message-ID: Subject: Re: [PATCH v7 04/28] powerpc/xmon: Use bitwise calculations in_breakpoint_table() To: Michael Ellerman Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Popple , Nicholas Piggin , Balamuruhan S , naveen.n.rao@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, Daniel Axtens Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, May 5, 2020 at 5:08 PM Michael Ellerman wrote: > > Jordan Niethe writes: > > A modulo operation is used for calculating the current offset from a > > breakpoint within the breakpoint table. As instruction lengths are > > always a power of 2, this can be replaced with a bitwise 'and'. The > > current check for word alignment can be replaced with checking that the > > lower 2 bits are not set. > > > > Suggested-by: Christophe Leroy > > Signed-off-by: Jordan Niethe > > --- > > v6: New to series > > --- > > arch/powerpc/xmon/xmon.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c > > index bbfea22f4a96..e122f0c8a044 100644 > > --- a/arch/powerpc/xmon/xmon.c > > +++ b/arch/powerpc/xmon/xmon.c > > @@ -857,8 +857,8 @@ static struct bpt *in_breakpoint_table(unsigned long nip, unsigned long *offp) > > off = nip - (unsigned long) bpt_table; > > if (off >= sizeof(bpt_table)) > > return NULL; > > - *offp = off % BPT_SIZE; > > - if (*offp != 0 && *offp != 4) > > + *offp = off & (BPT_SIZE - 1); > > + if (off & 3) > > return NULL; > > It would be even better if you didn't hard code the 3 wouldn't it? > The three is just checking word alignment, which I think was the intention of the previous - if (*offp != 0 && *offp != 4) But using BPT_SIZE is is a different calculation. BPT_SIZE == 2 * sizeof(unsigned int) == 8 Which would mean the trap of the breakpoint pair of instructions would return NULL. > eg: > > + *offp = off & (BPT_SIZE - 1); > + if (off & (BPT_SIZE - 1)) > return NULL; > > cheers