From: Christophe Leroy <christophe.leroy@csgroup.eu> To: "Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>, Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@redhat.com>, Benjamin Herrenschmidt <benh@kernel.crashing.org>, Paul Mackerras <paulus@samba.org>, Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1 03/22] powerpc/code-patching: Inline is_offset_in_{cond}_branch_range() Date: Thu, 24 Mar 2022 15:29:53 +0100 [thread overview] Message-ID: <6caf53ffb2f80fb7dac9423a9b4da4e9fa495d8f.1648131740.git.christophe.leroy@csgroup.eu> (raw) In-Reply-To: <cover.1648131740.git.christophe.leroy@csgroup.eu> Test in is_offset_in_branch_range() and is_offset_in_cond_branch_range() are simple tests that are worth inlining. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> --- arch/powerpc/include/asm/code-patching.h | 29 ++++++++++++++++++++++-- arch/powerpc/lib/code-patching.c | 27 ---------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h index 409483b2d0ce..e7c5df50cb4e 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -22,8 +22,33 @@ #define BRANCH_SET_LINK 0x1 #define BRANCH_ABSOLUTE 0x2 -bool is_offset_in_branch_range(long offset); -bool is_offset_in_cond_branch_range(long offset); +/* + * Powerpc branch instruction is : + * + * 0 6 30 31 + * +---------+----------------+---+---+ + * | opcode | LI |AA |LK | + * +---------+----------------+---+---+ + * Where AA = 0 and LK = 0 + * + * LI is a signed 24 bits integer. The real branch offset is computed + * by: imm32 = SignExtend(LI:'0b00', 32); + * + * So the maximum forward branch should be: + * (0x007fffff << 2) = 0x01fffffc = 0x1fffffc + * The maximum backward branch should be: + * (0xff800000 << 2) = 0xfe000000 = -0x2000000 + */ +static inline bool is_offset_in_branch_range(long offset) +{ + return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); +} + +static inline bool is_offset_in_cond_branch_range(long offset) +{ + return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3); +} + int create_branch(ppc_inst_t *instr, const u32 *addr, unsigned long target, int flags); int create_cond_branch(ppc_inst_t *instr, const u32 *addr, diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 00c68e7fb11e..58262c7e447c 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -208,33 +208,6 @@ int patch_branch(u32 *addr, unsigned long target, int flags) return patch_instruction(addr, instr); } -bool is_offset_in_branch_range(long offset) -{ - /* - * Powerpc branch instruction is : - * - * 0 6 30 31 - * +---------+----------------+---+---+ - * | opcode | LI |AA |LK | - * +---------+----------------+---+---+ - * Where AA = 0 and LK = 0 - * - * LI is a signed 24 bits integer. The real branch offset is computed - * by: imm32 = SignExtend(LI:'0b00', 32); - * - * So the maximum forward branch should be: - * (0x007fffff << 2) = 0x01fffffc = 0x1fffffc - * The maximum backward branch should be: - * (0xff800000 << 2) = 0xfe000000 = -0x2000000 - */ - return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); -} - -bool is_offset_in_cond_branch_range(long offset) -{ - return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3); -} - /* * Helper to check if a given instruction is a conditional branch * Derived from the conditional checks in analyse_instr() -- 2.35.1
WARNING: multiple messages have this Message-ID (diff)
From: Christophe Leroy <christophe.leroy@csgroup.eu> To: "Naveen N . Rao" <naveen.n.rao@linux.vnet.ibm.com>, Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@redhat.com>, Benjamin Herrenschmidt <benh@kernel.crashing.org>, Paul Mackerras <paulus@samba.org>, Michael Ellerman <mpe@ellerman.id.au> Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 03/22] powerpc/code-patching: Inline is_offset_in_{cond}_branch_range() Date: Thu, 24 Mar 2022 15:29:53 +0100 [thread overview] Message-ID: <6caf53ffb2f80fb7dac9423a9b4da4e9fa495d8f.1648131740.git.christophe.leroy@csgroup.eu> (raw) In-Reply-To: <cover.1648131740.git.christophe.leroy@csgroup.eu> Test in is_offset_in_branch_range() and is_offset_in_cond_branch_range() are simple tests that are worth inlining. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> --- arch/powerpc/include/asm/code-patching.h | 29 ++++++++++++++++++++++-- arch/powerpc/lib/code-patching.c | 27 ---------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/arch/powerpc/include/asm/code-patching.h b/arch/powerpc/include/asm/code-patching.h index 409483b2d0ce..e7c5df50cb4e 100644 --- a/arch/powerpc/include/asm/code-patching.h +++ b/arch/powerpc/include/asm/code-patching.h @@ -22,8 +22,33 @@ #define BRANCH_SET_LINK 0x1 #define BRANCH_ABSOLUTE 0x2 -bool is_offset_in_branch_range(long offset); -bool is_offset_in_cond_branch_range(long offset); +/* + * Powerpc branch instruction is : + * + * 0 6 30 31 + * +---------+----------------+---+---+ + * | opcode | LI |AA |LK | + * +---------+----------------+---+---+ + * Where AA = 0 and LK = 0 + * + * LI is a signed 24 bits integer. The real branch offset is computed + * by: imm32 = SignExtend(LI:'0b00', 32); + * + * So the maximum forward branch should be: + * (0x007fffff << 2) = 0x01fffffc = 0x1fffffc + * The maximum backward branch should be: + * (0xff800000 << 2) = 0xfe000000 = -0x2000000 + */ +static inline bool is_offset_in_branch_range(long offset) +{ + return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); +} + +static inline bool is_offset_in_cond_branch_range(long offset) +{ + return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3); +} + int create_branch(ppc_inst_t *instr, const u32 *addr, unsigned long target, int flags); int create_cond_branch(ppc_inst_t *instr, const u32 *addr, diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 00c68e7fb11e..58262c7e447c 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -208,33 +208,6 @@ int patch_branch(u32 *addr, unsigned long target, int flags) return patch_instruction(addr, instr); } -bool is_offset_in_branch_range(long offset) -{ - /* - * Powerpc branch instruction is : - * - * 0 6 30 31 - * +---------+----------------+---+---+ - * | opcode | LI |AA |LK | - * +---------+----------------+---+---+ - * Where AA = 0 and LK = 0 - * - * LI is a signed 24 bits integer. The real branch offset is computed - * by: imm32 = SignExtend(LI:'0b00', 32); - * - * So the maximum forward branch should be: - * (0x007fffff << 2) = 0x01fffffc = 0x1fffffc - * The maximum backward branch should be: - * (0xff800000 << 2) = 0xfe000000 = -0x2000000 - */ - return (offset >= -0x2000000 && offset <= 0x1fffffc && !(offset & 0x3)); -} - -bool is_offset_in_cond_branch_range(long offset) -{ - return offset >= -0x8000 && offset <= 0x7fff && !(offset & 0x3); -} - /* * Helper to check if a given instruction is a conditional branch * Derived from the conditional checks in analyse_instr() -- 2.35.1
next prev parent reply other threads:[~2022-03-24 14:31 UTC|newest] Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-24 14:29 [PATCH v1 00/22] powerpc: ftrace optimisation and cleanup and more [v1] Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 01/22] powerpc/ftrace: Refactor prepare_ftrace_return() Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 02/22] powerpc/ftrace: Remove redundant create_branch() calls Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy [this message] 2022-03-24 14:29 ` [PATCH v1 03/22] powerpc/code-patching: Inline is_offset_in_{cond}_branch_range() Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 04/22] powerpc/ftrace: Use is_offset_in_branch_range() Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 05/22] powerpc/code-patching: Inline create_branch() Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 06/22] powerpc/ftrace: Inline ftrace_modify_code() Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-04-18 6:07 ` Naveen N. Rao 2022-04-18 6:07 ` Naveen N. Rao 2022-04-22 9:12 ` Michael Ellerman 2022-04-22 9:12 ` Michael Ellerman 2022-05-04 11:43 ` Christophe Leroy 2022-05-04 11:43 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 07/22] powerpc/ftrace: Use patch_instruction() return directly Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-04-18 6:21 ` Naveen N. Rao 2022-04-18 6:21 ` Naveen N. Rao 2022-04-18 19:44 ` Steven Rostedt 2022-04-18 19:44 ` Steven Rostedt 2022-05-04 12:01 ` Christophe Leroy 2022-05-04 12:01 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 08/22] powerpc/ftrace: Make __ftrace_make_{nop/call}() common to PPC32 and PPC64 Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-04-18 6:40 ` Naveen N. Rao 2022-04-18 6:40 ` Naveen N. Rao 2022-05-04 12:19 ` Christophe Leroy 2022-05-04 12:19 ` Christophe Leroy 2022-05-06 11:41 ` Christophe Leroy 2022-05-06 11:41 ` Christophe Leroy 2022-03-24 14:29 ` [PATCH v1 09/22] powerpc/ftrace: Don't include ftrace.o for CONFIG_FTRACE_SYSCALLS Christophe Leroy 2022-03-24 14:29 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 10/22] powerpc/ftrace: Use CONFIG_FUNCTION_TRACER instead of CONFIG_DYNAMIC_FTRACE Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-04-18 7:00 ` Naveen N. Rao 2022-04-18 7:00 ` Naveen N. Rao 2022-05-06 11:41 ` Christophe Leroy 2022-05-06 11:41 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 11/22] powerpc/ftrace: Remove ftrace_plt_tramps[] Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 12/22] powerpc/ftrace: Use BRANCH_SET_LINK instead of value 1 Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 13/22] powerpc/ftrace: Use PPC_RAW_xxx() macros instead of opencoding Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-04-18 7:38 ` Naveen N. Rao 2022-04-18 7:38 ` Naveen N. Rao 2022-05-04 12:39 ` Christophe Leroy 2022-05-04 12:39 ` Christophe Leroy 2022-05-05 16:47 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 14/22] powerpc/ftrace: Use size macro " Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 15/22] powerpc/ftrace: Simplify expected_nop_sequence() Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 16/22] powerpc/ftrace: Minimise number of #ifdefs Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-04-18 7:59 ` Naveen N. Rao 2022-04-18 7:59 ` Naveen N. Rao 2022-05-04 12:44 ` Christophe Leroy 2022-05-04 12:44 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 17/22] powerpc/inst: Add __copy_inst_from_kernel_nofault() Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 18/22] powerpc/ftrace: Don't use copy_from_kernel_nofault() in module_trampoline_target() Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 19/22] powerpc/inst: Remove PPC_INST_BRANCH Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 20/22] powerpc/modules: Use PPC_INST_BRANCH_MASK instead of opencoding Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 21/22] powerpc/inst: Remove PPC_INST_BL Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy 2022-03-24 14:30 ` [PATCH v1 22/22] powerpc/opcodes: Remove unused PPC_INST_XXX macros Christophe Leroy 2022-03-24 14:30 ` Christophe Leroy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=6caf53ffb2f80fb7dac9423a9b4da4e9fa495d8f.1648131740.git.christophe.leroy@csgroup.eu \ --to=christophe.leroy@csgroup.eu \ --cc=benh@kernel.crashing.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=mingo@redhat.com \ --cc=mpe@ellerman.id.au \ --cc=naveen.n.rao@linux.vnet.ibm.com \ --cc=paulus@samba.org \ --cc=rostedt@goodmis.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.