Skip to content

Faster parity calculations for SerialPIO when using multiple instances #2932

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ahmedarif193 opened this issue May 1, 2025 · 1 comment
Closed

Comments

@ahmedarif193
Copy link
Contributor

Right now, SerialPIO calculates parity with a bit loop that gets slower with more data bits. If you're running several soft serial ports (like 4+), it starts eating CPU for no good reason.

A small lookup table (256 bytes) could do the same job way faster, basically constant time, just a few instructions per byte versus 60+ instructions for 8-bit data for example.

Tradeoffs:

  • Speed: about 10–12x faster per check
  • RAM: 256B global LUT (shared by all instances)
  • Determinism: fixed cost per check

I'm happy to send a PR for this.

ahmedarif193 pushed a commit to ahmedarif193/arduino-pico that referenced this issue May 1, 2025
use LUT for faster parity checks, reduces CPU load with multiple instances
ahmedarif193 pushed a commit to ahmedarif193/arduino-pico that referenced this issue May 1, 2025
ahmedarif193 pushed a commit to ahmedarif193/arduino-pico that referenced this issue May 1, 2025
earlephilhower pushed a commit that referenced this issue May 1, 2025
use bit manipulation technique from http://www.graphics.stanford.edu/~seander/bithacks.html#ParityParallel for parity calculation

Co-authored-by: Ahmed ARIF <contact@eotics.com>
@earlephilhower
Copy link
Owner

Fixed by #2933

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants