0.1.7 Fletcher

This commit is contained in:
rob tillaart 2022-11-07 14:21:36 +01:00
parent c009e84b8b
commit 6e182d283d
16 changed files with 340 additions and 25 deletions

View File

@ -1,14 +1,30 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
- leonardo
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
# - esp8266
# - mega2560
- rpipico
libraries:
- "printHelpers"

View File

@ -0,0 +1,39 @@
# Change Log Fletcher
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.7] - 2022-11-07
- add changelog.md
- add rp2040 to build-CI
- update readme.md
## [0.1.6] - 2022-09-10
- stabilize optimizations
## [0.1.5] - 2022-09-08
- roll back the optimizations in the stand-alone functions
- conflict with loop optimization already in.
- update keywords.txt
## [0.1.4] - 2022-09-08
- performance optimization (Kudos to Daniel Mohr).
- affects SAMD, ESP32 and ESP8266
- fix FLETCHER_LIB_VERSION
## [0.1.3] - 2022-04-15
- fix #4 split .h in .h and .cpp
## [0.1.2] - 2022-01-26
- add class implementation e.g. for streaming
## [0.1.1] - 2022-01-26
- optimize modulo math - variation based upon to Anastase Nakassis (wikipedia)
## [0.1.0] - 2022-01-25
- initial version, straightforward implementation

View File

@ -1,30 +1,18 @@
//
// FILE: Fletcher.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// VERSION: 0.1.7
// DATE: 2022-01-25
// PURPOSE: Arduino Library for calculating Fletcher's checksum
// URL: https://github.com/RobTillaart/Fletcher
// https://en.wikipedia.org/wiki/Fletcher%27s_checksum
//
// HISTORY
// 0.1.0 2022-01-25 initial version, straightforward implementation
// 0.1.1 2022-01-26 optimize % math variation based upon to Anastase Nakassis (wikipedia)
// 0.1.2 2022-01-26 add class implementation e.g. for streaming
// 0.1.3 2022-04-15 fix #4 split .h in .h and .cpp
// 0.1.4 2022-09-08 performance optimization (Kudos to Daniel Mohr).
// affects SAMD, ESP32 and ESP8266
// fix FLETCHER_LIB_VERSION
// 0.1.5 2022-09-08 roll back the optimizations in the standalone functions
// conflict with loop optimization already in.
// update keywords.txt
// 0.1.6 2022-09-10 stabilize optimizations
// HISTORY: see changelog.md
#include "Fletcher.h"
//
// straightforward implementation.
// max length buffer 65534.
// Wikipedia shows optimizations.

View File

@ -2,7 +2,7 @@
//
// FILE: Fletcher.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.6
// VERSION: 0.1.7
// DATE: 2022-01-25
// PURPOSE: Arduino Library for calculating Fletcher's checksum
// URL: https://github.com/RobTillaart/Fletcher
@ -12,7 +12,7 @@
#include "Arduino.h"
#define FLETCHER_LIB_VERSION (F("0.1.6"))
#define FLETCHER_LIB_VERSION (F("0.1.7"))
#define FLETCHER_16 255
#define FLETCHER_32 65535UL

View File

@ -102,16 +102,23 @@ See examples.
## Future ideas
#### must
- improve documentation
- update performance figures.
#### should
- test other platforms
- add parameter for start values for F in static functions
- would allow to use them in a stream too.
#### could
- others e.g. Fletcher24?
- generic FletcherN(). for N = 1..32
- add Print interface
- or Printable() ?
- Stream ??
- add getters for S1 and S2 in the classes
- add parameter for start values for F in static functions
- would allow to use them in a stream too.
#### wont

View File

@ -0,0 +1,10 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher16_performance
randomtime: 901328
total: 931424
1e4 x add: 30096
checksum: 14489

View File

@ -0,0 +1,11 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher16_performance
randomtime: 6947
total: 8702
1e4 x add: 1755
checksum: 43990

View File

@ -0,0 +1,11 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher32_performance
randomtime: 901328
total: 938028
1e4 x add: 36700
checksum: 3613420079

View File

@ -0,0 +1,12 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher32_performance
randomtime: 6948
total: 8579
1e4 x add: 1631
checksum: 1747945808

View File

@ -0,0 +1,11 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher64_performance
randomtime: 901328
total: 963500
1e4 x add: 62172
checksum: 8878666521548909084

View File

