Path: utzoo!attcan!uunet!lll-winken!lll-lcc!mordor!joyce!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.c Subject: Re: Optimal structure field ordering Summary: Life is stranger than you can imagine. Message-ID: <818@garth.UUCP> Date: 27 Jun 88 22:43:03 GMT References: <163@navtech.uucp> <2775@ttrdc.UUCP> <164@navtech.uucp> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 21 > "The space requirement of any given C structure may be easily > optimized by reorganizing the structure fields in order of decreasing > base type size." Some machines provide an item offset, base address+n chars or words or ..., where the hardware shifts the offset before adding to the base, and some of these same machines handle small offsets or a small range of offsets. In these cases, it is more efficient to put all the small fields first. For example, Cyber 205 provides bit, byte, halfword, and word loads with item offsets of the form LODx [base-address-register,offset-register],destination. If elements are arranged 1 bit, 1 byte, 1 halfword, 1 word, the item offsets are (halfword=32 bits, word=64 bits): small to large large to small +0 bit +0 word +1 byte +2 halfword +1 halfword +12 byte +1 word +104 bit In one case, the program only needs two constant registers and the other needs 4. It is very difficult to find a general rule to best pack a structure. One of the easiest is to throw whole mess at the compiler and say gimme your best shot.