![]() ![]() Those routines will all return the same result, differing only in arguments are ignored, and the initial CRC, i.e. applied to the previous CRC value, crc. crcany can be used to generate alternative code for big-endian and other word sizes.Ĭrc16dnp.h: // The _bit, _byte, and _word routines return the CRC of the len bytes at mem, Intel x86 and x86-64, and it assumes that uintmax_t is 64 bits. This code assumes a little-endian architecture for the word-wise calculation, e.g. Following is the code generated by crcany for that CRC definition. It has very good performance detecting up to 6-bit errors in a packet. One of the good 16-bit performers in Koopman's tables that is also in the catalog of CRCs used in practice is CRC-16/DNP. The classic CRCs, such as the CCITT/Kermit 16-bit CRC or the X.25 16-bit CRC are not the best performers. single digit number of errors per packet, and you want to maximize your error detection performance, you would need to look at the packet size you are applying the CRC to, assuming that that is constant or bounded, and look at the performance of the best polynomials in Philip Koopman's extensive research. If you have a relatively low bit error rate, e.g. ![]() In this case, you can pick any 16-bit CRC in the catalog, and you will get good performance. You do not seem to have a protocol definition with a specific CRC definition that you need to match. Byte-wise is still much faster than bit-wise, but the implementation is more easily portable over architectures. ![]() crcany generates both byte-wise routines and word-wise routines, the latter tuned to the architecture they are generated on. That function returns 0xbb3d for me when I pass in "123456789".Ĭrcany will generate efficient C code for any CRC, and includes a library of over one hundred known CRC definitions.Įfficient CRC code uses tables instead of bit-wise calculations. Out > bits_read) & 1 // item a) work from the least significant bits So, your function might look like: #define CRC16 0x8005
0 Comments
Leave a Reply. |