Sender: chris AT mindspring DOT com Message-ID: <38921CD6.2A725779@ix.netcom.com> Date: Fri, 28 Jan 2000 14:48:54 -0800 From: Chris Sears X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.13-7mdk i686) X-Accept-Language: en MIME-Version: 1.0 To: pgcc AT delorie DOT com Subject: pgcc and egcs alignment -- function, basic block and string Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: pgcc AT delorie DOT com I am using pgcc version 2.95.2 and egcs version 2.95.1 Reading specs from /usr/local/pgcc/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.2/specs gcc version pgcc-2.95.2 19991024 (release) Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.95.1/specs gcc version 2.95.1 19990816/Linux (release) This is my pgcc compile line: pgcc -D__KERNEL__ -I/home/chris/linux/include -D__SMP__ -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -fno-strength-reduce -mpreferred-stack-boundary=2 -DCPU=686 -march=i686 -S arch/i386/kernel/ioport.c -o arch/i386/kernel/ioport.s In pgcc functions are being aligned to 16 byte boundaries. Shouldn't this be alignment to a cacheline, .align 32? .text .align 16 .type set_bitmap,@function set_bitmap: pushl %ebp pushl %edi In pgcc some basic blocks (loops?) are being aligned. These 16 byte blocks are ifetch blocks. Quoting Agner Fog, "While aligning data is always important, aligning code is not necessary on the PPlain and PMMX." He means with respect to instruction fetch, not cache line. Is this alignment a good idea? It seems unnecessary from a processor point of view and it seems to increase the cache footprint. The p2align 4,,7 means align min(2^4,7) and it means that there may be some padded nop instructions. This is a COST for ifetch alignment in addition to the cache footprint. cmpl $31,%ebx jle .L1476 .p2align 4,,7 .L1471: movl %edx,(%ebp) addl $4,%ebp In pgcc strings are being aligned to cache lines. But is alignment even necessary for strings? Data structures yes, strings no. .file "ioport.c" .version "01.01" gcc2_compiled.: .section .rodata .LC0: .string "eip: %p\n" .align 32 .LC1: .string "/home/chris/linux/include/asm/spinlock.h" egcs has the same string (32) and basic block alignment (.p2align 4,,7) But it uses .align 4 (!) for functions. I might point out that the gas documentation has a bug in the .align description saying that the operand is like the .p2align operand, the number of bits to shift. So in summary, I think that functions should be aligned to cache lines and that basic blocks and strings should not be aligned at all. Chris Sears cbsears AT ix DOT netcom DOT com