From owner-freebsd-hackers@FreeBSD.ORG Sun May 3 18:59:57 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5CE2C106566C for ; Sun, 3 May 2009 18:59:57 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from mail14.syd.optusnet.com.au (mail14.syd.optusnet.com.au [211.29.132.195]) by mx1.freebsd.org (Postfix) with ESMTP id 156C48FC12 for ; Sun, 3 May 2009 18:59:55 +0000 (UTC) (envelope-from peterjeremy@optushome.com.au) Received: from server.vk2pj.dyndns.org (c122-106-216-167.belrs3.nsw.optusnet.com.au [122.106.216.167]) by mail14.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id n43Ixqfl032418 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 4 May 2009 04:59:53 +1000 X-Bogosity: Ham, spamicity=0.000000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.3/8.14.3) with ESMTP id n43IxpYN062180; Mon, 4 May 2009 04:59:51 +1000 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.3/8.14.3/Submit) id n43Ixowu062173; Mon, 4 May 2009 04:59:50 +1000 (EST) (envelope-from peter) Date: Mon, 4 May 2009 04:59:50 +1000 From: Peter Jeremy To: John Gemignani Message-ID: <20090503185950.GA62081@server.vk2pj.dyndns.org> References: <108501c9c8fe$3a30ab0e$72020a0a@desktop.isilon.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="T4sUOijqQbZv57TR" Content-Disposition: inline In-Reply-To: <108501c9c8fe$3a30ab0e$72020a0a@desktop.isilon.com> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.19 (2009-01-05) X-Mailman-Approved-At: Sun, 03 May 2009 19:12:47 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: C99: Suggestions for style(9) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 May 2009 18:59:57 -0000 --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2009-Apr-29 12:10:44 -0700, John Gemignani w= rote:=20 >Are local variables allocated on-the-fly on the stack or does the >compiler preallocate the space on entry? This is compiler and optimisation dependent. As a general rule, if a compiler is not performing any optimisation, it is likely to allocate all variables on the stack. An obvious code optimisation is to keep variables in registers instead of storing them on the stack. In the specific case of older gcc versions with optimisation enabled (I'm not sure of the behaviour of gcc 4.x), gcc will immediately spill (allocate on the stack) local variables that aren't eligible to be held in registers (eg too large or the variable address is taken) and allocate remaining variables to virtual registers. During code generation, virtual registers are mapped to physical registers and any remaining virtual registers are allocated on the stack. > If I have to delve into a >crashdump, having the variables on the big entry allocation has been >very helpful in the past. OTOH, not caching variables in registers has a significant adverse impact on performance. --=20 Peter Jeremy --T4sUOijqQbZv57TR Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (FreeBSD) iEYEARECAAYFAkn96aYACgkQ/opHv/APuIeUlQCghdfapFUS4oq1QlKxGhl+4Ui6 F9IAoLCv+iOrQcFdgTD2FCcmh6SAugca =b42X -----END PGP SIGNATURE----- --T4sUOijqQbZv57TR--