This reminded me of the pin register trick I wrote about in a previous post, but this trick starts to become really interesting when used with the concept of loop unrolling for hard-core code optimization.
Thanks to Tom Duff and his cleverly named "Duff Device", we can show this optimization technique in C and not assembler.
/* A Duff Device
antipastohw.blogspot.com */
#define DUFF_DEVICE_8(aCount, aAction) \
do { \ int count_ = (aCount); \
int times_ = (count_ + 7) >> 3; \
switch (count_ & 7){\
case 0: do { aAction; \
case 7: aAction; \
case 6: aAction; \
case 5: aAction; \
case 4: aAction; \
case 3: aAction; \
case 2: aAction; \
case 1: aAction; \
} while (--times_ > 0); \ } \ } while (0)
Thanks Tom, and now it's possible to enhance many of the low-level drawing routines of Matt's Sub-Processing library on the TouchShield to support screen painting at 60 frames per second. Not too shabby for an 8-bit device.
Chris
1 comment:
wow - all that, just to avoid some extra conditional jumps in assembly language... crazy! i can't wait to test out the faster core to see what it looks like :)
Post a Comment