All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Jan Beulich <JBeulich@suse.com>, Daniel Borkmann <dborkman@redhat.com>
Cc: davem@davemloft.net, mingo@elte.hu, tglx@linutronix.de,
	ffusco@redhat.com, tgraf@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] x86/hash: swap parameters of crc32_u32()
Date: Mon, 24 Feb 2014 05:01:16 -0800	[thread overview]
Message-ID: <530B429C.2090507@zytor.com> (raw)
In-Reply-To: <530B4058.80705@zytor.com>

On 02/24/2014 04:51 AM, H. Peter Anvin wrote:
> On 02/24/2014 04:41 AM, Jan Beulich wrote:
>>>
>>> So I'm guessing this hash is deliberately using the CRC32 instruction
>>> "backwards", which would actually make sense: an actual CRC is actually
>>> a pretty poor hash due to linearity.
>>>
>
> OK, it really is even more confusing than that.
>
> It does seem like the crc32 instruction really *is* commutative, which
> isn't something I would personally have expected at all.
>
> Given that fact, I suspect the ordering in the DPDK is actually a bug,
> and that we should correct the ordering (which I would do at the call
> sites because it seems to make the code clearer) because it reduces the
> size of the loop by two instructions.
>
> I guess I should find out how to file a bug report against DPDK too...
>

Looking through the DPDK project git history, it seems that this was a 
bug introduced when changing from using inline assembly to using intrinsics:

  static inline uint32_t
  rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
  {
-	asm volatile("crc32 %[data], %[init_val]"
-	             : [init_val]"=r" (init_val)
-	             : [data]"r" (data), "[init_val]" (init_val));
-	return init_val;
+	return _mm_crc32_u32(data, init_val);
  }

The operand order, of course, of the intrinsic being the opposite of 
AT&T-style assembly.

I never expected that the CRC32 operation would be commutative.  Very 
fascinating.

	-hpa


  reply	other threads:[~2014-02-24 13:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 10:33 [PATCH 2/3] x86/hash: swap parameters of crc32_u32() Jan Beulich
2014-02-22 12:09 ` Daniel Borkmann
2014-02-24  8:03   ` Jan Beulich
2014-02-24 10:22     ` Daniel Borkmann
2014-02-24 10:53       ` Jan Beulich
2014-02-24 11:46         ` Daniel Borkmann
2014-02-24 12:16           ` Jan Beulich
2014-02-24 12:32           ` H. Peter Anvin
2014-02-24 12:41             ` Jan Beulich
2014-02-24 12:51               ` H. Peter Anvin
2014-02-24 13:01                 ` H. Peter Anvin [this message]
2014-02-24 13:07                   ` Jan Beulich
2014-02-24 13:09                   ` Daniel Borkmann
2014-02-24 13:16                     ` H. Peter Anvin
2014-02-24 12:35     ` H. Peter Anvin
2014-02-25 20:26 ` H. Peter Anvin
2014-02-25 20:34   ` Daniel Borkmann
2014-02-25 20:37     ` H. Peter Anvin
2014-02-26  9:29       ` Jan Beulich
2014-02-26 16:06         ` H. Peter Anvin

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=530B429C.2090507@zytor.com \
    --to=hpa@zytor.com \
    --cc=JBeulich@suse.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=ffusco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=tgraf@redhat.com \
    /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 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.