On Mon, 24 Feb 2003, IOhannes zmoelnig wrote:
how can i make use of loop-unrolling of the compiler ? (how do i have to built the loops? my experiments showed rather worse results when i did large loops (which could have been unrolled by the compiler))
excerpt from gridflow/base/number.c :
template <class O> class Op2Loops { public: template <class T> static void op_map (int n, T *as, T b) { while ((n&3)!=0) { *as++ = O::foo(*as,b); n--; } while (n) { as[0] = O::foo(as[0],b); as[1] = O::foo(as[1],b); as[2] = O::foo(as[2],b); as[3] = O::foo(as[3],b); as+=4; n-=4; } } [...]
and then you have to limit the size of your vectorizations in order to reduce cache-misses.
afaik, gcc only does unrolling when it knows exactly the number of iterations. maybe recent versions are different, but gcc 2.95 is still quite in use (and i still use it).
________________________________________________________________ Mathieu Bouchard http://artengine.ca/matju