简体   繁体   English

在Intel CPU上选择32至64位固有CRC

[英]Choosing between 32 and 64 bit intrinsic CRC on Intel CPU

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: 为了在INTEL机器上形成哈希函数,我需要计算CRC并提出以下两个固有函数:

  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. 在我的项目中,我正在处理32位变量,而我的困境是在对两个变量进行移位和或运算(从而创建64位变量)之间,然后使用64位CRC或对每个变量运行32位CRC两个32位变量。

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: 同样的难题也适用于CRC函数的16位版本:

_mm_crc32_u16

I tried checking it by taking the time before and after the CRC. 我尝试通过花CRC前后的时间来检查它。 The results were pretty much the same. 结果几乎相同。 So I need a more sophisticated way of calculating it. 因此,我需要一种更复杂的计算方法。

Don't use CRC for hash values. 不要将CRC用作哈希值。 It's not the same kind of thing. 这不是一回事。 Use the murmurhash for classic computer science hashing needs (that is, not huge cryptographic strength hashes). 使用murmurhash满足经典的计算机科学哈希需求(即,不是巨大的加密强度哈希)。 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? 我不明白您的意思:您有两个32位值,想要一个哈希值吗? That might be sensible or might not, depending on why. 根据原因,这可能是明智的,也可能不是。 Can you clarify what you are trying to accomplish? 您能否阐明您要完成的工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM