unsigned int crc32(unsigned char *message) { int i, j; unsigned int byte, crc, mask; i = 0; crc = 0xFFFFFFFF; while (message != 0) { byte = message; // Get next byte. crc = crc ^ byte; for (j = 7; j >= 0; j--) { // Do eight times. mask = -(crc & 1); crc = (crc >> 1) ^ (0xEDB88320 & mask); } i = i + 1; } return ~crc; }
|
אמרו לנו להשתמש בקוד הזה ליצירת CRC בפריים של אטרנט.
אבל אנחנו צריכים לדעת כול שורה מה היא עושה.
ניסיתי לקרוא ולהבין.
זה הטקסט המצורף אבל עדין לא הצלחתי להבין מה כול שורה עושה..
מישהוא יכול להסביר לי בבקשה?
תודה!
It is not unreasonable to unroll the inner loop by the full factor of eight. If this
is done, the program of Figure 14–6 executes in about 46 instructions per byte of
input message. This includes a load and a branch. (We rely on the compiler to
common the two loads of message, and to transform the while-loop so
there is only one branch, at the bottom of the loop.)
Our next version employs table lookup. This is the usual way that CRC-32 is
calculated. Although the programs above work one bit at a time, the table lookup
method (as usually implemented) works one byte at a time. A table of 256 fullword
constants is used.
The inner loop of Figure 14–6 shifts register crc right eight times, while
doing an exclusive or operation with a constant when the low-order bit of crc is
1. These steps can be replaced by a single right shift of eight positions, followed
by a single exclusive or with a mask which depends on the pattern of 1-bits in the
rightmost eight bits of the crc register.
