#include #include #include long divloop(long n1, long n2) { long q=1; long i; for (i=0; i<100000000; i++) { //printf("%ld\n",q); #ifdef MORE_DEFINED q=n1/n2; // for performance, we have to place it here. #endif if (n2==0) abort(); if (n2==-1 && n1==LONG_MIN) abort(); #ifndef MORE_DEFINED q=n1/n2; // to eliminate undefined behaviour, we have to place it here. #endif n1+=q; // use the result (to so the latency becomes effective); // also, change n1 in the loop to avoid moving the check // for n1 out of the loop. n2 += q; // change n2 in the loop to avoid moving the checks for // n2 out of the loop; moreover, this avoids the // potential optimization of division by loop-invariant // dividers. } return q; }