WizziLab / CRC

Dependents:   D7A_1x_demo_CodeUpgradeProtocol D7A_1x_demo_big_file D7A_1x_demo_sensors_v3 D7A_1x_demo_send_file_data

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fast_crc32.h Source File

fast_crc32.h

00001 // //////////////////////////////////////////////////////////
00002 // Crc32.h
00003 // Copyright (c) 2011-2016 Stephan Brumme. All rights reserved.
00004 // Slicing-by-16 contributed by Bulat Ziganshin
00005 // Tableless bytewise CRC contributed by Hagai Gold
00006 // see http://create.stephan-brumme.com/disclaimer.html
00007 //
00008 
00009 // if running on an embedded system, you might consider shrinking the
00010 // big Crc32Lookup table by undefining these lines:
00011 #define CRC32_USE_LOOKUP_TABLE_BYTE
00012 //#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_4
00013 //#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_8
00014 //#define CRC32_USE_LOOKUP_TABLE_SLICING_BY_16
00015 // - crc32_bitwise  doesn't need it at all
00016 // - crc32_halfbyte has its own small lookup table
00017 // - crc32_1byte_tableless and crc32_1byte_tableless2 don't need it at all
00018 // - crc32_1byte    needs only Crc32Lookup[0]
00019 // - crc32_4bytes   needs only Crc32Lookup[0..3]
00020 // - crc32_8bytes   needs only Crc32Lookup[0..7]
00021 // - crc32_4x8bytes needs only Crc32Lookup[0..7]
00022 // - crc32_16bytes  needs all of Crc32Lookup
00023 // using the aforementioned #defines the the table is automatically fitted to your needs
00024 
00025 // uint8_t, uint32_t, int32_t
00026 #include <stdint.h>
00027 // size_t
00028 #include <stddef.h>
00029 
00030 // crc32_fast selects the fastest algorithm depending on flags (CRC32_USE_LOOKUP_...)
00031 /// compute CRC32 using the fastest algorithm for large datasets on modern CPUs
00032 uint32_t crc32_fast(const void* data, size_t length, uint32_t previousCrc32 = 0);
00033 
00034 /// compute CRC32 (bitwise algorithm)
00035 uint32_t crc32_bitwise (const void* data, size_t length, uint32_t previousCrc32 = 0);
00036 /// compute CRC32 (half-byte algoritm)
00037 uint32_t crc32_halfbyte(const void* data, size_t length, uint32_t previousCrc32 = 0);
00038 
00039 #ifdef CRC32_USE_LOOKUP_TABLE_BYTE
00040 /// compute CRC32 (standard algorithm)
00041 uint32_t crc32_1byte   (const void* data, size_t length, uint32_t previousCrc32 = 0);
00042 #endif
00043 
00044 /// compute CRC32 (byte algorithm) without lookup tables
00045 uint32_t crc32_1byte_tableless (const void* data, size_t length, uint32_t previousCrc32 = 0);
00046 /// compute CRC32 (byte algorithm) without lookup tables
00047 uint32_t crc32_1byte_tableless2(const void* data, size_t length, uint32_t previousCrc32 = 0);
00048 
00049 #ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_4
00050 /// compute CRC32 (Slicing-by-4 algorithm)
00051 uint32_t crc32_4bytes  (const void* data, size_t length, uint32_t previousCrc32 = 0);
00052 #endif
00053 
00054 #ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_8
00055 /// compute CRC32 (Slicing-by-8 algorithm)
00056 uint32_t crc32_8bytes  (const void* data, size_t length, uint32_t previousCrc32 = 0);
00057 /// compute CRC32 (Slicing-by-8 algorithm), unroll inner loop 4 times
00058 uint32_t crc32_4x8bytes(const void* data, size_t length, uint32_t previousCrc32 = 0);
00059 #endif
00060 
00061 #ifdef CRC32_USE_LOOKUP_TABLE_SLICING_BY_16
00062 /// compute CRC32 (Slicing-by-16 algorithm)
00063 uint32_t crc32_16bytes (const void* data, size_t length, uint32_t previousCrc32 = 0);
00064 /// compute CRC32 (Slicing-by-16 algorithm, prefetch upcoming data blocks)
00065 uint32_t crc32_16bytes_prefetch(const void* data, size_t length, uint32_t previousCrc32 = 0, size_t prefetchAhead = 256);
00066 #endif