Hello,
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?
regards,
da
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.
Hi again,
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?
Da
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:
.text MVK $C$SW1, A3 MVKH $C$SW1, A3 LDW *A3, A3 NOP 4 B A3 NOP 5 $C$L1: ... something ... $C$L2: ... something else ... .switch $C$SW1: .word $C$L1 .word $C$L2
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.
-Da