For the two sections,I can not find detailed description for them. But they are mentioned in the data sheet--compiler optimizer 187q
In my opinion, switch and vector should both contain instructions instead of data, right?
I know .text is for code, looks like the rest should be data.
If so anyone can tell me how to use switch and vector sections?
The .switch section contains the "jump table", which is an array of function pointers. When the switch is reached, the program loads the appropriate function pointer and branches to it. Function pointers are data, so the .switch section is data. I don't know what ".vector" is.
But how is .switch section is reached please? I think in the assembled code, there are a lot of Branches(B.) which jumps to the address of the subprocedure.
When should we use .switch section?
You refer to SPRU187Q, which is the TMS320C6000 Optimizing Compiler User's Guide. On C6x, switch tables are not executable, they are just arrays of pointers. You will find in the .text section a LDW instruction which loads from this table, followed by a branch to a register. It will look like this:
MVK $C$SW1, A3
MVKH $C$SW1, A3
LDW *A3, A3
$C$L1: ... something ...
$C$L2: ... something else ...
You probably should not use the .switch section in assembly code. It is intended only for use by the compiler to implement C switch statements.
But I think you directly B $C$L1, or B $C$L2, right?
That should not be the case for a compiler-generated switch table.
But if we can use branch directly, we don't even need a switch section. Why we need to bring in the switch section?
The .switch table is a way to densely encode what would have been a bunch of branches. It's just an optimization. When there are many entries in the .switch table, it becomes more clear how you can save a lot of code size (and maybe cycles) compared to the version with lots of branches.
Is the .switch table causing you a problem?
No sir, just curious.
From your answer, I know those records in .switch are independent to each other. That is enough for my research.
Thank you very much. And your answer already verified.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.