From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31809 invoked by alias); 18 Nov 2011 15:04:23 -0000 Received: (qmail 31799 invoked by uid 22791); 18 Nov 2011 15:04:22 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-gx0-f175.google.com (HELO mail-gx0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Nov 2011 15:04:06 +0000 Received: by ggnh4 with SMTP id h4so2832400ggn.20 for ; Fri, 18 Nov 2011 07:04:06 -0800 (PST) Received: by 10.236.192.233 with SMTP id i69mr5657351yhn.60.1321628646376; Fri, 18 Nov 2011 07:04:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.47.163 with HTTP; Fri, 18 Nov 2011 07:03:45 -0800 (PST) In-Reply-To: References: From: Alexandru Juncu Date: Fri, 18 Nov 2011 17:57:00 -0000 Message-ID: Subject: Stack allocation To: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg00186.txt.bz2 Hello! [I sent an email on the gcc main list by my mistake, and I am moving the discussion here] I have a curiosity with something I once tested. I took a simple C program and made an assembly file with gcc -S. The C file looks something like this: int main(void) { =C2=A0 int a=3D1, b=3D2; =C2=A0 return 0; } The assembly instructions look like this: subl =C2=A0 =C2=A0$16, %esp movl =C2=A0 =C2=A0$1, -4(%ebp) movl =C2=A0 =C2=A0$2, -8(%ebp) The subl $16, means the allocation of local variables on the stack, right? 16 bytes are enough for 4 32bit integers. If I have 1,2,3 or 4 local variables declared, you get those 16 bytes. If I have 5 variables, we have " =C2=A0 =C2=A0 =C2=A0 =C2=A0subl =C2=A0 =C2= =A0$32, %esp". 5,6,7,8 variables ar the same. 9, 10,11,12, 48 bytes. The observation is that gcc allocates increments of 4 variables (if they are integers). If I allocate 8bit chars, increments of 16 chars. So the allocation is in increments of 16 bytes no matter what. OK, that's the observation... my question is why? What's the reason for this, is it an optimization (does is matter what's the -O used?) or is it architecture dependent (I ran it on x86) and is this just in gcc, just in a certain version of gcc or this is universal? I got a response that is related to the cache line alignment, to optimize cache hits. But I tried to compile the program with the --param l1-cache-size and got the same .s file. Is this ok? Thank you! -- Alexandru Juncu ROSEdu