• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Development Tools » TI C/C++ Compiler » TI C/C++ Compiler - Forum » .switch and .vector sections
Share
TI C/C++ Compiler
  • Forum
Options
  • Subscribe via RSS

Forums

.switch and .vector sections

This question is answered
da cheng
Posted by da cheng
on Oct 01 2010 01:59 AM
Intellectual370 points

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

Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • Archaeologist
    Posted by Archaeologist
    on Oct 01 2010 09:49 AM
    Mastermind40800 points

    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.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • da cheng
    Posted by da cheng
    on Oct 01 2010 11:20 AM
    Intellectual370 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Oct 01 2010 12:18 PM
    Verified Answer
    Verified by da cheng
    Mastermind40800 points

    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.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • da cheng
    Posted by da cheng
    on Oct 01 2010 12:24 PM
    Intellectual370 points

    But I think you directly B $C$L1, or  B $C$L2, right?

     

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Oct 01 2010 12:30 PM
    Mastermind40800 points

    That should not be the case for a compiler-generated switch table.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • da cheng
    Posted by da cheng
    on Oct 01 2010 12:40 PM
    Intellectual370 points

    But if we can use branch directly, we don't even need a switch section. Why we need to bring in the switch section?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Archaeologist
    Posted by Archaeologist
    on Oct 01 2010 13:05 PM
    Mastermind40800 points

    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?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • da cheng
    Posted by da cheng
    on Oct 01 2010 13:39 PM
    Intellectual370 points

    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

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

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.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use