Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!mcsun!ukc!inmos!mph From: mph@lion.inmos.co.uk (Mike Harrison) Newsgroups: comp.arch Subject: Re: RISC Machine Data Structure Word Alignment Problems? Message-ID: <3919@ganymede.inmos.co.uk> Date: 1 Feb 90 13:36:14 GMT References: <1810@sunquest.UUCP> Sender: news@inmos.co.uk Reply-To: mph@inmos.co.uk (Mike Harrison) Organization: INMOS Limited, Bristol, UK. Lines: 64 In article <1810@sunquest.UUCP> terry@sunquest.UUCP (Terry Friedrichsen) writes: >The abstruct/memstruct proposal for aligning/not aligning C structure >members leads me to post what I thought was the obvious idea all >along :-): > >Borrow Pascal's idea of "records" and "packed records". So in C, Or even borrow Ada's ideas, which separate the abstaction and the representation. Given a sset of declarations such as: type INTEGER32 is range -2147483648 .. 2147483647; type INTEGER16 is range -32768 .. 32767; type STRUCT is record F1 : INTEGER32; F2 : INTEGER16; F : INTEGER32; end record; objects of type STRUCT will be mapped in any way that the compiler wishes, with fields (potentially) re-ordered, padding added etc., for efficiency of access. If I need a specific mapping I can achieve it by providing a Representation Clause, eg. for maximum packing: WORD : constant := 4; -- assumes storage unit is byte, 4 bytes per word. for INTEGER32'SIZE use 32; for INTEGER16'SIZE use 16; for STRUCT use record at mod 16; F1 at 0 * WORD range 0 .. 31; F2 at 1 * WORD range 0 .. 15; F3 at 1 * WORD range 16 .. 47; end record; In this case objects of type STRUCT will be laid out exactly as shown and will occupy exactly 80 bits, and will be aligned on a half-word boundary. The compiler will generate appropriate code to access complete objects or idividual fields, for a RISC of the kind being discussed this will obviously be (?much) less efficient, but if the application needs it who cares? If I wish to declare an array of these objects, such as: type STRUCT_ARRAY is array (NATURAL range <>) of STRUCT; I can inform the compile that I want maximum packing by writing : pragma PACK (STRUCT_ARRAY); Mike, Michael P. Harrison - Software Group - Inmos Ltd. UK. ----------------------------------------------------------- UK : mph@inmos.co.uk with STANDARD_DISCLAIMERS; US : mph@inmos.com use STANDARD_DISCLAIMERS;