13.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

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

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

<strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>ARM</strong> <strong>User</strong> <strong>Guide</strong>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#pragma tbb_switch#pragma tbh_switch#pragma no_tbh_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 used<strong>for</strong>ce use of tbb instruction (uses a table of 8-bit jump offsets)<strong>for</strong>ce use of tbh instruction (uses a table of 16-bit jump offsets)same as smart_switch, but do not use tbh instructionUsing a pragma cannot overrule the restrictions as described earlier.The switch pragmas must be placed be<strong>for</strong>e the switch statement. Nested switch statements use thesame switch method, unless the nested switch is implemented in a separate function which is precededby a different switch pragma.Example:/* place pragma be<strong>for</strong>e function body */#pragma jump_switchvoid test(unsigned char val){ /* function containing the switch */switch (val){/* use jump table */}}22

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

Saved successfully!

Ooh no, something went wrong!