From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 20630 invoked from network); 23 Jun 1999 17:22:06 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 23 Jun 1999 17:22:06 -0000 Received: from delta.ds2.pg.gda.pl (macro@delta.ds2.pg.gda.pl [153.19.170.1]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id MAA13057 for ; Wed, 23 Jun 1999 12:24:56 -0400 Received: from localhost (macro@localhost) by delta.ds2.pg.gda.pl (8.8.8/8.8.8) with SMTP id SAA18443 for ; Wed, 23 Jun 1999 18:24:00 +0200 (MET DST) Date: Wed, 23 Jun 1999 18:23:59 +0200 (MET DST) From: "Maciej W. Rozycki" To: axp-list@redhat.com Subject: Re: problem with unaligned access on Alpha In-Reply-To: <199906231456.IAA03278@ellpspace.math.ualberta.ca> Message-ID: Organization: Technical University of Gdansk MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Wed, 23 Jun 1999, Michal Jaegermann wrote: > Legality aside peple who write such "nice" code should be run out of > town. Unfortunately such way is quite popular; mostly because in most > situations one can get away with it. Let me give you a real example. I have a stream of compressed data created on a 16-bit machine. It is a mixture of 8-bit and 16-bit unsigned quantities. How would you handle it most efficiently? I would define a "uint8_t *x" pointer (a "void *x" would be an option here, but the former one allows pointer arithmetics in a portable way) and depending on the current necessity I would use it as is for 8-bit quantities or use "((uint16_s *)&(x))->v" cast (where "uint16_s" is defined as "typedef struct { uint16_t v __attribute__((packed)); } uint16_s;") to access 16-bit ones. As of egcs 1.1 this should inform the compiler, data is potentially unaligned and result in a possibly most efficient code, i.e. a single opcode for machines that do not have any alignment constraints (like i386) or two opcodes for unaligned fetch for machines that do not support unaligned bus accesses (like Alpha or MIPS). One can use "uint8_t" fetches with appropriate shifting and ORing (it's still necessary on different-endian machines even though some archs have explicit support for most common endianness convertions) but this wastes a lot of unnecessary cycles. If you have any other ideas, please do not hesitate to share them. -- + Maciej W. Rozycki, Technical University of Gdansk, Poland + +--------------------------------------------------------------+ + e-mail: macro@ds2.pg.gda.pl, PGP key available +