Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adbancroft/avr-fast-shift
Optimized 32-bit shifting for avr-gcc
https://github.com/adbancroft/avr-fast-shift
avr gcc performance
Last synced: about 1 month ago
JSON representation
Optimized 32-bit shifting for avr-gcc
- Host: GitHub
- URL: https://github.com/adbancroft/avr-fast-shift
- Owner: adbancroft
- License: lgpl-2.1
- Created: 2024-08-27T02:12:21.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-10-11T17:28:59.000Z (3 months ago)
- Last Synced: 2024-10-16T06:34:19.776Z (3 months ago)
- Topics: avr, gcc, performance
- Language: C++
- Homepage:
- Size: 75.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build](https://github.com/adbancroft/avr-fast-shift/actions/workflows/build.yml/badge.svg)](https://github.com/adbancroft/avr-fast-shift/actions/workflows/build.yml)
[![Unit Tests](https://github.com/adbancroft/avr-fast-shift/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/adbancroft/avr-fast-shift/actions/workflows/unit-tests.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=adbancroft_avr-fast-shift&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=adbancroft_avr-fast-shift)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=adbancroft_avr-fast-shift&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=adbancroft_avr-fast-shift)# avr-fast-shift: optimized 32-bit shifting for avr-gcc
As of AVR-GCC 14.2.0, the code produced for unsigned 32-bit shifts with a *compile time shift distance* is very poor when using -O2 or -O3. E.g.
rpmDelta = (toothDeltaV << 10) / (6 * toothDeltaT);
The functions provided here implement optimised left and right shifting of `uint32_t` up to 31 places.
On a physical AtMega2560, up to:
* 35% increase in right shift performance
* 22% increase in left shift performanceSee timing unit tests.
## Using the library
### Installation
The library is available in both the [Arduino Library](https://www.arduino.cc/reference/en/libraries/avr-fast-shift/) and [PlatformIO Library](https://registry.platformio.org/libraries/adbancroft/avr-fast-shift) registries.The library can also be cloned & included locally or included directly from GitHub (if your tooling supports it).
### Code
1. `#include `
2. Replace all 32-bit shift operations that use a compile time constant shift distance with the equivalent shift function. I.e.
* `a >> b` -> `rshift(a)`
* `a << b` -> `lshift(a)`
* E.g.
* `rpmDelta = (toothDeltaV << 10) / (6 * toothDeltaT);` -> `rpmDelta = lshift<10U>(toothDeltaV) / (6 * toothDeltaT);`