Topic : Possible to inline specific functions?

Forum : ST7/STM8

Original Post
Post Information Post
January 27, 2010 - 11:31pm
Guest

I have a main loop with structure like:

void main()
{
     init();
     while(1)
     {
          if( task_1_fg )
               task_1();
          if( task_2_fg )
               task_2();
          if( task_3_fg )
               task_3();
     }
}

The optimizer is configured to optimize for small space because the program is nearing the maximum size. However, functions like task_1(), task_2(), and task_3() are only called from this main loop. I think the code might run faster (and possibly even be smaller) if these functions were placed inline (so there is not actually a function call but just a series of instructions). However, I think it is much easier to read and manage to have it structured as functions. I thought I could use the "inline" keyword when declaring these functions to give the compiler a hint to try to convert these functions to inline code, but I get errors like "Syntax error near 'void'" when I try to do the following:

inline void task_1()
{
     .....
}

Could you advise me of the correct way to do this?
Thanks in advance.

Replies
Post Information Post
+1
0
-1
January 28, 2010 - 9:47am
Raisonance Support Team

Hi Jacob,

The "inline" function qualifier has been standardized by C99. Most compilers only follow C90, and so does ours.
This means that "inline" is not available.

However, we have been working on this feature for some time now, and the inline functions will be supported in the next release of RKit-STM8.

Note: The inline functions are generally used for inlining small functions (SetBit for example would be a good idea, as it is small and potentially called from a lot of places). But in your case, The gain will be very small: CALL/RET is only 4+4 CPU cycles and 3+1 bytes of code. So you will not notice any measurable difference when inlining your 3 functions.

Regards,
Bruno

+1
0
-1
January 29, 2010 - 5:40pm
Guest

I guess it's not so much that I would expect this to yield significant gains in speed or size, but rather I don't understand why these functions should not be converted to inline code (no disadvantages). Thanks for the insight, Bruno; I really appreciate your assistance!