[PATCH] x86/asm/entry: clean up usage of TEST insns
From: Denys Vlasenko
Date: Mon Mar 30 2015 - 10:14:03 EST
After TEST insn, JE actually performs "jump if zero",
let's use JZ mnemonic instead. No code changes,
but less confusion.
By the nature of TEST operation, it is often possible
to test a narrower part of the operand:
"testl $3, mem" -> "testb $3, mem",
"testq $3, %rcx" -> "testb $3, %cl"
This results in shorter insns, because TEST insn has no
sign-entending byte-immediate forms unlike other ALU ops.
Signed-off-by: Denys Vlasenko <dvlasenk@xxxxxxxxxx>
CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
CC: Steven Rostedt <rostedt@xxxxxxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxxxxx>
CC: Borislav Petkov <bp@xxxxxxxxx>
CC: "H. Peter Anvin" <hpa@xxxxxxxxx>
CC: Andy Lutomirski <luto@xxxxxxxxxxxxxx>
CC: Oleg Nesterov <oleg@xxxxxxxxxx>
CC: Frederic Weisbecker <fweisbec@xxxxxxxxx>
CC: Alexei Starovoitov <ast@xxxxxxxxxxxx>
CC: Will Drewry <wad@xxxxxxxxxxxx>
CC: Kees Cook <keescook@xxxxxxxxxxxx>
CC: x86@xxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx
---
Code changes in assembly are:
-f7 84 24 88 00 00 00 03 00 00 00 testl $0x3,0x88(%rsp)
+f6 84 24 88 00 00 00 03 testb $0x3,0x88(%rsp)
-f7 44 24 68 03 00 00 00 testl $0x3,0x68(%rsp)
+f6 44 24 68 03 testb $0x3,0x68(%rsp)
-49 f7 c3 00 00 01 00 test $0x10000,%r11
+41 f7 c3 00 00 01 00 test $0x10000,%r11d
-f7 84 24 90 00 00 00 03 00 00 00 testl $0x3,0x90(%rsp)
+f6 84 24 90 00 00 00 03 testb $0x3,0x90(%rsp)
arch/x86/kernel/entry_32.S | 10 +++++-----
arch/x86/kernel/entry_64.S | 20 ++++++++++----------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 438d193..57c204e 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -436,7 +436,7 @@ sysenter_after_call:
TRACE_IRQS_OFF
movl TI_flags(%ebp), %ecx
testl $_TIF_ALLWORK_MASK, %ecx
- jne sysexit_audit
+ jnz sysexit_audit
sysenter_exit:
/* if something modifies registers it must also disable sysexit */
movl PT_EIP(%esp), %edx
@@ -464,7 +464,7 @@ sysenter_audit:
sysexit_audit:
testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
- jne syscall_exit_work
+ jnz syscall_exit_work
TRACE_IRQS_ON
ENABLE_INTERRUPTS(CLBR_ANY)
movl %eax,%edx /* second arg, syscall return value */
@@ -476,7 +476,7 @@ sysexit_audit:
TRACE_IRQS_OFF
movl TI_flags(%ebp), %ecx
testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
- jne syscall_exit_work
+ jnz syscall_exit_work
movl PT_EAX(%esp),%eax /* reload syscall return value */
jmp sysenter_exit
#endif
@@ -514,7 +514,7 @@ syscall_exit:
TRACE_IRQS_OFF
movl TI_flags(%ebp), %ecx
testl $_TIF_ALLWORK_MASK, %ecx # current->work
- jne syscall_exit_work
+ jnz syscall_exit_work
restore_all:
TRACE_IRQS_IRET
@@ -616,7 +616,7 @@ work_notifysig: # deal with pending signals and
#ifdef CONFIG_VM86
testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
movl %esp, %eax
- jne work_notifysig_v86 # returning to kernel-space or
+ jnz work_notifysig_v86 # returning to kernel-space or
# vm86-space
1:
#else
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index ca80adc..b79a935 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -512,7 +512,7 @@ ENTRY(ret_from_fork)
RESTORE_EXTRA_REGS
- testl $3,CS(%rsp) # from kernel_thread?
+ testb $3,CS(%rsp) # from kernel_thread?
jz 1f
/*
@@ -597,8 +597,8 @@ END(interrupt)
leaq -RBP(%rsp),%rdi /* arg1 for \func (pointer to pt_regs) */
- testl $3, CS-RBP(%rsp)
- je 1f
+ testb $3, CS-RBP(%rsp)
+ jz 1f
SWAPGS
1:
/*
@@ -654,8 +654,8 @@ ret_from_intr:
exit_intr:
GET_THREAD_INFO(%rcx)
- testl $3,CS(%rsp)
- je retint_kernel
+ testb $3,CS(%rsp)
+ jz retint_kernel
/* Interrupt came from user space */
/*
@@ -711,7 +711,7 @@ retint_swapgs: /* return to user-space */
cmpq %r11,EFLAGS(%rsp) /* R11 == RFLAGS */
jne opportunistic_sysret_failed
- testq $X86_EFLAGS_RF,%r11 /* sysret can't restore RF */
+ testl $X86_EFLAGS_RF,%r11d /* sysret can't restore RF */
jnz opportunistic_sysret_failed
/* nothing to check for RSP */
@@ -951,7 +951,7 @@ ENTRY(\sym)
.if \paranoid
.if \paranoid == 1
CFI_REMEMBER_STATE
- testl $3, CS(%rsp) /* If coming from userspace, treat */
+ testb $3, CS(%rsp) /* If coming from userspace, treat */
jnz 1f /* as non-paranoid. */
.endif
call paranoid_entry
@@ -1294,8 +1294,8 @@ ENTRY(error_entry)
SAVE_C_REGS 8
SAVE_EXTRA_REGS 8
xorl %ebx,%ebx
- testl $3,CS+8(%rsp)
- je error_kernelspace
+ testb $3,CS+8(%rsp)
+ jz error_kernelspace
error_swapgs:
SWAPGS
error_sti:
@@ -1346,7 +1346,7 @@ ENTRY(error_exit)
TRACE_IRQS_OFF
GET_THREAD_INFO(%rcx)
testl %eax,%eax
- jne retint_kernel
+ jnz retint_kernel
LOCKDEP_SYS_EXIT_IRQ
movl TI_flags(%rcx),%edx
movl $_TIF_WORK_MASK,%edi
--
1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/