-
-
Notifications
You must be signed in to change notification settings - Fork 773
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
Fix: extract method for SWD parity calculation #1700
Fix: extract method for SWD parity calculation #1700
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.
It's definitely looking good - nice job cleaning things up and rationalising them with this change!
We've spotted a couple of functional issues in review, noted below, and have a couple of name suggestions to pick from for what to name this new function, but we're happy once those are addressed to get this merged.
It's definitely a shame we don't have a nice way of building a sim suite or test suite for the maths functions so we can have in-repo proofs of their correctness, but that's an improvement to strive for in a future PR.
Requesting next round of review. |
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 all looks good to us now - the one review note here is an optional change. Please replay the history to make it clean and we'll get this merged.
344c1e7
to
e5ce5ca
Compare
* The only two users are cortexm_dwt_mask() and stlink_v2_set_frequency(). * This leads to less ccache invalidation when maths_utils.h changes (e.g. odd_parity)
* swdptap of firmware and "adapter"_swd of `hosted` all used parity/popcount * Extracting this also allows using MSVC with adapter backends * Use `uint8_t` to correspond to `hosted` libusb packet buffers
* BMF on Cortex-M3 relies on libgcc2 software builtin impls, not the x86-64-v2 popcnt insn, so adjust accordingly (parity is cheaper) * More type- and const-correctness (bmp_gpio_get/set)
* This still resolves to `__builtin_parity()` for GCC targeting Cortex-M
e5ce5ca
to
c812d4c
Compare
Merged fixups, propagated the rename, build-tested intermediate commits with a custom pre-commit extended hook, and rebased to latest main. |
c812d4c
to
3f47538
Compare
Most excellent! Regarding MSVC, once the new Meson support lands it should become considerably easier to generate full BMDA builds under MSVC and get logs from them. |
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.
LGTM, approved pending testing with our Tigard. We'll merge (assuming it all works properly, but we believe it should) once that's been tested.
* Always use a parity function, not `popcount & 1` * Hide most `__builtin` usage (from entities like MSVC) * `ftdi_swd_seq_in_parity_mpsse()`: break up the bitmask calculation to enforce uint32_t intermediate * `jlink_swd_seq_in_parity()`: cosmetic: fix a typo in comment
3f47538
to
d7455f5
Compare
We'll get this merged now it's been tested and the one bug found and fixed, good work! 🙂 |
Detailed description
This PR is aimed at two problems:
__popcountsi2(): 40 bytes
is more expensive. Solution 1: create a shim/dispatcher in maths_utils, name itswd_odd_parity
and call that from swdptap (the gpio-bitbanging one). This leads to cleaner code at that callsite, and less flash space occupiedhosted
adapter driver backends also want to calculate parity, and also do that via both popcount and parity builtins. MSVC does not provide these builtins, only the__popcount
for x86-64 optional instruction. Solution 2: incorporate this _MSC-specific builtin as well into the shim, and tweak all saidhosted
parity calculations to call the shim.This PR is triggered from the discussion of #1688 two weeks ago.
I decided to name the function
swd_odd_parity()
for where it is going to be used. If future JTAG-PDI code also would want to use it (and attribute alias does not cut it), the reviewer/implementer of that can suggest a better name and I'll mass-rename the touched callsites (with a force-push).Notice that I drop
maths_utils.h
fromgeneral.h
and include it where needed by this PR. The point on making the shimstatic inline
in the header is a valid discussion topic.Your checklist for this pull request
make PROBE_HOST=native
)make PROBE_HOST=hosted
)Closing issues
May help fix building BMDA under MSVC with
HOSTED_BMP_ONLY=0
(caveat libusb/hidapi).