#define DUFFS_DEVICE(x,size) \
{ \
if(size 0) \
{ \
int __DUFFS_DEVICE_count, __DUFFS_DEVICE_n; \
__DUFFS_DEVICE_count = size; \
__DUFFS_DEVICE_n = (__DUFFS_DEVICE_count+7) 3; \
switch (__DUFFS_DEVICE_count & 7) \
{ \
case 0: do { x; \
case 7: x; \
case 6: x; \
case 5: x; \
case 4: x; \
case 3: x; \
case 2: x; \
case 1: x; \
} while (--__DUFFS_DEVICE_n 0); \
} \
} \
}
Sample usage:
/*
Previous code:
for(int i=0; i<size; i++) { *dest++ = *src++; }
*/
//New code:
DUFFS_DEVICE(*dest++ = *src++, size);
Another example:
/*
Previous code:
for(int i=0; i<size; i++) { do_something_given(i); }
*/
//New code:
//Note: for optimal performance, do_something_given() should be inlined
DUFFS_DEVICE(do_something_given(i); i++;, size); |