From owner-freebsd-current Mon Jan 29 20:13:33 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id UAA18971 for current-outgoing; Mon, 29 Jan 1996 20:13:33 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id UAA18948 Mon, 29 Jan 1996 20:13:14 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id PAA18640; Tue, 30 Jan 1996 15:08:25 +1100 Date: Tue, 30 Jan 1996 15:08:25 +1100 From: Bruce Evans Message-Id: <199601300408.PAA18640@godzilla.zeta.org.au> To: bde@zeta.org.au, terry@lambert.org Subject: Re: Optimization topics Cc: current@freefall.freebsd.org, dyson@freefall.freebsd.org Sender: owner-current@FreeBSD.ORG Precedence: bulk >Specifically, it should be possible to run FreeBSD with the unaligned >access bit set to disallow unaligned access of word/dword/qword objects. I implemented this in Minix about 5 years ago. My compiler generates many misaligned access (it forgets to align switch tables) and gcc generates a few (e.g., it generates pessimized inline code for assigning poorly (but correctly!) aligned structs: --- struct foo { char x[4096]; }; struct bar { char pad; struct foo slow; }; void misaligned_copy(struct bar *p, struct bar *q) { p->slow = q->slow; } --- so my alignment trap handler silently clears the alignment check in the flags and returns (printing a warning was too annoying and not printing a warning wasn't annoying enough for me to fix the compilers :-). >At the very least, the kernel code should be clean of this cruft. It isn't easy to check for alignment in the kernel because the alignment trap doesn't apply in ring 0. >In Windows95, some programmers apparently believe that adding 3 bytes >to the end of a packed structure containing a byte followed by 20 >longs means "align to a longword boundry" -- at least that's what >the comments in the DDK header files say. >Clearly, these people never ran their own code in a kernel debugger, >or they simply failed to see the significance of unaligned access. Well, alignment to 32-bit boundaries is standard for the i386 (Unix) version of gcc. The longs would be automatically aligned and the 3 bytes at the end would waste 4 bytes of space. There is a problem for alignment of doubles. They should be aligned on 64 boundaries but ABIs specify only 32-bit boundaries >Many of the problems derive from unaligned stacks being passed down >to otherwise "correct" code. Fie. This isn't a problem for FreeBSD (except when the temporary kernel stack was misaligned in an old version :-). Bruce