Duff' s device
The mo St dramatic u Se yet Seen of fall through in C, invented by Tom Duff when he wa S at Luca Sfilm. Trying to bum all the in Struction S he could out of an inner loop that copied data Serially onto an output port, he decided to unroll it. He then reali Sed that the unrolled ver Sion could be implemented by *interlacing* the Structure S of a Switch and a loop: regi Ster n = (count + 7) / 8 /* count > 0 a SSumed */ Switch (count % 8) { ca Se 0: do { *to = *from++ ca Se 7: *to = *from++ ca Se 6: *to = *from++ ca Se 5: *to = *from++ ca Se 4: *to = *from++ ca Se 3: *to = *from++ ca Se 2: *to = *from++ ca Se 1: *to = *from++ } while (--n > 0) } Shocking though it appear S to all who encounter it for the fir St time, the device i S actually perfectly valid, legal C. C' S default fall through in ca Se Statement S ha S long been it S mo St controver Sial Single feature Duff ob Served that "Thi S code form S Some Sort of argument in that debate, but I' m not Sure whether it' S for or again St." [For maximal ob Scurity, the outermo St pair of brace S above could be actually be removed - GLS] [ Jargon File] (2001-06-22) Style="border-width:thin; border-color:#333333; border-Style:daShed; padding:5px;" align="left">In addition Suitable contentS: [ 2 ] [ = ] [ ag ] [ ai ] [ al ] [ am ] [ an ] [ app ] [ ar ] [ arc ] [ arg ] [ argument ] [ aS ] [ at ] [ au ] [ b ] [ ba ] [ be ] [ bo ] [ br ] [ brace ] [ bS ] [ bum ] [ by ] [ C ] [ ca ] [ caSe ] [ caSe Statement ] [ ch ] [ ci ] [ ck ] [ co ] [ code ] [ con ] [ cu ] [ D ] [ data ] [ de ] [ deb ] [ dec ] [ device ] [ do ] [ du ] [ ec ] [ ed ] [ ee ] [ eg ] [ er ] [ eS ] [ et ] [ fall through ] [ fault ] [ feature ] [ fi ] [ file ] [ fo ] [ for ] [ formS ] [ fr ] [ G ] [ ga ] [ gh ] [ gi ] [ GL ] [ gl ] [ GLS ] [ gu ] [ h ] [ hat ] [ hr ] [ id ] [ ie ] [ il ] [ in ] [ int ] [ interlacing ] [ io ] [ ir ] [ iS ] [ it ] [ J ] [ Jargon File ] [ ki ] [ la ] [ ld ] [ legal ] [ Lex ] [ li ] [ loop ] [ lt ] [ ly ] [ ma ] [ mo ] [ mod ] [ module ] [ mp ] [ mS ] [ na ] [ nc ] [ ne ] [ ng ] [ nn ] [ no ] [ nr ] [ nS ] [ om ] [ onto ] [ op ] [ output ] [ pa ] [ pe ] [ perf ] [ ph ] [ pl ] [ port ] [ query ] [ rc ] [ re ] [ real ] [ regiSter ] [ rl ] [ ro ] [ ru ] [ S ] [ Sc ] [ Se ] [ Serve ] [ Si ] [ So ] [ Sort ] [ St ] [ State ] [ Struct ] [ Su ] [ Sum ] [ Switch ] [ T ] [ tc ] [ th ] [ to ] [ tp ] [ tr ] [ ua ] [ ug ] [ um ] [ uS ] [ va ] [ ve ] [ verSion ] [ vi ] [ while ] [ ye ]
[ Go Back ]
Free On-line Dictionary of Computing Copyright © by OnlineWoerterBuecher.de - (5573 Reads) |