Starting with the Nehalam series, Intel processors feature the Streaming SIMD Extensions instruction set which provide a hardware-accelerated version of the CRC-32 algorithm (Castagnoli variant). This library uses the Intel SSE 4.2 instruction set to provide a fast CRC-32C implementation.
- Intel Streaming SIMD Extensions 4.2 based hardware-accelerated CRC-32C calculation
- Graceful fallback to software-based CRC-32C (table-based CRC calculation)
- Supports streams, strings and buffers
The tests were run on a Macbook Air running an Intel Core i7 processor, with 16GB of RAM and used buffers instead of strings to prevent having items on the V8 heap that might cause the garbage collector to fire frequently and interfere with the test run-times.
Below are the results from the 2 test cases:
Use the following command to install the library from npm:
npm install --save sse4_crc32
Import the module:
const Sse4Crc32 =
Calculate the 32-bit CRC for any string:
const crc = Sse4Crc32
Instead of passing in a string, a buffer can be passed to the
calculate() function. Furthermore, the
calculate() function takes an optional
initialCrc value as the second argument, allowing for progressive CRC calculation.
const crc = Sse4Crc32const newCrc = Sse4Crc32
You can also calculate the CRC for streams, as follows:
const stream = Sse4Crc32
how to compile
Once the repository has been cloned, use one of the following commands to build the library:
make all // Builds the release version of the library and runs all testsmake debug // Builds the debug version of the librarymake clean // Removes all files generated by builds
All feedback/suggestions/criticisms can be directed to Anand Suresh