@ -0,0 +1,12 @@
Tested on Arduino UNO
IDE 1.18.19
LIB VERSION 0.1.6
Fletcher64_performance
randomtime: 6947
total: 8954
1e4 x add: 2007
checksum: 9165826312677596359

View File

@ -0,0 +1,34 @@
Tested on Arduino UNO
IDE 1.18.19
FLETCHER_LIB_VERSION: 0.1.0
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 22696 53705
FLETCHER32: 32740 1196447857
FLETCHER64: 11916 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 1120 53705
FLETCHER32: 728 1196447857
FLETCHER64: 1952 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.4
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 1120 53705
FLETCHER32: 552 1196447857
FLETCHER64: 1960 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.6
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 1120 53705
FLETCHER32: 728 1196447857
FLETCHER64: 1952 10053561395214921491

View File

@ -0,0 +1,36 @@
Tested on Arduino UNO
IDE 1.18.19
(included for comparison Arduino UNO)
FLETCHER_LIB_VERSION: 0.1.1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 1120 53705
FLETCHER32: 728 1196447857
FLETCHER64: 1952 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.3
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 61 53705
FLETCHER32: 33 1196447857
FLETCHER64: 34 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.4
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 60 53705
FLETCHER32: 34 1196447857
FLETCHER64: 31 10053561395214921491
FLETCHER_LIB_VERSION: 0.1.6
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ae...
LENGTH STR: 868
FLETCHER16: 61 53705
FLETCHER32: 33 1196447857
FLETCHER64: 35 10053561395214921491

View File

@ -0,0 +1,128 @@
//
// FILE: Fletcher_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
#include "Arduino.h"
#include "Fletcher16.h"
#include "Fletcher32.h"
#include "Fletcher64.h"
#include "printHelpers.h" // https://github.com/RobTillaart/printHelpers
Fletcher16 F16;
Fletcher32 F32;
Fletcher64 F64;
uint32_t count = 0;
void setup()
{
Serial.begin(115200);
while (!Serial);
F16.begin();
F32.begin();
F64.begin();
}
void loop()
{
uint32_t r32 = random(0x7FFFFFFF) * random(0x7FFFFFFF) + random(0x7FFFFFFF);
uint16_t r16 = r32 & 0xFFFF;
uint8_t r8 = r16 & 0xFF;
uint16_t x16 = F16.getFletcher();
F16.add(r8);
if (F16.getFletcher() != ref16(r8))
{
Serial.print("16:\t");
Serial.print(x16);
Serial.print(" + ");
Serial.print(r8);
Serial.print("==>");
Serial.print(F16.getFletcher());
Serial.println();
while (1);
}
uint32_t x32 = F32.getFletcher();
F32.add(r16);
if (F32.getFletcher() != ref32(r16))
{
Serial.print("32:\t");
Serial.print(x32);
Serial.print(" + ");
Serial.print(r16);
Serial.print("==>");
Serial.print(F32.getFletcher());
Serial.println();
while (1);
}
uint64_t x64 = F64.getFletcher();
F64.add(r32);
if (F64.getFletcher() != ref64(r32))
{
Serial.print("64:\t");
Serial.print(print64(x64));
Serial.print(" + ");
Serial.print(r32);
Serial.print("==>");
Serial.print(print64(F64.getFletcher()));
Serial.println();
while (1);
}
count++;
if (count % 100000 == 0)
{
Serial.print(millis());
Serial.print("\t");
Serial.print(count);
Serial.print("\t");
Serial.println(count * 1000.0 / millis());
}
}
uint64_t ref64(uint32_t x)
{
static uint64_t s1 = 0;
static uint64_t s2 = 0;
s1 += x;
s1 %= 0xFFFFFFFF;
s2 += s1;
s2 %= 0xFFFFFFFF;
return (s2 << 32 | s1);
}
uint32_t ref32(uint16_t x)
{
static uint32_t s1 = 0;
static uint32_t s2 = 0;
s1 += x;
s1 %= 0xFFFF;
s2 += s1;
s2 %= 0xFFFF;
return (s2 << 16 | s1);
}
uint16_t ref16(uint8_t x)
{
static uint16_t s1 = 0;
static uint16_t s2 = 0;
s1 += x;
s1 %= 0xFF;
s2 += s1;
s2 %= 0xFF;
return (s2 << 8 | s1);
}
// -- END OF FILE --

View File

@ -18,7 +18,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/Fletcher.git"
},
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=Fletcher
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence="Arduino Library for calculating Fletcher's checksum.