Page tree
Skip to end of metadata
Go to start of metadata

Modern compilers have extremely good optimisers, but they are still only as good as the code they are trying to optimise.

This project will investigate how the layout of the source code affects the code to be optimised.
For example in this loop, if the if clause always returns the same value, the code will always evaluate the if and else if to get to the function DoYetAnotherThing

for(i=0; i<n; i++)  {
  if( (lpDRV->dpCAPS) & CLIPPING ) {
    DoOneThing(i);
  } else if( (lpDRV->dpCAPS) & ALREADYCULLED ) {
    DoSomethingElse(i);
  } else {
    DoYetAnotherThing(i);
  }
}

A more efficient approach would be:

if( (lpDRV->dpCAPS) & CLIPPING ) {
  for(i=0; i<n; i++)  {
    DoOneThing(i);
  }
} else if( (lpDRV->dpCAPS) & ALREADYCULLED ) 	{
  for(i=0; i<n; i++) {
      DoSomethingElse(i);
   }
} else {
  for(i=0; i<n; i++) {
    DoYetAnotherThing(i);
  }
}

Here the if clause is only called once.

  • No labels