-
Notifications
You must be signed in to change notification settings - Fork 3k
Optimized CRC implementation - (32-bit ANSI polynomial) #7735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functional change - the main drive is saving ROM, or is there any other benefit we are getting?
@0xc0170 - Initial intent was to replace Littlefs util crc implementation with this, but that will need thread safety changes as well. We can mark this as fix. Will have another PR for thread safety and integration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
#ifdef DEVICE_CRC | ||
case HARDWARE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so is HARDWARE not defined unless DEVICE_CRC is defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HARDWARE is set as zero in enum as is available. But it should not be set if 'DEVICE_CRC` is defined.
Other option will be to return error and not 0 as per API.
* @return 0 on success or a negative error code on failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a good idea. Though if HARDWARE is not set, trying to use it will be a compile error, which IMO is a slightly better.
Looking around a bit, I found this good resource on half-byte CRCs: They are ~4x slower, but 16x smaller (64B instead of 1KB) It looks like there is a generator we could use for all CRC tables if we wanted to adopt this approach for all polynomials? // from https://create.stephan-brumme.com/crc32
for (unsigned int i = 0; i < 16; i++) {
unsigned int crc = i * 16;
for (unsigned int j = 0; j < 8; j++)
crc = (crc >> 1) ^ (-int(crc & 1) & Polynomial);
lut[i] = crc;
}
👍 |
dbc89be
to
f593555
Compare
/morph build |
Build : SUCCESSBuild number : 2782 Triggering tests/morph test |
Test : SUCCESSBuild number : 2519 |
Exporter Build : SUCCESSBuild number : 2413 |
@deepikabhavnani What tests have been carried out to ensure that this optimised version has identical results to the original version ? |
@adbridge I would image that's what the CRC tests are for? |
@adbridge - https://github.com/ARMmbed/mbed-os/blob/master/TESTS/mbed_drivers/crc/main.cpp#L52 is the test case of the polynomial which was optimized |
Optimized CRC implementation - (32-bit ANSI polynomial)
Description
Adopted the optimized version of 32-bit ANSI CRC table (0x04c11db7). Saves 960 bytes of flash.
Pull request type
CC @geky