mirror of
https://github.com/nqtronix/fifofast.git
synced 2026-08-18 00:58:13 +08:00
[update] optimised log2 macro by using a GCC build-in function...
... This also fixed a bug with the log2_16 and log2_32 macros (which was not further investigated, because both macros have been replaced now).
This commit is contained in:
+3
-29
@@ -130,41 +130,15 @@
|
||||
<Compile Include="fifofast_demo.c">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\com\macro_array.h">
|
||||
<Compile Include="helper\macros.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\com\macro_math.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\com\macro_type.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\mpl\macro_cat.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\mpl\macro_narg.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="utility\macros\mpl\macro_vfunc.h">
|
||||
<Compile Include="helper\macros_math.h">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="utility\" />
|
||||
<Folder Include="utility\macros\" />
|
||||
<Folder Include="utility\macros\com\" />
|
||||
<Folder Include="utility\macros\mpl\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="utility\macros\com\com readme.txt">
|
||||
<SubType>compile</SubType>
|
||||
</None>
|
||||
<None Include="utility\macros\mpl\mpl readme.txt">
|
||||
<SubType>compile</SubType>
|
||||
</None>
|
||||
<None Include="utility\macros\readme.txt">
|
||||
<SubType>compile</SubType>
|
||||
</None>
|
||||
<Folder Include="helper\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
</Project>
|
||||
+3
-3
@@ -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)
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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_ */
|
||||
Reference in New Issue
Block a user