Skip to content

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

Merged
merged 2 commits into from
Aug 14, 2018

Conversation

deepikabhavnani
Copy link

@deepikabhavnani deepikabhavnani commented Aug 8, 2018

Description

Adopted the optimized version of 32-bit ANSI CRC table (0x04c11db7). Saves 960 bytes of flash.

Pull request type

[ ] Fix
[X] Refactor
[ ] Target update
[ ] Feature
[ ] Breaking change

CC @geky

Copy link
Contributor

@0xc0170 0xc0170 left a 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?

@deepikabhavnani
Copy link
Author

@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.

Copy link
Contributor

@geky geky left a 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:
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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.

@geky
Copy link
Contributor

geky commented Aug 9, 2018

Looking around a bit, I found this good resource on half-byte CRCs:
https://create.stephan-brumme.com/crc32

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;
}

Will have another PR for thread safety and integration.

👍

@cmonr
Copy link
Contributor

cmonr commented Aug 13, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

Build : SUCCESS

Build number : 2782
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/7735/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

@mbed-ci
Copy link

mbed-ci commented Aug 14, 2018

@adbridge
Copy link
Contributor

@deepikabhavnani What tests have been carried out to ensure that this optimised version has identical results to the original version ?

@cmonr
Copy link
Contributor

cmonr commented Aug 14, 2018

@adbridge I would image that's what the CRC tests are for?

@deepikabhavnani
Copy link
Author

@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

@deepikabhavnani
Copy link
Author

Hello.. CRC PR's #7735, #7781, #7793 and #7824 are related and will be better to have them all in one patch. Can we change the tag of merged PR's to next patch

pan- pushed a commit to pan-/mbed that referenced this pull request Aug 22, 2018
Optimized CRC implementation - (32-bit ANSI polynomial)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants