qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 5/8] crypto: convert xts_mult_x to use xts_uint128 type
Date: Tue, 16 Oct 2018 14:59:27 +0100	[thread overview]
Message-ID: <20181016135927.GH7995@redhat.com> (raw)
In-Reply-To: <w51bm7uypyy.fsf@maestria.local.igalia.com>

On Tue, Oct 16, 2018 at 03:35:01PM +0200, Alberto Garcia wrote:
> On Tue 16 Oct 2018 12:09:15 PM CEST, Daniel P. Berrangé wrote:
> > Using 64-bit arithmetic increases the performance for xts-aes-128
> > when built with gcrypt:
> >
> >   Encrypt: 355 MB/s -> 545 MB/s
> >   Decrypt: 362 MB/s -> 568 MB/s
> >
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> 
> This patch is also fine, but I have a couple of minor comments:
> 
> > +static void xts_mult_x(xts_uint128 *I)
> > +{
> > +    uint64_t tt;
> > +
> > +    xts_uint128_cpu_to_les(I);
> > +
> > +    tt = I->u[0] >> 63;
> > +    I->u[0] = I->u[0] << 1;
> 
> Perhaps I->u[0] <<= 1 , for clarity and consistency with the following
> line (I->u[0] ^= 0x87) ? But I don't mind if you prefer to keep it as is
> now.

In fact I could do the following:

@@ -59,12 +59,13 @@ static void xts_mult_x(xts_uint128 *I)
     xts_uint128_cpu_to_les(I);
 
     tt = I->u[0] >> 63;
-    I->u[0] = I->u[0] << 1;
+    I->u[0] <<= 1;
 
     if (I->u[1] >> 63) {
         I->u[0] ^= 0x87;
     }
-    I->u[1] = (I->u[1] << 1) | tt;
+    I->u[1] <<= 1;
+    I->u[1] |= tt;
 
     xts_uint128_le_to_cpus(I);
 }

either way it generates the exact same asm code

> 
> > +    if (I->u[1] >> 63) {
> > +        I->u[0] ^= 0x87;
> >      }
> > +    I->u[1] = (I->u[1] << 1) | tt;
> > +
> > +    xts_uint128_le_to_cpus(I);
> 
> I think both endianness conversion calls should be flipped. First you
> convert from the buffer byte order (LE) to the CPU byte order so you can
> do the bit shifts, then back to the original byte order (LE).
> 
> Changing this doesn't have any practical effect because both calls
> perform the exact same operation, but it documents better what's going
> on.

Yep, ok

> With this changed,
> 
> Reviewed-by: Alberto Garcia <berto@igalia.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2018-10-16 13:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16 10:09 [Qemu-devel] [PATCH v2 0/8] crypto: improve performance of XTS cipher mode Daniel P. Berrangé
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 1/8] crypto: expand algorithm coverage for cipher benchmark Daniel P. Berrangé
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 2/8] crypto: remove code duplication in tweak encrypt/decrypt Daniel P. Berrangé
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 3/8] crypto: introduce a xts_uint128 data type Daniel P. Berrangé
2018-10-16 12:45   ` Alberto Garcia
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 4/8] crypto: convert xts_tweak_encdec to use xts_uint128 type Daniel P. Berrangé
2018-10-16 13:09   ` Alberto Garcia
2018-10-16 13:51     ` Daniel P. Berrangé
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 5/8] crypto: convert xts_mult_x " Daniel P. Berrangé
2018-10-16 13:35   ` Alberto Garcia
2018-10-16 13:59     ` Daniel P. Berrangé [this message]
2018-10-16 14:22       ` Alberto Garcia
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 6/8] crypto: annotate xts_tweak_encdec as inlineable Daniel P. Berrangé
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 7/8] crypto: refactor XTS cipher mode test suite Daniel P. Berrangé
2018-10-16 14:34   ` Alberto Garcia
2018-10-16 10:09 ` [Qemu-devel] [PATCH v2 8/8] crypto: add testing for unaligned buffers with XTS cipher mode Daniel P. Berrangé
2018-10-16 14:50   ` Alberto Garcia

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=20181016135927.GH7995@redhat.com \
    --to=berrange@redhat.com \
    --cc=berto@igalia.com \
    --cc=qemu-devel@nongnu.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: 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).