Fix: extract method for SWD parity calculation#1700
Fix: extract method for SWD parity calculation#1700dragonmux merged 5 commits intoblackmagic-debug:mainfrom
Conversation
dragonmux
left a comment
There was a problem hiding this comment.
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. |
dragonmux
left a comment
There was a problem hiding this comment.
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. |
dragonmux
left a comment
There was a problem hiding this comment.
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 bytesis more expensive. Solution 1: create a shim/dispatcher in maths_utils, name itswd_odd_parityand call that from swdptap (the gpio-bitbanging one). This leads to cleaner code at that callsite, and less flash space occupiedhostedadapter 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__popcountfor x86-64 optional instruction. Solution 2: incorporate this _MSC-specific builtin as well into the shim, and tweak all saidhostedparity 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.hfromgeneral.hand include it where needed by this PR. The point on making the shimstatic inlinein 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).