Explanation, please!
Henry Spencer
henry at utzoo.uucp
Sun Aug 28 13:19:26 AEST 1988
In article <634 at proxftl.UUCP> bill at 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 at zoo.toronto.edu
More information about the Comp.lang.c
mailing list