Commit ee26260
fix(pru): memcpyToPRU's block loop was dead and overran short destinations
memcpy_ldnp() opened with
int sz = sztotal - sztotal & 64;
which parses as (sztotal - sztotal) & 64, i.e. always zero. Two consequences.
Every copy fell through to the byte loop, so the ldnp/stnp path the function
exists for - the optimized memcpy faults on the uncacheable PRU mappings - has
never actually run. And the asm block is a do-while, so it always executed one
iteration and stored 64 bytes at the destination regardless of the length
asked for, writing past the end of anything shorter.
Mask the low bits instead, skip the block loop when there is nothing for it,
and only take it when both operands are 16 byte aligned, since an unaligned
vector access to an uncacheable mapping faults. Head and tail go through the
byte loop as before. Exactly sztotal bytes are written and no more.
Callers are unaffected. Every existing call is either a whole number of 64
byte units or at least 64 bytes long, and for any length of 64 or more the old
and new code write the same bytes over the same range - the stray store just
repeated the first block. Only shorter copies change, and there the bytes that
are no longer written were uninitialized stack.
The BBShiftPanel comments describing the copy as spilling into the next 64 byte
unit no longer hold; the padding they explain is kept, and now writes that slot
outright rather than relying on the overrun to do it.
Verified two ways. A/B harness over 66816 combinations of length 0-260 and
source/destination alignment: the old code wrote past the end in 16368 of them,
the new code in none, and neither ever got the copied bytes wrong. Removing
the new byte loop and re-running the aligned, block sized cases still copies
correctly, which is what shows the ldnp path is now the one doing the work
rather than the test passing on the fallback. On hardware, the BBShiftString
command table lands in PRU data RAM byte identical to before.
BBShiftPanel and BBB48String are compile and equivalence checked only, not run
on panels or a 48 string cape.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 857d998 commit ee26260
2 files changed
Lines changed: 27 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
| 443 | + | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| |||
2064 | 2064 | | |
2065 | 2065 | | |
2066 | 2066 | | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
2071 | 2072 | | |
2072 | 2073 | | |
2073 | 2074 | | |
| |||
2096 | 2097 | | |
2097 | 2098 | | |
2098 | 2099 | | |
2099 | | - | |
2100 | | - | |
2101 | | - | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
2102 | 2104 | | |
2103 | 2105 | | |
2104 | 2106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
449 | 455 | | |
450 | | - | |
451 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
452 | 464 | | |
453 | 465 | | |
454 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
455 | 470 | | |
456 | 471 | | |
457 | 472 | | |
| |||
0 commit comments