From 586583d6d6184cfcadae5652ad683360abf16f59 Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 22:14:52 -0200 Subject: [PATCH 1/7] Update Fix16_benchmark.ino --- examples/Fix16_benchmark/Fix16_benchmark.ino | 42 ++++---------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/examples/Fix16_benchmark/Fix16_benchmark.ino b/examples/Fix16_benchmark/Fix16_benchmark.ino index 3453d55..4857784 100644 --- a/examples/Fix16_benchmark/Fix16_benchmark.ino +++ b/examples/Fix16_benchmark/Fix16_benchmark.ino @@ -1,18 +1,8 @@ -#define NO_DOUBLE -#define NO_FIX16 - -#if !defined(NO_DOUBLE) && !defined(NO_FIX16) #include -#endif - -#ifndef NO_FIX16 #include -#endif -#ifndef NO_DOUBLE #include -#endif -#define NUM_RUNS (5) +#define NUM_RUNS (10) #define COMMENT(x) Serial.println(F("\n----" x "----")); @@ -81,7 +71,7 @@ template void test_divTestcases( void ) T a = testcases[i]; T b = testcases[j]; // We don't require a solution for /0 :) - if (b == T(0)) continue; + if (b == T((int16_t)0)) continue; f = a / b; } } @@ -115,20 +105,17 @@ template void test_subTestcases( void ) } } -#ifndef NO_FIX16 void test_sqrtTestcasesFix16( void ) { unsigned int i; for (i = 0; i < TESTCASES_COUNT; i++) { Fix16 a = testcases[i]; - if (a < Fix16(0)) continue; + if (a < (int32_t)0) continue; f = a.sqrt(); } } -#endif -#ifndef NO_DOUBLE void test_sqrtTestcasesDouble( void ) { unsigned int i; @@ -139,7 +126,6 @@ void test_sqrtTestcasesDouble( void ) f = sqrt(a); } } -#endif #define TIMED_EXEC(func,delta,runs) \ { \ @@ -151,8 +137,11 @@ void test_sqrtTestcasesDouble( void ) void setup() { -#if !defined(NO_DOUBLE) && !defined(NO_FIX16) Serial.begin(115200); + while(!Serial.available()){ + Serial.println("Enter any key to begin"); + delay(1000); + } COMMENT("Running testcases for multiplication"); unsigned long time_Fix16Mult, time_doubleMult; @@ -193,23 +182,6 @@ void setup() Serial.print("Sqrt "); Serial.print(time_doubleSqrt); Serial.print("\t"); Serial.print(time_Fix16Sqrt); Serial.print("\t"); Serial.print(incr_Sqrt); Serial.println("%"); COMMENT("Test finished"); -#endif - -#if defined(NO_DOUBLE) && !defined(NO_FIX16) - test_multTestcases(); - test_divTestcases(); - test_addTestcases(); - test_subTestcases(); - test_sqrtTestcasesFix16(); -#endif - -#if !defined(NO_DOUBLE) && defined(NO_FIX16) - test_multTestcases(); - test_divTestcases(); - test_addTestcases(); - test_subTestcases(); - test_sqrtTestcasesDouble(); -#endif while (1) {}; } From 7d076a89ccada7abe1c510ee0d1bb38bf6b5b789 Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 22:17:21 -0200 Subject: [PATCH 2/7] ARM/AVR Compatibility --- libfixmath_conf.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libfixmath_conf.h b/libfixmath_conf.h index 3cf1ee2..91a953b 100644 --- a/libfixmath_conf.h +++ b/libfixmath_conf.h @@ -1,15 +1,25 @@ #ifndef _LIBFIXMATH_CONF_H #define _LIBFIXMATH_CONF_H -#ifdef ARDUINO_ARCH_AVR -// ARDUINO_ARCH_AVR might not be the optimum define to check on, -// but nothing else is available... +#if defined(__arm__) + +//#define FIXMATH_NO_64BIT +//#define FIXMATH_OPTIMIZE_8BIT +//#define FIXMATH_NO_CACHE +#define FIXMATH_NO_OVERFLOW +//#define FIXMATH_NO_ROUNDING + +#elif defined(__AVR__) + // AVR Architecture is 8bit & limited in memory #define FIXMATH_NO_64BIT #define FIXMATH_OPTIMIZE_8BIT #define FIXMATH_NO_CACHE -//#define FIXMATH_NO_OVERFLOW +#define FIXMATH_NO_OVERFLOW //#define FIXMATH_NO_ROUNDING + +#else +#error Architecture or board not supported. #endif #endif From 2532db8473243f631a57c1be71120b9050a70464 Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 22:25:29 -0200 Subject: [PATCH 3/7] Update Fix16_benchmark.ino --- examples/Fix16_benchmark/Fix16_benchmark.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Fix16_benchmark/Fix16_benchmark.ino b/examples/Fix16_benchmark/Fix16_benchmark.ino index 4857784..ec3da55 100644 --- a/examples/Fix16_benchmark/Fix16_benchmark.ino +++ b/examples/Fix16_benchmark/Fix16_benchmark.ino @@ -2,7 +2,7 @@ #include #include -#define NUM_RUNS (10) +#define NUM_RUNS 5 #define COMMENT(x) Serial.println(F("\n----" x "----")); From 94a64425d50a4a8fdcc241885457a2756ae50d8a Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 23:34:26 -0200 Subject: [PATCH 4/7] Update README.md --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 48741d0..93efd41 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,24 @@ Fixed point (16.16 & 8.8) library for Arduino to replace resource hungry float/d Implementation based on libfixmath (https://code.google.com/p/libfixmath). See also http://en.wikipedia.org/wiki/Libfixmath. +Works on AVR (Uno, etc) and ARM (Due, etc) based Arduinos. + +Benchmarks (Fix16_benchmark.ino example) + +Arduino Due fix16_t vs double Benchmark (time in micro seconds): +Op double fixpt speed improvement fixpt over double +Mult 372545 97631 381.58% +Div 1335860 203392 656.79% +Add 457899 14830 3087.65% +Sub 456773 37275 1225.41% +Sqrt 14453 2842 508.55% + +Arduino Due fix16_t vs float Benchmark (time in micro seconds): +Op float fixpt speed improvement fixpt over float +Mult 304898 103902 293.45% +Div 640075 206859 309.43% +Add 356009 22301 1596.38% +Sub 361209 39842 906.60% +Sqrt 14750 2662 554.09% + Released under MIT License. From f6a5ae2f24bef0f6ca4621bc66ae0a73bffe5a48 Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 23:35:33 -0200 Subject: [PATCH 5/7] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 93efd41..1f7010e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ See also http://en.wikipedia.org/wiki/Libfixmath. Works on AVR (Uno, etc) and ARM (Due, etc) based Arduinos. Benchmarks (Fix16_benchmark.ino example) - +``` Arduino Due fix16_t vs double Benchmark (time in micro seconds): Op double fixpt speed improvement fixpt over double Mult 372545 97631 381.58% @@ -16,7 +16,9 @@ Div 1335860 203392 656.79% Add 457899 14830 3087.65% Sub 456773 37275 1225.41% Sqrt 14453 2842 508.55% +``` +``` Arduino Due fix16_t vs float Benchmark (time in micro seconds): Op float fixpt speed improvement fixpt over float Mult 304898 103902 293.45% @@ -24,5 +26,5 @@ Div 640075 206859 309.43% Add 356009 22301 1596.38% Sub 361209 39842 906.60% Sqrt 14750 2662 554.09% - +``` Released under MIT License. From d5f25cc979eb43273981eb400ea981266f9e1c13 Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Sun, 18 Oct 2015 23:36:34 -0200 Subject: [PATCH 6/7] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1f7010e..dfd5338 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,21 @@ Works on AVR (Uno, etc) and ARM (Due, etc) based Arduinos. Benchmarks (Fix16_benchmark.ino example) ``` Arduino Due fix16_t vs double Benchmark (time in micro seconds): -Op double fixpt speed improvement fixpt over double -Mult 372545 97631 381.58% +Op double fixpt speed improvement fixpt over double +Mult 372545 97631 381.58% Div 1335860 203392 656.79% -Add 457899 14830 3087.65% -Sub 456773 37275 1225.41% -Sqrt 14453 2842 508.55% +Add 457899 14830 3087.65% +Sub 456773 37275 1225.41% +Sqrt 14453 2842 508.55% ``` ``` Arduino Due fix16_t vs float Benchmark (time in micro seconds): -Op float fixpt speed improvement fixpt over float +Op float fixpt speed improvement fixpt over float Mult 304898 103902 293.45% Div 640075 206859 309.43% -Add 356009 22301 1596.38% -Sub 361209 39842 906.60% -Sqrt 14750 2662 554.09% +Add 356009 22301 1596.38% +Sub 361209 39842 906.60% +Sqrt 14750 2662 554.09% ``` Released under MIT License. From 40cd3c9c19ea340e5b544cf703000d4546451d4d Mon Sep 17 00:00:00 2001 From: Daniel Zanco Date: Mon, 19 Oct 2015 00:34:02 -0200 Subject: [PATCH 7/7] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dfd5338..2ff6e77 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ See also http://en.wikipedia.org/wiki/Libfixmath. Works on AVR (Uno, etc) and ARM (Due, etc) based Arduinos. +PS: The examples may not compile, only Fix16_benchmark was tested and fixed from the original repository. + Benchmarks (Fix16_benchmark.ino example) ``` Arduino Due fix16_t vs double Benchmark (time in micro seconds):