linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Pavel Machek <pavel@ucw.cz>
Cc: Jan Beulich <JBeulich@suse.com>,
	mingo@elte.hu, tglx@linutronix.de, hpa@zytor.com,
	davem@davemloft.net, herbert@gondor.apana.org.au,
	rjw@rjwysocki.net, Juergen Gross <jgross@suse.com>,
	linux-kernel@vger.kernel.org, Alok Kataria <akataria@vmware.com>
Subject: Re: [PATCH v2] x86-64: use 32-bit XOR to zero registers
Date: Thu, 5 Jul 2018 09:12:16 +0200	[thread overview]
Message-ID: <20180705071215.GA29659@gmail.com> (raw)
In-Reply-To: <20180704202934.GB15246@amd>


* Pavel Machek <pavel@ucw.cz> wrote:

> On Mon 2018-07-02 04:31:54, Jan Beulich wrote:
> > Some Intel CPUs don't recognize 64-bit XORs as zeroing idioms. Zeroing
> > idioms don't require execution bandwidth, as they're being taken care
> > of in the frontend (through register renaming). Use 32-bit XORs instead.
> > 
> > Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> > @@ -702,7 +702,7 @@ _no_extra_mask_1_\@:
> >  
> >  	# GHASH computation for the last <16 Byte block
> >  	GHASH_MUL \AAD_HASH, %xmm13, %xmm0, %xmm10, %xmm11, %xmm5, %xmm6
> > -	xor	%rax,%rax
> > +	xor	%eax, %eax
> >  
> >  	mov	%rax, PBlockLen(%arg2)
> >  	jmp	_dec_done_\@
> 
> This is rather subtle... and looks like a bug. To zero 64-bit
> register, you zero its lower half, relying on implicit zeroing of the
> upper half. Wow.
> 
> Perhaps we should get comments in the code? Because the explicit code
> is more readable...

The automatic zero-extension of 32-bit ops to the full 64-bit register is a basic, 
fundamental and well-known x86-64 idiom in use in literally hundreds of places in 
x86-64 assembly code.

We sometimes document zero-extension on entry boundaries where we want to make it 
really clear what information gets (and what doesn't get) into the kernel, but 
generally it only needs documentation is the (very rare) cases where it's *not* 
done.

Also, why would it be a bug?

Thanks,

	Ingo

  reply	other threads:[~2018-07-05  7:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 10:31 [PATCH v2] x86-64: use 32-bit XOR to zero registers Jan Beulich
2018-07-03  8:35 ` [tip:x86/asm] x86/asm/64: Use " tip-bot for Jan Beulich
2018-07-04 20:29 ` [PATCH v2] x86-64: use " Pavel Machek
2018-07-05  7:12   ` Ingo Molnar [this message]
2018-07-09  8:33     ` Pavel Machek
2018-07-09  8:47       ` Jan Beulich

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=20180705071215.GA29659@gmail.com \
    --to=mingo@kernel.org \
    --cc=JBeulich@suse.com \
    --cc=akataria@vmware.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).