Опубликован: 12.07.2012 | Уровень: специалист | Доступ: платный
Лекция 4:

Optimizing compiler. Loop optimizations

< Лекция 3 || Лекция 4: 123456 || Лекция 5 >

Some example estimation for loop unswitching effectivenes:

int main() {
float x[1000],y[1000];
int i,repeat,p;

for(i=0;i<1000;i++) { y[i] = i; x[i] = 1; }

for(repeat=0;repeat<3000000;repeat++) {
p=repeat%10>5;
#ifdef PERF
  if(p) {
    for(i=0;i<1000;i++) {
      x[i]=x[i]+y[i];
      y[i]++;     }
  }
    else {
      for(i=0;i<1000;i++) {
        x[i]=x[i]+y[i];     }
    }
#else
  for(i=0;i<1000;i++) {
    x[i]=x[i]+y[i];
    if(p) {
      y[i]++;      }   }
#endif
}
printf("x[123]= %f\n",x[123]);
}

Рис. 4.4.
Comparison of branch missprediction events for original and modified tests

увеличить изображение
Рис. 4.5. Comparison of branch missprediction events for original and modified tests
Binding processor events to lines of source code

увеличить изображение
Рис. 4.6. Binding processor events to lines of source code
< Лекция 3 || Лекция 4: 123456 || Лекция 5 >
8400 谭
8400 谭
Китай, 从化
JianZhang Xie
JianZhang Xie
Гонконг, HK