0 points

Duff’s Device - code snippet written by Tom Duff at Lucasfilm to speed up animation by 50%


Sun Feb 09 2020 19:39:03 GMT+0000 (UTC)

Posted by @carlathemarla #C #historicalcode #loops #starwars

send(to, from, count)
	register short *to, *from;
	register count;
		register n=(count+7)/8;
		case 0:	do{	*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++;
content_copy Copy

In this code, a loop is unwound 8 times and embedded in a switch statement. This decreases the number of sobleqs and gives you a leftover partial loop. Before the loop is entered, the switch calculates the remainder of register copies to carry out. Execution jumps into the loop at the calculated case label, falls through the remaining case labels, and then hits the while keyword which will jump to the beginning of the do-while loop and execute cycles of 8 register copies until n reaches 0.