NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Restrict Inlining Problem

From Texas Instruments Wiki
Jump to: navigation, search

Description of the Restrict Inlining Problem[edit]

A loop which contains an inlined function call and also makes memory accesses may not achieve the expected performance, even if the appropriate pointers are declared "restrict." The reason is that the C standard defines "restrict" to operate within a single lexical scope, and each function body exists in a separate lexical scope. As a result, the effect of "restrict" in the caller does not extend to memory accesses in the called function (inlined or not) and the compiler cannot exploit it to know that accesses in the caller do not overlap (alias) accesses in the called function.

Example[edit]

In the code below, the compiler will be unable to determine if "testArray" and "out" overlap in memory. This is because the C standard specifies specific scoping rules for restrict and so the restrict qualifier on "out" does not apply in funcA. Therefore, the compiler cannot know that "testArray" and "out" do not alias (overlap) and so the software pipelining performance suffers.

  extern int * testArray;

  static __inline int funcA(int i)
  {
    return testArray[i*i];
  }

  void testFunc(int * restrict out, int thresh)
  {
    int i;
    for(i=0; i<100; i++)
    {
      if( funcA(i) > thresh )
      {
        out[0] = i;
        out[1] = i*i;
      }
    }
    return;
  }

Possible Workarounds[edit]

Use a Macro[edit]

Turn the inlined function ("funcA" in our example above) into a macro. "funcA" and "out" will appear in the same scope and so the compiler can use the "restrictness" of out to determine that "funcA" does not alias out.

In the example above, the programmer could turn funcA into:

 #define funcA(i) testArray[i*i]

Hand-inline the function[edit]

The programmer could hand-inline the function. "funcA" and "out" will appear in the same scope and so the compiler can use the "restrictness" of out to determine that "funcA" does not alias out.

Historical Notes[edit]

In the 6.0.x version of the C6000 compiler, certain aspects of the restrict scoping rules were incorrectly implemented. This means that in some situations, incorrect code would be produced by the compiler when restrict was used. In the 6.1.x and later versions of the compiler, the restrict scoping rules are properly implemented. When users move from 6.0.x to 6.1.x or later, users may see decreased performance because of this issue with the restrict keyword and inlined functions.

References[edit]

Restrict Type Qualifier

E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Restrict Inlining Problem here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Restrict Inlining Problem here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article Restrict Inlining Problem here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article Restrict Inlining Problem here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article Restrict Inlining Problem here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Restrict Inlining Problem here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Restrict Inlining Problem here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article Restrict Inlining Problem here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article Restrict Inlining Problem here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity