diff --git a/fifofast.cproj b/fifofast.cproj index 89780d1..9fb085a 100644 --- a/fifofast.cproj +++ b/fifofast.cproj @@ -130,41 +130,15 @@ compile - + compile - - compile - - - compile - - - compile - - - compile - - + compile - - - - - - - - compile - - - compile - - - compile - + \ No newline at end of file diff --git a/fifofast.h b/fifofast.h index e7ee22e..72b916c 100644 --- a/fifofast.h +++ b/fifofast.h @@ -49,7 +49,7 @@ // version numbering is based on "Semantic Versioning 2.0.0" (semver.org) #define FIFOFAST_VERSION_MAJOR 0 #define FIFOFAST_VERSION_MINOR 3 -#define FIFOFAST_VERSION_PATCH 1 +#define FIFOFAST_VERSION_PATCH 2 #define FIFOFAST_VERSION_SUFFIX #define FIFOFAST_VERSION_META @@ -118,8 +118,8 @@ typedef struct #define _fff__sizeof_array(_id) _sizeof_array(((struct _fff__name_struct(_id)*)0)->data) // returns the length of the data array; fifo contrains are automatically applied -#define _fff__get_arraydepth8(_depth) _limit((1<<(1+_log2_8((uint8_t)_depth-1))), 4, UINT8_MAX+1) -#define _fff__get_arraydepth16(_depth) _limit((1<<(1+_log2_16((uint16_t)_depth-1))), 4, (uint16_t)INT16_MAX+1) +#define _fff__get_arraydepth8(_depth) _limit((1<<(1+_log2((uint8_t)_depth-1))), 4, UINT8_MAX+1) +#define _fff__get_arraydepth16(_depth) _limit((1<<(1+_log2((uint16_t)_depth-1))), 4, (uint16_t)INT16_MAX+1) ////////////////////////////////////////////////////////////////////////// diff --git a/utility/macros/com/macro_math.h b/utility/macros/com/macro_math.h index 4f2c85d..9a8e01e 100644 --- a/utility/macros/com/macro_math.h +++ b/utility/macros/com/macro_math.h @@ -43,65 +43,10 @@ (shiftAmount > 0 ? arg >> shiftAmount : arg << (-shiftAmount)) // returns the mathematical function log2(x), rounded down to nearest integer -// this marco-like function does not contain a loop and can be used eg. for if(log2(x)>y) -#define _log2_8(_n) ((_n) >= 1<<7 ? 7 \ - : (_n) >= 1<<6 ? 6 \ - : (_n) >= 1<<5 ? 5 \ - : (_n) >= 1<<4 ? 4 \ - : (_n) >= 1<<3 ? 3 \ - : (_n) >= 1<<2 ? 2 \ - : (_n) >= 1<<1 ? 1 \ - : 0) +// this marco-like function makes use of a GCC build-in function and can be used eg. for if(log2(x)>y) +// If a literal is passed to this function, the result is calculated at compile time and stored in flash. +#define _log2(n) ((unsigned) (8*sizeof (unsigned long long) - __builtin_clzll((n)) - 1)) -#define _log2_16(_n) ((_n) >= 1<<15 ? 15 \ - : (_n) >= 1<<14 ? 14 \ - : (_n) >= 1<<13 ? 13 \ - : (_n) >= 1<<12 ? 12 \ - : (_n) >= 1<<11 ? 11 \ - : (_n) >= 1<<10 ? 10 \ - : (_n) >= 1<<9 ? 9 \ - : (_n) >= 1<<8 ? 8 \ - : (_n) >= 1<<7 ? 7 \ - : (_n) >= 1<<6 ? 6 \ - : (_n) >= 1<<5 ? 5 \ - : (_n) >= 1<<4 ? 4 \ - : (_n) >= 1<<3 ? 3 \ - : (_n) >= 1<<2 ? 2 \ - : (_n) >= 1<<1 ? 1 \ - : 0) - -#define _log2_32(_n) ((_n) >= 1<<31 ? 31 \ - : (_n) >= 1<<30 ? 30 \ - : (_n) >= 1<<29 ? 29 \ - : (_n) >= 1<<28 ? 28 \ - : (_n) >= 1<<27 ? 27 \ - : (_n) >= 1<<26 ? 26 \ - : (_n) >= 1<<25 ? 25 \ - : (_n) >= 1<<24 ? 24 \ - : (_n) >= 1<<23 ? 23 \ - : (_n) >= 1<<22 ? 22 \ - : (_n) >= 1<<21 ? 21 \ - : (_n) >= 1<<20 ? 20 \ - : (_n) >= 1<<19 ? 19 \ - : (_n) >= 1<<18 ? 18 \ - : (_n) >= 1<<17 ? 17 \ - : (_n) >= 1<<16 ? 16 \ - : (_n) >= 1<<15 ? 15 \ - : (_n) >= 1<<14 ? 14 \ - : (_n) >= 1<<13 ? 13 \ - : (_n) >= 1<<12 ? 12 \ - : (_n) >= 1<<11 ? 11 \ - : (_n) >= 1<<10 ? 10 \ - : (_n) >= 1<<9 ? 9 \ - : (_n) >= 1<<8 ? 8 \ - : (_n) >= 1<<7 ? 7 \ - : (_n) >= 1<<6 ? 6 \ - : (_n) >= 1<<5 ? 5 \ - : (_n) >= 1<<4 ? 4 \ - : (_n) >= 1<<3 ? 3 \ - : (_n) >= 1<<2 ? 2 \ - : (_n) >= 1<<1 ? 1 \ - : 0) #endif /* MACRO_MATH_H_ */ \ No newline at end of file