From owner-freebsd-current@FreeBSD.ORG Fri Apr 8 19:39:03 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 76A5816A4CE for ; Fri, 8 Apr 2005 19:39:03 +0000 (GMT) Received: from pi.codefab.com (pi.codefab.com [199.103.21.227]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2C06F43D2F for ; Fri, 8 Apr 2005 19:39:03 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from localhost (localhost [127.0.0.1]) by pi.codefab.com (Postfix) with ESMTP id 6FEF75E16; Fri, 8 Apr 2005 15:39:02 -0400 (EDT) Received: from pi.codefab.com ([127.0.0.1]) by localhost (pi.codefab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 66947-05; Fri, 8 Apr 2005 15:39:01 -0400 (EDT) Received: from [192.168.1.3] (pool-68-161-53-96.ny325.east.verizon.net [68.161.53.96]) by pi.codefab.com (Postfix) with ESMTP id 3C8055E11; Fri, 8 Apr 2005 15:39:00 -0400 (EDT) Message-ID: <4256DD80.4030103@mac.com> Date: Fri, 08 Apr 2005 15:37:36 -0400 From: Chuck Swiger Organization: The Courts of Chaos User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050319 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Peter Jeremy References: <200504061737.18204.michaelnottebrock@gmx.net> <20050407.211210.100582852.imp@bsdimp.com> <20050408184838.GC89047@cirb503493.alcatel.com.au> In-Reply-To: <20050408184838.GC89047@cirb503493.alcatel.com.au> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at codefab.com cc: freebsd-current@freebsd.org Subject: Re: machdep.conspeed sysctl X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2005 19:39:03 -0000 Peter Jeremy wrote: > On Thu, 2005-Apr-07 21:12:10 -0600, M. Warner Losh wrote: [ ... ] > bde made it volatile in 1.162 though it's not clear to me why the > volatile is needed here. I probably need to go and have a close study > of exactly what a compiler is permitted to optimise away in the > absence of 'volatile'. Page 586 of _Compilers: Principles, Techniques, and Tools_ by Aho, Sethi, and Ullman states: "First, a transformation must preserve the meaning of programs. That is, an 'optimization' must not change the output produced by a program for a given input, or cause an error, such as a division by zero, that was not present in the original program." The simple answer is that the compiler is permitted to optimize away *any* code [1], so long as doing so does not change the output of the program. Dead code elimination and common subexpression elimination can be iterated using fixed points until the code is as small and fast as possible, although many compilers only do a few passes. A simple example: int a = 1, b = 2, c = 3; a = b + c; /* this line can be removed as dead code, since nothing uses a before a is assigned a new value. Ditto for "a = 1" above. */ a = b * c; -- -Chuck [1]: With obvious exceptions-- notably the volatile keyword-- as you already know. Basicly, when a variable is declared volatile, the compiler treats that variable as always being live, and it refuses to try to apply CSE or DCE to that variable, so that the code the compiler produces references the variable exactly as the original source code specifies.