Friday, May 11, 2007

Duff's Template


template <class T>
void
duff(T* to, T* from, T count) {
T n = (count+7)/8;
switch (count % 8) {
do {
case 0: *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while (--n > 0);
}
}