0

I need to calculate CRC in order to form a hash function on an INTEL machine and came up with the following two intrinsic functions:

  1. _mm_crc32_u32
  2. _mm_crc32_u64

In my project, I am dealing with 32-bit variables and my dilemma is between shifting and ORing each two variables (thus creating a 64-bit variable) and then using the 64-bit CRC or run the 32-bit CRC on each of the two 32-bit variables.

I can't find anywhere the amount of cycles that each one of these functions take, and from the Intel function specifications it is unclear which one is preferable.

The same dilemma also applies on the 16-bit version of the CRC function:

_mm_crc32_u16

I tried checking it by taking the time before and after the CRC. The results were pretty much the same. So I need a more sophisticated way of calculating it.

Jongware
  • 22,200
  • 8
  • 54
  • 100
antonpuz
  • 3,256
  • 4
  • 25
  • 48
  • If you want to benchmark the alternatives, here is a start: http://stackoverflow.com/questions/15752770/mm-crc32-u64-poorly-defined/15754706#15754706 _mm_crc32_u64 isn't available for use in 32-bit builds. –  Oct 13 '14 at 22:06

1 Answers1

1

Don't use CRC for hash values. It's not the same kind of thing. Use the murmurhash for classic computer science hashing needs (that is, not huge cryptographic strength hashes). That also has implementations for different widths.

I don't understand what you mean: you have two 32-bit values and want a hash of that? That might be sensible or might not, depending on why. Can you clarify what you are trying to accomplish?

JDługosz
  • 5,592
  • 3
  • 24
  • 45
  • Hi, I want to save as many cycles as I can, my dilemma is between using the 32bit CRC twice on two 32bit values or using shifts and ORs to combine them into one 64bit value and run the CRC function on it. I think the question can be reduced to is which is bigger the difference between the 64bit and 32bit CRC or shift and OR operation. And the reason i use crc is beacause it has intrinsic function – antonpuz Oct 12 '14 at 06:52
  • 1
    Saying the same thing again doesn't help. What's the point of a CRC on only 32 bits of input? Is that what you are saying?Why are you pairing the input size and the CRC length? That makes me think I'm not understanding. CRC is *not fast* on current processors, since it uses a table. Explain differently than "two 32-bit values" or show an example. – JDługosz Oct 12 '14 at 07:01
  • 1
    @Anton.P: Have you tried measuring the performance? Which one does the job faster for you? Make sure you're not penalizing one with cache misses when the other benefits from the first having already been run. How big a chunk of data are you calculating the CRC for? How well is it aligned? – Jonathan Leffler Oct 12 '14 at 07:09
  • 2
    @jdlugosz "CRC is not fast on current processors" - It has 1 cycle per 64-bits throughput on Intel processors. That's actually pretty fast. – Mysticial Oct 12 '14 at 07:15
  • @Mysticial so by "intrinsic" he meant the new CPU has a special instruction for that? I did not know. I thought he meant compiler support. – JDługosz Oct 12 '14 at 22:38