Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Explanation, please! Message-ID: <1988Aug28.031926.19222@utzoo.uucp> Organization: U of Toronto Zoology References: <638@paris.ICS.UCI.EDU> <634@proxftl.UUCP> Date: Sun, 28 Aug 88 03:19:26 GMT In article <634@proxftl.UUCP> bill@proxftl.UUCP (T. William Wells) writes: >[Duff's Device] >The false god of efficiency has reared it ugly head. This >routine would be imagined to be more efficient than the almost >equivalent: ... > while (--count >= 0) > *to++ = *from++; > >However, it often (always?) is not... On the contrary, it often (usually?) is. This is from experience, not theory. (Specifically, experience in C News and related code.) The major exceptions are (a) the 68010, on which unrolling of simple loops is a mistake because of "loop mode" [the hardware's very limited loop cache], and (b) machines with fairly smart compilers and specialized bulk-transfer instructions, as the compilers may be able to recognize and optimize the simple loop but not the complex one. In general, however, in the long run the correct way to implement bulk data copying is to call "memcpy", which (in the long run) is likely to be recognized and given special attention by most compilers. -- Intel CPUs are not defective, | Henry Spencer at U of Toronto Zoology they just act that way. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu