Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: what C needs -- packed structures Summary: bogus 68000 code Message-ID: <519@cresswell.quintus.UUCP> Date: 11 Jan 88 03:12:00 GMT References: <8801071842.AA04669@decwrl.dec.com> <2083@chinet.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 25 In article <2083@chinet.UUCP>, dag@chinet.UUCP (Daniel A. Glasser) writes: > struct yerks { char y_foo; int *y_fie; char y_poo; }; > struct yerks *w; > int i; > i = *w->y_fie; He claims that this assignment would turn into 9 M680x0 instructions. Wrong. It can be coded in three: movl _w, a0 movl 1(a0), a0 movl (a0), _i The /370, and the 80386 can also handle misaligned data. The R2000 can handle misaligned data at the cost of one extra instruction *if* the compiler knows the data are misaligned, which in this case it would. None of this spoils Glasser's real point, namely that packing is machine-dependent, and doesn't come free on any machine. Even the machines that will handle his example in few instructions tend to take lots more *cycles* to handle misaligned data. (A loop like register int n = {something}; register long *d = {something}; register long *s = {something}; while (--n >= 0) *d++ = *s++; takes about 30% longer for misaligned than for aligned data on a 68020.) Glasser says > No, packed structures do not belong in the standard. He's absolutely right. We already *have* bitfields, after all.