OSDN Git Service

powerpc/xmon: Use bitwise calculations in_breakpoint_table()
authorJordan Niethe <jniethe5@gmail.com>
Wed, 6 May 2020 03:40:24 +0000 (13:40 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 18 May 2020 14:10:36 +0000 (00:10 +1000)
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 <christophe.leroy@c-s.fr>
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Reviewed-by: Alistair Popple <alistair@popple.id.au>
Link: https://lore.kernel.org/r/20200506034050.24806-5-jniethe5@gmail.com
arch/powerpc/xmon/xmon.c

index 948d025..0fa3aae 100644 (file)
@@ -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;
        return bpts + (off / BPT_SIZE);
 }