Date: Sat, 13 May 95 01:59:30 -0700 From: Bakul Shah <bakul@netcom.com> To: bugs@FreeBSD.org Subject: Re: i386/395: CRITICAL PROBLEM: spl functions implemented incorrectly Message-ID: <199505130859.BAA28730@netcom19.netcom.com> In-Reply-To: Your message of "Sat, 13 May 95 01:17:00 %2B0700." <m0sACNm-000K2iC@pelican.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans wrote: >The standard also allows entire expressions, function calls and even >accesses to volatile objects to be optimized away if it can be shown >that the side effects are not needed. This is the usual "as if" >rule explictly stated. Except that w.r.t. volatile the compiler has *no* way of knowing the side effects of external entities. The original intent of volatilve was precisely for preventing such `optimizations'. A more reasonable notation would've been _shared_ instead of _volatile_. It is easy to see that a shared variable can change behind your back. Unfortunately, `shared' nowadays connotes something much more specific. I agree with the rest of what Bruce said. This is why in general hiding things away in a function is not safe enough (though, usually, in practise it is). Making driver globals etc. volatile is the way to go (this problem has already been encountered and solved in a similar way by a number of commercial systems, especially multi- processor ones). This seems to work because a compiler must not reorder volatile accesses w.r.t. *other* volatile accesses and it must not optimize away such references. Though, I don't know if gcc handles them right in all cases. If you want to temporarily lose volatility for performance (and where you know this is safe), you can manually copy such values to registers or perhaps, typecasting will work. Pete Carah wrote: > To make global optimizers safe in the presence of *any* non-memory > side effects (I/O) one needs function-attribute flags in the library I think GNU extension of volatile attribute for a function deals with this well, when used with an asm() `function'. --bakul
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199505130859.BAA28730>