-
Notifications
You must be signed in to change notification settings - Fork 3k
MbedCRC and CRC HAL revisions #11559
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
8f3b1e9
to
d8acc7e
Compare
@kjbracey-arm, thank you for your changes. |
82de4e6
to
4c63461
Compare
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.
Thanks @kjbracey-arm that looks great. I will spend some time latter (not today) to review it in deep.
I just wonder if it wouldn't have been easier for porting to have hardware CRC supported in targets.json
. Inheriting targets benefit from parents definitions. Not all vendors have a common/objects.h
mechanism. As long as it is documented; it should be sufficient.
* | ||
* Platform support for particular CRC polynomials is indicated by the | ||
* macro HAL_CRC_IS_SUPPORTED(polynomial, width), which must be defined | ||
* in device.h, or a file included from there. |
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.
In this pr, it is defined in objects.h
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.
I don't believe objects.h
is a formal part of the HAL API - the core code includes device.h
, and most (or all?) targets include objects.h
from there.
It seems the usual structure is that each device.h
is maximally specific for a target, and those include a more common objects.h
.
(Update: searched, and there's no reference to objects.h
outside /target
, apart from one mention in cryptocell's Readme.md
on porting)
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.
device.h
is the one. We used to have objects.h
but after added config system it almost vanished.
We do have So |
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.
No unittests?
Not sure what that would add over the Greentea module test - which we need anyway to cover the board and chip variance (M0 vs M4 assembly and HW accel versus not). The Greentea test could do with being expanded to ensure fuller coverage - in particular the previous table errors were not picked up because it only CRC checks There is an issue about the config though - how can we give Greentea tests a config such that at least some targets test the table size set to 256? The 3 main modes (bitwise, table, hardware) get exercised already, but the two possible table sizes aren't. |
I was thinking that does it make sense to test the software implementation in unittests, and HW implementation in Greentea.. but we still need to test the SW in Greentea as well.. but does it have to be all platforms? |
Yeah, could shift to unit test away from Greentea for the "driver" software test. But I think you do want to check that the There is a separate HAL CRC Greentea test just exercising the HAL API for targets that support it. |
@pan-, if you're interested in staring at compiler output again, much of the aim of this PR was to try to exclude dead code, with the most important point being to make the "do I have hardware for this CRC" test compile-time. That leaves us with polynomial and size as template parameters, hardware availability based on template parameters, and the 2 xor and 2 flip options as constructor parameters. So, in principle, given
The compiler should be able to fully optimise out the xor and flip options from the constructor. And that's the reason for the SDBlockDriver changes. GCC fully optimises that as I intend, but clang x86 (in compiler explorer) doesn't. It ends up inlining pointless code that checks _reflect_result, when it knows full well what it's set to. Weird. (I haven't checked to see if ARMC6 does better - I doubt it would). Not found any way of persuading it to do better. :( |
that looks awesome! I'm afraid I don't fully understand all of the C++ magic though, @pan- would be awesome if you could have a closer look. @ARMmbed/team-cypress @ARMmbed/team-st-mcd @ARMmbed/team-silabs @ARMmbed/team-nxp @ARMmbed/team-toshiba can you please review changes to your HAL implementation in this commit b7f41cf |
@ARMmbed/mbed-os-maintainers that's a breaking change that shouldn't go to 5.15 |
ST CI:
|
I think I sort of understand the reluctance to optimise - when compiling
When clang doesn't inline the GCC does inline the |
Test run: FAILEDSummary: 2 of 4 test jobs failed Failed test jobs:
|
Please review unit test failures, related to the change set |
The ARM build failure was spurious though? |
* 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.
Updated to fix unit tests - needed a portable definition of Unit test build failure was newly-arising from the |
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
OK this should not have gone to master prior to the creation of 5.15. @0xc0170 this needs to be reverted before we make the 5.15 branch .... |
Remarked, revert also in 5.15. Master should be now OK |
Description
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:
POLY_32BIT_ANSI
, which now uses the same 16-entry tables by default, or can use hardware acceleration, which was disabled forPOLY_32BIT_REV_ANSI
.MbedCRC<POLY_32BIT_ANSI, 32, CrcMode::TABLE>
can be used to force software like POLY_32BIT_REV_ANSI.POLY_16BIT_IBM
had errors - this has been corrected, but software CRC results will be different from the previous software calculation.(crc << 1) | 1
, rather thancrc | 1
.Pull request type
Reviewers
@bulislaw, @deepikabhavnani, @evedon, @pan-
Release Notes
MbedCRC
class has been improved and optimised. There is now a global JSON configurationdrivers.crc-table-size
controlling table usage, and individual uses can be size-optimised via template parameters. However some changes are backwards-incompatible:POLY_32BIT_REV_ANSI
has been removed - the same result can be obtained viaPOLY_32BIT_ANSI
.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)