CoIDE is just an IDE. The actual implementation is done by the compiler(s) you hook to CoIDE, just like any other IDE.
How are math.h library functions like sqrt, asinf, tanf implemented for the CoIDE compiler?
Need further information regarding the internal implementation(like taylor series?) to calculate the number of cycles taken for a certain program which implements these functions takes in FPU enabled Cortex M4 based MCU's.
I have used the arm-gcc compiler. I have tried to search online for a good description of these functions in source code. But to no avail. Could you please provide any further sources?
Math.h is the library
I believe that by default, the gcc compilers use a set of generic software floating point code as part of libgcc (https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html ), and higher level math functions as part of gcc libc ( http://www.gnu.org/software/libc/ ) All nice and portable, but not particularly fast or small.
Technically, these are separate from the compiler, and in fact are one of the things that a value-added compiler vendor might provide as "improved" versions. For example, avr-gcc has its own complete set of floating point routines. However, coide expects you to download the ARM compiler from launchpad.net, which claims to be using newlib or newlib-nano, so you can find code there, ie: https://github.com/32bitmicro/newlib-nano-1.0/tree/master/newlib/libm/math
It takes a brave (or desperate) vendor or engineer to implement new floating point math code...
Different libs for chips with HW floating point, of course. And cmsis-dsp has some specially optimized functions (apparently not direct replacements for libm functions, though.) CooCox does seem to have a bunch of peripheral libraries that replace the usual vendor libraries, but I don't see alternate floating point functions.
The processor I used is a STM32F4 it has FPU. But, we can have the option of enabling it or not.
So, by observing the documentation for these functions in libm code give some idea to calculate the number of cycles it took to calculate that particular function?
For example- for sinf function with fpu enabled - can we calculate the number of clock cycles consumed for it?
? Absolute value (1 cycle)
? Negate of a float or of multiple floats (1 cycle)
? Addition (1 cycle)
? Subtraction (1 cycle)
? Multiply, multiply accumulate/subtract, multiply accumulate/subtract then negate (3 cycles)
? Divide (14 cycles)
? Square root (14 cycles)
Obviously, if they are part of a math library, this might need some additional cycles. E.g. if the check the value for a square root to be positive etc.For example- for sinf function with fpu enabled - can we calculate the number of clock cycles consumed for it?
QuoteFor example- for sinf function with fpu enabled - can we calculate the number of clock cycles consumed for it?
Yeah: most simulators will provide exact cycle counts for you; and you can use timers too - systick comes in handy for things like this.
The processor I used is a STM32F4 it has FPU. But, we can have the option of enabling it or not.
So, by observing the documentation for these functions in libm code give some idea to calculate the number of cycles it took to calculate that particular function?
For example- for sinf function with fpu enabled - can we calculate the number of clock cycles consumed for it?
Can't you just run a benchmark and extract the numbers from it?
Well, a quick search brings us to the manual:
http://www.st.com/st-web-ui/static/active/jp/resource/technical/document/application_note/DM00047230.pdf
From what I see there, it's single precision FPU with add/sub/mul/div and sqrt plus some MAC instructions, but no trigonometric functions.
Quoting the manual, the cycles needed are:Code: [Select]? Absolute value (1 cycle)
Obviously, if they are part of a math library, this might need some additional cycles. E.g. if the check the value for a square root to be positive etc.
? Negate of a float or of multiple floats (1 cycle)
? Addition (1 cycle)
? Subtraction (1 cycle)
? Multiply, multiply accumulate/subtract, multiply accumulate/subtract then negate (3 cycles)
? Divide (14 cycles)
? Square root (14 cycles)
Anyway, the above functions are relatively "cheap" cycle wise. The trigonometric functions are then probably implemented using taylor series and accordingly expensive.
Thanks for the link 0deadbeeef. I too have it. The problem is, since I do not know how exactly the asinf and tanf functions are implemented. I can only keep guessing with these numbers.
Can we run the benchmarks from the CoIDE compiler?
How are math.h library functions like sqrt, asinf, tanf implemented for the CoIDE compiler?
How are math.h library functions like sqrt, asinf, tanf implemented for the CoIDE compiler?Complex math function are typically implemented using Taylor Series. Slow, but accurate.
QuoteCan we run the benchmarks from the CoIDE compiler?
Yes, if you have a hardware debugger like st-link or jlink, + the actual hardware.
How are math.h library functions like sqrt, asinf, tanf implemented for the CoIDE compiler?Complex math function are typically implemented using Taylor Series. Slow, but accurate.
inspect the implementation!
Find the library and disassemble the routines
is it not possible if we only have the compiler?
I mean, without the actual hardware/microcontroller.
QuoteI mean, without the actual hardware/microcontroller.A far better approach is to get the actual hardware.