-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccea46b
commit b52f389
Showing
5 changed files
with
80 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Arduino-lint | ||
|
||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: arduino/arduino-lint-action@v1 | ||
with: | ||
library-manager: submit | ||
compliance: strict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
avr-fast-div example | ||
*/ | ||
#include <Arduino.h> | ||
#include <stdint.h> | ||
#include "avr-fast-div.h" | ||
|
||
void setup() { | ||
Serial.begin(9600); //send and receive at 9600 baud | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
|
||
Serial.println("Beginning test..."); | ||
|
||
const uint32_t divisor = random(2U, UINT16_MAX/2U); | ||
const uint32_t dividend = random((uint32_t)UINT16_MAX+1U, (uint32_t)UINT16_MAX*24U); | ||
|
||
constexpr uint32_t iterations = 5000; | ||
|
||
// Built in "/" operator | ||
uint32_t divCheckSum = 0UL; | ||
uint32_t divStartTime = micros(); | ||
for (uint32_t i = 0U; i < iterations; i++) { | ||
// We need the +i & -i to prevent the optimiser making this loop a no-op | ||
divCheckSum += (dividend+i) / (divisor+i); | ||
} | ||
uint32_t divEndTime = micros(); | ||
uint32_t divDuration = divEndTime-divStartTime; | ||
|
||
// fast_div() | ||
uint32_t fastdivCheckSum = 0UL; | ||
uint32_t fastdivStartTime = micros(); | ||
for (uint32_t i = 0U; i < iterations; i++) { | ||
fastdivCheckSum += fast_div((dividend+i), (divisor+i)); | ||
} | ||
uint32_t fastdivEndTime = micros(); | ||
uint32_t fastdivDuration = fastdivEndTime-fastdivStartTime; | ||
|
||
char msg[128]; | ||
sprintf(msg, "Dividend: %" PRIu32 ", Divisor: %" PRIu32, dividend, divisor); | ||
Serial.println(msg); | ||
sprintf(msg, "Div Checksum: %" PRIu32 ", FastDiv Checksum: %" PRIu32, divCheckSum, fastdivCheckSum); | ||
Serial.println(msg); | ||
sprintf(msg, "Div Duration: %" PRIu32 ", FastDiv Duration: %" PRIu32, divDuration, fastdivDuration); | ||
Serial.println(msg); | ||
uint16_t percentDelta = fastdivDuration * 100U / divDuration; | ||
sprintf(msg, "fast_div() took %" PRIu16 "%% less time than the division operator", 100-percentDelta); | ||
Serial.println(msg); | ||
} | ||
|
||
void loop() { | ||
|
||
// Blink to indicate end of test | ||
digitalWrite(LED_BUILTIN, HIGH); | ||
delay(250); | ||
digitalWrite(LED_BUILTIN, LOW); | ||
delay(250); | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=avr-fast-div | ||
version=1.0.0 | ||
author=Andrew Bancroft | ||
maintainer=Andrew Bancroft | ||
sentence=Optimized integer division for avr-gcc | ||
paragraph=On AVR, runtime division is done in software. This library provides *up to* 70% improvement in run time division speed on AVR hardware. Exact speedup varies depending on data types & number ranges. | ||
category=Data Processing | ||
url=https://github.com/adbancroft/avr-fast-div | ||
architectures=* |