Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!ut-ngp!dlnash From: dlnash@ut-ngp.UUCP (Donald L. Nash) Newsgroups: comp.arch,comp.lang.c Subject: Re: Byte .vs. Word Alignment Message-ID: <5025@ut-ngp.UUCP> Date: Thu, 16-Apr-87 11:31:34 EST Article-I.D.: ut-ngp.5025 Posted: Thu Apr 16 11:31:34 1987 Date-Received: Sun, 19-Apr-87 05:58:10 EST References: <244@petro.UUCP> Organization: UTexas Computation Center, Austin, Texas Lines: 55 Keywords: C, 680X0, Alignment Xref: mnetor comp.arch:972 comp.lang.c:1744 In article <244@petro.UUCP>, jrb@petro.UUCP (Jon Boede) writes: > This is probably the most trivial of questions, but I've always wondered if > wordwise alignment affected efficiency on the 68000. > > For example, assuming that a structure like: > > struct { > int an_int; > char a_char; > } a_struct; > > starts on a word boundry, would a structure placing the /char/ first and the > /int/ therefore a 1/4 word off be less, can we say, "efficient" in terms of > the manipulation needed to get to /an_int/?? Or doesn't the C compiler always > start structures on words boundries, making alignment consideration by the > programmer meaningless? > > struct { > char a_char; > int an_int; > } a_struct; /* is this less "efficient"? */ C compilers reserve the right to pad a structure to make it fit alignment restrictions. There might be some unused space between a_char and an_int to make an_int line up on a word boundary. I know that 4.3 BSD pcc on a VAX does this, because I have tested it on similar constructs, ditto 4.2 BSD pcc. If you are using a 680x0 C compiler derived from either of these (like on 4.2 BSD on a Sun), it probably pads as well. > Also, whilst I'm on the subject, how much extra effort is required of the > 68000 to get to specific bits than to, say, an int? I often use structures > of bit flags to save space in files. I can easily compute the space savings, > but an accurate guess as to the time savings is a little more elusive. The 68020 has bit field instructions for dealing with this sort of thing. How efficient your code is when using bit fields in C depends on whether your compiler is smart enough to use these instructions. I don't have a 68000 manual, only a 68020 manual, so I can't tell you for certain if the 68000 has these instructions, although I assume it does. Don Nash UUCP: ...!{ihnp4, allegra, seismo!ut-sally}!ut-ngp!dlnash ARPA: dlnash@ngp.UTEXAS.EDU BITNET: CCEU001@UTADNX, DLNASH@UTADNX TEXNET: UTADNX::CCEU001, UTADNX::DLNASH UUU UUU U U The University of Texas at Austin U TTTTUTTTTTTTTT Computation Center U T U TT T U U TT "The world is basically non-linear." UUUUUUU TT TT TTTT