cancel
Showing results for 
Search instead for 
Did you mean: 

For certain complex fpu instructions from math.h library, how to calculate the number of cycles taken to complete an instruction on ARM cortex M4 based MCU(STM32)

santosh239955
Associate II
Posted on December 22, 2014 at 17:00

For example:

 output = asinf(num1)*0/PI; 
//result = 60

output = output/2.0; 
//result = 30
 output
 = output * PI /0; 
//result = 0.5235987 radians (30 degrees0

output = tanf(output); 
//result = sqrt(3)/3

output = output / 
sqrt
(3); 
//result = 1/3

output = output * 6.0 + 9.9; 
//result = 9

#math.h #lmgtfy #armcm4.h-arm_math.h
7 REPLIES 7
Posted on December 22, 2014 at 17:30

Use DWT_CYCCNT?

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Duration%20of%20FLOAT%20operations&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=4325]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FDuration%20of%20FLOAT%20operations&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=4325

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 22, 2014 at 17:34

I'd also recommend precomputing constants to convert from/to degrees and radians, so that you use MULTIPLICATION instead of DIVISION, ie use reciprocals.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
santosh239955
Associate II
Posted on December 26, 2014 at 01:59

Thanks for the idea. But, I do not have the mcu currently with me.

I wanted to calculate the number of cycles it took to complete a certain program on STM32F4 which I did quite a while ago.

So, can you suggest any other way.

I later found that, each compiler has a different implementation internally for functions of the math.h library. I used Cocox CoIDe.

santosh239955
Associate II
Posted on December 26, 2014 at 02:03

That is a viable option when you want to reduce the number of cycles for the program to complete, right?

With FPU enabled I guess multiplication would take lesser cycles than division.

I want to find out how many cycles(time) a certain mcu(stm32f4 in this case) would take to reach a certain point of code

Posted on December 26, 2014 at 02:36

Unless you have access to a gate level simulation, the best you can do is review ARM documentation as to what range of cycles the instructions will take, and walk through your code.

The exact number of cycles will likely depend on the numbers (mantissa/exponent) being used in a specific operation.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
santosh239955
Associate II
Posted on December 28, 2014 at 18:40

Thanks for the solution. Other than manually computing.

If I don't have the MCU and I have the code and the compiler-

Can I use DWT_CYCCNT in the compiler and get a result for the respective functions?

Posted on December 28, 2014 at 23:58

You can use the method to count any group of code or subroutines. Best to have interrupts disabled as it will count those instructions also.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..