Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: faster bcopy using duffs device (source) Keywords: loop unrolling, optimize, hacks Message-ID: <19531@mimsy.UUCP> Date: 12 Sep 89 12:33:11 GMT References: <5180@portia.Stanford.EDU> <19473@mimsy.UUCP> <16902@rphroy.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 67 >In article <19491@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>Just for fun, here is my bcopy-in-C for (gcc+68010) >> >>#ifndef __GNUC__ >> /* for some reason, gcc does not optimise this */ >> *(short *)dst = *(short *)src; >> dst -= sizeof (short); >> src -= sizeof (short); >>#else >> /* so we use a gcc extension */ >> *--(short *)dst = *--(short *)src; >>#endif In article <16902@rphroy.UUCP> tkacik@rphroy.UUCP (Tom Tkacik) writes: >Do these two program fragments really do the same thing? OOPS! I did not need the gcc-specific grungy hack after all. The first three (#ifndef __GNUC__) lines *should* have read: dst -= sizeof (short); src -= sizeof (short); *(short *)dst = *(short *)src; which gcc is perfectly willing to optimise. >I think that the gcc code should be > *(short *)dst-- = *(short *)src--; No, this is legal C, and means to: evaluate dst, evaluate src; sometime in the near future, assign dst-1 to dst and src-1 to src; fetch a short from the location named by the conversion of the original value of the character pointer `src' to a pointer-to-short (a machine-dependent operation); store that short to the location named by the conversion of ... `dst' (another machine-dependent operation); : finish side effects on dst and src. The gcc-specific hack is not legal C; it means to pretend dst and src are pointers to short, rather than pointers to char (this operation is not only machine-dependent, it is hopeless on some machines, e.g., those where `char *' is 48 bits long but `short *' is 32 bits long); assign dst-sizeof(short) to dst and src-sizeof(short) to src, sometime in the near future; fetch a short from the location named by the result of the decrement of the (pretended word pointer) src; store that short in the location named by the result ... dst; : finish side effects on dst and src. >I just did that and do not see what extenstion Chris is referring to. >Chris, which is it? The one that says that a cast on a pointer is a type pun, rather than a conversion. This, if nothing else, tells why gcc cannot be used to compile C code for a Prime (32 bit word pointers, 48 bit char pointers). (In fact, gcc assumes internally that sizeof(any-pointer) == sizeof(int) and that all pointers are `byte pointers', as far as I can tell.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris