C# 快速 crc32 计算:

发布于 2024-08-13 22:33:53 字数 419 浏览 6 评论 0原文

我已经用 Ants 分析了我的应用程序,发现 > 10% 用于 CRC32 计算。 (CRC32 计算是用纯 C# 完成的)

我做了一些谷歌搜索并了解了 Visual Studio 2008 中的以下内在函数:

_mm_crc32_u8

_mm_crc32_u16

_mm_crc32_u32

_mm_crc32_u64

( http://msdn.microsoft.com/en-us/library/bb514036.aspx

任何人都可以告诉我/告诉我如何使用这些来替换我的自制 CRC32 ?

I've profiled my application with Ants and found out that > 10% is in CRC32 calculations.
(The CRC32-calculation is done in plain C#)

I did some googling and learned about the following intrinsics in Visual Studio 2008 :

_mm_crc32_u8

_mm_crc32_u16

_mm_crc32_u32

_mm_crc32_u64

( http://msdn.microsoft.com/en-us/library/bb514036.aspx )

Can anyone tell me / show me how to use these to replace my homebrew CRC32 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谜泪 2024-08-20 22:33:53

这些年来,CRC32 计算速度越来越快。部分原因是实现优化,还有新的处理器指令可用。因此,这是对近十年之久的问题的新答案!

Stephan Brumme 的 CRC32 页面概述了优化的概述,最后一页日期为 2016 年。Yuri Babich 的 FastCRC 是 Stephan Brumme 和 Stephan Brumme 的快速 C++ CRC32 算法“Slicing-by-16”的 2019 C# 实现。布拉特·齐甘辛。他声称他的版本仅比本机 CLI C++ 快速 CRC32 实现慢一点(大约 10%)。该算法是较旧的 CRC-32-IEEE。

如果您能够选择其他变体,请选择 CRC-32C (Castagnoli)。这在 Crc32C.NET 包中可用。

CRC-32C 中的多项式被证明具有更好的错误检测能力
属性,这是其在新标准中采用的原因
(iSCSI、SCTP、ext4)。除了更高的可靠性之外,CRC-32C 现在还具有
较新的英特尔处理器上专用指令的优势。
这就是为什么它被选用于高性能应用程序,
Snappy 压缩算法示例。

Crc32.NET 是 Robert Važan 对上述 Crc32C.NET 的 .NET 安全实现,但是对于Crc32算法。

这个库包含对托管代码的优化,所以,它确实是
比其他 Crc32 实现更快。如果您正好需要 Crc32,
这个图书馆是最好的选择。对此实施进行了调查
不同变体中最快的。此外,它对于 x64 和
x86,所以看来,做两种不同的实现是没有意义的。

我不知道上述两个 .NET 实现中哪一个对于经典 CRC-32-IEEE 算法来说最快。 性能比较表未引用第一个实现。

Anonymous Coward 的回答指向 crcutil,这是一个小说的高性能 CRC 参考实现多字 CRC 算法由 Andrew Kadatch 和 Bob Jenkins 于 2007 年初发明。新算法针对现代 Intel 和 AMD 处理器进行了大量调整,并且比几乎所有其他软件 CRC 算法快得多。他们 2010 年的论文 下载中列出了我们所知道但又害怕忘记的有关 CRC 的所有内容。本文展示了一些可用于避免重新处理某些数据范围的技巧:

  • 增量 CRC 计算
  • 更改初始 CRC 值
  • CRC 串联
  • 就地修改 CRC 消息
  • 在消息后存储 CRC 值

因此,请尽量明智地了解需要计算的内容一旦数据量足够大或者环境有限时。

CRC32 calculations are getting faster over the years. Part because of implementation optimizations but also due to new processor instructions becoming available. Hence this new answer to almost a decade old question!

Stephan Brumme's CRC32 page has an overview of optimizations with the last one dated 2016. FastCRC by Yuri Babich is a 2019 C# implementation of the fast C++ CRC32 algorithm "Slicing-by-16" by Stephan Brumme & Bulat Ziganshin. He claims his version is just a little bit slower (about 10%) than the native CLI C++ fast CRC32 implementation. This algorithm is the older CRC-32-IEEE.

If you have the ability to choose another variant, go for CRC-32C (Castagnoli). This is available in the Crc32C.NET package.

The polynomial in CRC-32C was shown to have better error detection
properties, which is the reason for its adoption in newer standards
(iSCSI, SCTP, ext4). Aside from higher reliability, CRC-32C now has
the advantage of dedicated instruction on newer Intel processors.
That's why it is being chosen for high-performance applications, for
example Snappy compression algorithm.

Crc32.NET is a .NET safe implementation of the above Crc32C.NET by Robert Važan but for the the Crc32 algorithm.

This library contains optimizations for managed code, so, it really is
faster than other Crc32 implementations. If you need exactly Crc32,
this library is the best choice. This implementation was investigated
as fastest from different variants. Also, it is good for x64 and for
x86, so, it seems, there is no sense to do 2 different realizations.

I have no idea which of the two .NET implementations above is the fastest for the classic CRC-32-IEEE algorithm. The performance comparison table does not reference the first implementation.

The answer from Anonymous Coward points to crcutil, a high performance CRC reference implementation of a novel Multiword CRC algorithm invented by Andrew Kadatch and Bob Jenkins in early 2007. The new algorithm is heavily tuned towards modern Intel and AMD processors and is substantially faster than almost all other software CRC algorithms. Their 2010 paper Everything we know about CRC but afraid to forget is listed in the downloads. This paper shows some tricks that can be used to avoid reprocessing certain data ranges:

  • Incremental CRC computation
  • Changing initial CRC value
  • Concatenation of CRCs
  • In-place modification of CRC-ed message
  • Storing CRC value after the message

So try to be smart about what needs calculating once the amount of data becomes large enough or when the environment is limited.

一影成城 2024-08-20 22:33:53

围绕此的 AC# 包装器可能是当前大小数据的最佳解决方案。

http://code.google.com/p/crcutil/

Crcutil 库提供了以下功能的高效实现: CRC 算法。它包括 Andrew Kadatch 和 Bob Jenkins 在 2007 年初发明的新型多字 CRC 算法的参考实现。新算法针对现代 Intel 和 AMD 处理器进行了大力调整,并且比几乎所有其他软件 CRC 算法快得多。

硬件辅助 CRC32C:每字节 0.13 (Nehalem) CPU 周期。
64 位及更小的 CRC:每字节 1.0 (Nehalem) - 1.2 (Core) CPU 周期。
128 位 CRC:每字节 1.7 个 CPU 周期。

Haswell 的 AVX2 可能会带来一些可以进一步提高性能的指令,如果是这样的话,如果它们包含在这个库中那就太酷了。

A C# wrapper around this might be the best solution for decent size data currently.

http://code.google.com/p/crcutil/

Crcutil library provides efficient implementation of CRC algorithms. It includes reference implementation of a novel Multiword CRC algorithm invented by Andrew Kadatch and Bob Jenkins in early 2007. The new algorithm is heavily tuned towards modern Intel and AMD processors and is substantially faster than almost all other software CRC algorithms.

Hardware-assisted CRC32C: 0.13 (Nehalem) CPU cycles per byte.
64-bit and smaller CRCs: 1.0 (Nehalem) - 1.2 (Core) CPU cycles per byte.
128-bit CRCs: 1.7 CPU cycles per byte.

Haswell's AVX2 may bring some instructions which may further improve perf, if so, would be cool if they were included in this library.

婴鹅 2024-08-20 22:33:53

不确定您是否必须使用这些方法来代替您的自制啤酒。 在此处用 C# 计算 CRC-32 找到了一个很好的实现。

Not sure that you have to use those methods to replace your home brew. Found a good implementation for calculating CRC-32 in C# here.

浮华 2024-08-20 22:33:53

您可以使用 PInvoke(和纯 c#)或创建 C++/CLI 项目并围绕此函数编写包装器。

你在msdn上看到过例子吗?要计算字符串的 CRC,您只需循环它即可。

嗯,它们是内在函数。这意味着您只有一个选择:创建 C++/CLI 包装器。

You can use PInvoke (and pure c#) or create C++/CLI project and write wrapper around this functions.

Did you saw example on msdn? To compute CRC of string you need just loop through it.

Well, they're Intrinsic functions. It means you have only one option: create C++/CLI wrapper.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文