Skip to content
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

MbedCRC and CRC HAL revisions (6.0 redo) #11957

Merged
merged 5 commits into from
Dec 3, 2019
Merged

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Nov 27, 2019

Description

Summary of change

Re-submitting #11559 and #11896 for Mbed OS 6.0. Same 5 commits, cherry-picked.

Coupled changes to help speed and size optimisation, reduce special cases, and increase configurability.

  • Use compile-time detection of hardware CRC capability, so unneeded code and tables do not go into the image.

  • Add global JSON config option to allow choice between no tables, 16-entry tables or 256-entry tables for software CRC. Default set to 16-entry, reducing ROM size from previous 256-entry.

  • Allow manual override in template parameter to force software or bitwise CRC for a particular instance.

  • Micro-optimisations, particularly use of RBIT instruction and optimising bitwise computation using inline assembler.

  • Add support for 32-bit CRCs and reversals to TMPM3HQ target.

Incompatible changes as part of removing special cases:

  • Remove special-case "POLY_32BIT_REV_ANSI" - users can use standard POLY_32BIT_ANSI, which now uses the same 16-entry tables by default, or can use hardware acceleration, which was disabled for POLY_32BIT_REV_ANSI. MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE> can be used to force software like POLY_32BIT_REV_ANSI.
  • The precomputed table for POLY_16BIT_IBM had errors - this has been corrected, but software CRC results will be different from the previous software calculation.
  • < 8-bit CRC results are no longer are shifted up in the output value, but placed in the lowest bits, like other sizes. This means that code performing the SD command CRC will now need to use (crc << 1) | 1, rather than crc | 1.

Documentation

n/a


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[X] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Release Notes

Summary of changes

The MbedCRC class has been improved and optimised.

Impact of changes

There is now a global JSON configuration drivers.crc-table-size controlling table usage, and individual uses can be size-optimised via template parameters. However some changes are backwards-incompatible:

Migration actions required

  • The special-case handling of POLY_32BIT_REV_ANSI has been removed - the same result can be obtained via POLY_32BIT_ANSI.
  • CRCs smaller than 8 bits now return results in the standard position at the bottom of the register - previously they were shifted with random bits at the bottom.
  • The previous precomputed table for POLY_16BIT_IBM had errors - this has been corrected, but CRC results will be different from the previous software calculation (but will match any hardware calculation)

@ciarmcom
Copy link
Member

@kjbracey-arm, thank you for your changes.
@maclobdell @ARMmbed/mbed-os-core @ARMmbed/mbed-os-storage @ARMmbed/mbed-os-test @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 added the release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 label Dec 2, 2019
@0xc0170
Copy link
Contributor

0xc0170 commented Dec 2, 2019

@kjbracey-arm Please rebase to resolve one conflict. Will start CI right after

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 2, 2019

Re-submitting #11559 and #11896 for Mbed OS 6.0. Same 5 commits, cherry-picked.

As both were approved and reviewed, this should be ready for CI.

* Change "is supported" check to be a macro, so it can be done at
  compile-time.
* Eliminate weird shift on 7-bit CRCs.
* Add support for 32-bit CRCs and reversals to TMPM3HQ.
* Use compile-time detection of hardware CRC capability, so unneeded
  code and tables do not go into the image.
* Add global JSON config option to allow choice between no tables,
  16-entry tables or 256-entry tables for software CRC. Default set
  to 16-entry, reducing ROM size from previous 256-entry.
* Allow manual override in template parameter to force software or
  bitwise CRC for a particular instance.
* Micro-optimisations, particularly use of `RBIT` instruction and
  optimising bitwise computation using inline assembler.

Incompatible changes:

* Remove special-case "POLY_32BIT_REV_ANSI" - users can use standard
  POLY_32BIT_ANSI, which now uses the same 16-entry tables by default,
  or can use hardware acceleration, which was disabled for
  POLY_32BIT_REV_ANSI. MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE> can
  be used to force software like POLY_32BIT_REV_ANSI.
* The precomputed table for POLY_16BIT_IBM had errors - this has been
  corrected, but software CRC results will be different from the previous
  software calculation.
* < 8-bit CRC results are no longer are shifted up in the output value,
  but placed in the lowest bits, like other sizes. This means that code
  performing the SD command CRC will now need to use `(crc << 1) | 1`,
  rather than `crc | 1`.
* Make mbed_error use bitwise MbedCRC call rather than local
  implementation.
* Remove use of POLY_32BIT_REV_ANSI from LittleFS.
* Move some MbedCRC instances closer to use - construction cost is
  trivial, and visibility aids compiler optimisation.
When using MbedCRC, init value must be non-reversed, regardless of
`reflect_data` or `reflect_out` settings. This means we need to reflect
the intermediate output before passing using it as the next init value.

(In GCC this ends up putting in two `RBIT` instructions back-to-back,
because it's implemented as assembler, so it doesn't know how to
optimise. In ARMC6, `__RBIT` is implemented as an intrinsic, so adding
this reflection cancels the existing reflection and makes the code
smaller).
@kjbracey
Copy link
Contributor Author

kjbracey commented Dec 2, 2019

Rebased.

@0xc0170 0xc0170 removed the request for review from a team December 2, 2019 13:12
@0xc0170
Copy link
Contributor

0xc0170 commented Dec 2, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 2, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 merged commit ad3647c into ARMmbed:master Dec 3, 2019
@0xc0170 0xc0170 removed the needs: CI label Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING-CHANGE release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants