Remix.run Logo
▲ ahartmetz 2 hours ago

You want to avoid branches in hot paths. If you branch inside the loop, lots of branches. If you branch outside the loop (into different specialized loops), few branches. Big fucking deal.

▲gpderetta 2 hours ago | parent [-]

https://en.wikipedia.org/wiki/Loop_unswitching

▲econ an hour ago | parent [-]

    bool w;
    int x[1000];
    int y[1000];
    for(int i=0;i<1000;i++){
      x[i] += y[i];
    }
    if(w){
      for(int i=0;i<1000;i++){
        y[i] = 0;
      }
    }
Slower but prettier with the if pushed down.