12.07.2015 Views

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C LanguageMacro__VERSION__DescriptionIdentifies the version number of the compiler. For example, if you use version3.0r1 of the compiler, __VERSION__ expands to 3000 (dot and revisionnumber are omitted, minor version number in 3 digits).Example#ifdef __C<strong>ARM</strong>__/* this part is only compiled <strong>for</strong> the <strong>ARM</strong> */...#endif1.9. Switch StatementThe <strong>TASKING</strong> C compiler supports three ways of code generation <strong>for</strong> a switch statement: a jump chain(linear switch), a jump table or a binary search table.A jump chain is comparable with an if/else-if/else-if/else construction. A jump table is a table filled withjump instructions <strong>for</strong> each possible switch value. The switch argument is used as an index to jump withinthis table. A binary search table is a table filled with a value to compare the switch argument with and atarget address to jump to.#pragma smart_switch is the default of the compiler. The compiler tries to use the switch methodwhich uses the least space in ROM (table size in ROMDATA plus code to do the indexing). With the Ccompiler option --tradeoff you can tell the compiler to emphasis more on speed than on ROM size.For a switch with a long type argument, only binary search table code is used.For an int type argument, a jump table switch is only possible when all case values are in the same 256value range (the high byte value of all programmed cases are the same).Especially <strong>for</strong> large switch statements, the jump table approach executes faster than the binary searchtable approach. Also the jump table has a predictable behavior in execution speed: independent of theswitch argument, every case is reached in the same execution time. However, when the case labels aredistributed far apart, the jump table becomes sparse, wasting code memory. The compiler will not usethe jump table method when the waste becomes excessive.With a small number of cases, the jump chain method can be faster in execution and shorter in size.For <strong>ARM</strong>v7M a switch using the tbh instruction gets priority over a normal switch table implementation.How to overrule the default switch methodYou can overrule the compiler chosen switch method by using a pragma:#pragma linear_switch#pragma jump_switch#pragma binary_switch#pragma smart_switch<strong>for</strong>ce jump chain code<strong>for</strong>ce jump table code<strong>for</strong>ce binary search table codelet the compiler decide the switch method used19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!