[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK1hOcP___TU9=ZcQRR3whkuct++ngx1Q_GVqi3pRPS3HA-tLg@mail.gmail.com>
Date: Fri, 6 Mar 2015 23:37:23 +0100
From: Denys Vlasenko <vda.linux@...glemail.com>
To: Andi Kleen <andi@...stfloor.org>
Cc: Denys Vlasenko <dvlasenk@...hat.com>,
"H. Peter Anvin" <hpa@...ux.intel.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Steven Rostedt <rostedt@...dmis.org>,
Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
Andy Lutomirski <luto@...capital.net>,
Oleg Nesterov <oleg@...hat.com>,
Frederic Weisbecker <fweisbec@...il.com>,
Will Drewry <wad@...omium.org>,
Kees Cook <keescook@...omium.org>, X86 ML <x86@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86: clean up unnecessarily wide TEST insns
On Fri, Mar 6, 2015 at 11:24 PM, Andi Kleen <andi@...stfloor.org> wrote:
> Denys Vlasenko <dvlasenk@...hat.com> writes:
>
>> 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.
>
> It also results in expensive LCP stalls. Please don't do it.
> If you feel the need to change instructions around like this read
> the optimization manuals first.
Length-changing prefix (LCP) stalls result from 0x66 prefix.
(See https://software.intel.com/en-us/forums/topic/328256).
Basically, LCP happens because adding 66 byte before this instruction:
[test_opcode] [modrm] [imm32]
changes it to
[66] [test_opcode] [modrm] [imm16]
where [imm16] has *different length* now: 2 bytes instead of 4.
This confuses decoder.
REX prefixes were carefully designed to almost never hit this case:
adding REX prefix does not change instruction length except MOVABS
and MOV [addr],RAX insn.
My patch does not add optimizations which would use 0x66 prefix.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists