Hello,
I am looking to do a moving average function using DSP instructions of ARM Cortex M7. Unfortunately I couldn't find a direct example. My goal is to have variables for
- the sum
- the new value
- the oldest value
Then the algorithm is sum = sum + new value - oldest value and average = sum / ( number of values between oldest and new), ie two instructions
I think instruction UMAAL could be good for this, I found it in instruction set summary, but it is not in CMSIS library. Why is that? Where can I find details about it and how can I create my own C asm caller?
Thanks for any help and hints or other ideas on this topic, I hope it also helps other developers.
Kind regards
Martin
I am not sure if CMSIS would provide intrinsics for every instruction. From its headers, it seems that they provide wrappers for certain SIMD instructions.
CMSIS supports iccarm compiler (where iccarm does indeed support __umaal as an intrinsic function), but CMSIS still does not expose it in its cmsis_iccarm.h. For such a compiler, it is quite easy to expose the required function by defining as below (or something similar). The signature of the function should be available with the compiler's manual.
#define __UMAAL __iar_builtin_UMAAL
TI's CCS compiler too provides the function.
As for gcc, cmsis_gcc.h has most of the instructions hand-written using inline-assembly, including a few simple ones such as wfe/wfi. It is unlikely that gcc has the required function builtin. But one can attempt to provide one by hand.
The description the instruction is here. Accordingly, the operation can be roughly written as below (as if embedding it inside the cmsis_gcc.h file).
__STATIC_FORCEINLINE uint64_t __UMAAL(uint64_t acc, uint32_t rn, uint32_t rm) { uint32_t lo, hi; lo = acc; hi = acc >> 32; __ASM volatile ("umaal %0, %1, %2, %3" : "+r" (lo), "+r" (hi) : "r" (rn), "r" (rm)); acc = hi; acc <<= 32; acc |= lo; return acc; }
Edit: Replaced "=r" to "+r".
thanks for your answer, it gave valuable information and helped me along