This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

_never_executed() vs. __even_in_range()

I'm wondering what the difference between those two intrinsics is, and if there is a significant difference between them when dealing with a interrupt vector like TAIV on the MSP430.

My understanding is, that:

switch (__even_in_range( x , NUM ))
{
...

Will tell the compiler that x is an even number and takes on values from 0 to NUM (inclusive). The compiler can therefore generate an optimized jumptable based on that assumption (which it isn't allowed to do otherwise).

Now if I'd write:

switch (x)
{
...
default: _never_executed()
}

with the same x and the same cases (so it's still even and in range of 0 to NUM), would this create a code which is equally optimized or is there a difference between them?

My understanding of _never_executed() is that it tells the compiler that the x can only take the values of the cases given, and then can optimize the code based on that knowledge. But there is no restriction on x being even.

Maybe for personal reasons I like the _never_executed() intrinsic more (it's less intimidating) than the __even_in_range() intrinsic, and they work in a similar manner, they both are able to optimize the switch statement using knowledge about the range of the statement. But if the __even_in_range() generates better (faster, more efficient) code then I should probably use it rather than _never_executed().

  • The TI compiler has supported _never_executed for several years.  Support for __even_in_range was added later.  That is because __even_in_range is supported in the IAR compiler, and there is customer demand for source compatibility between the IAR and TI MSP430 compilers.

    Bernhard Weller said:
    if there is a significant difference between them when dealing with a interrupt vector like TAIV on the MSP430

    Not really.  The _never_executed intrinsic is a bit more general.  You can use it in any switch statement, not just those associated with timer interrupts.  Otherwise, it is up to user preference.

    Thanks and regards,

    -George

  • Ah so that's where it comes from. Thank you for pointing that out, now I just have to check whether my code needs to be compiled by IAR compilers at some time or not...