String copy idiom.
Joe Orost
joe at petsd.UUCP
Sun Mar 10 04:16:48 AEST 1985
In article <3448 at alice.UUCP> ark at alice.UUCP (Andrew Koenig) writes:
>If s and t are char pointers in registers,
>
> while (*s++ = *t++) ;
>
>generates the best code I could possibly imagine.
>
> while ((*s = *t) != '\0') {s++; t++;}
>
>is considerably worse. Try it with register variables on your compiler.
Ok, I did. The second sequence generates less code than the first sequence
on our machine (Perkin-Elmer). This is due to the fact that our machine
doesn't support auto-increment in hardware. The C compiler has to "fake" it.
regards,
joe
--
Full-Name: Joseph M. Orost
UUCP: ..!{decvax,ucbvax,ihnp4}!vax135!petsd!joe
ARPA: vax135!petsd!joe at BERKELEY
US Mail: MS 313; Perkin-Elmer; 106 Apple St; Tinton Falls, NJ 07724
Phone: (201) 870-5844
Location: 40 19'49" N / 74 04'37" W
More information about the Comp.lang.c
mailing list