www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13170] New: Optimizer - improve branch prediction for final


          Issue ID: 13170
           Summary: Optimizer - improve branch prediction for final switch
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

void A();
void B();
void C();
void D();
void E();

void test(int i)
    while (1)
        final switch (i)
            case 1: A(); break;
            case 2: B(); break;
            case 3: C(); break;
            case 4: D(); break;
            case 5: E(); break;

Instead of using one dispatch at the start of the loop, put the dispatch at
each break;, which will produce much better branch prediction.

See also:


Jul 20 2014