On Wed, 6 Feb 2013, Ye Joey wrote:

> Following case attempts to set floating point control register and
> execute floating point operation afterward. However, it doesn't works
> as expected with -Os, as GCC hoists multiply operation beyond FP
> control register setting.

Recent discussions started by Michael Zolotukhin (see gcc list archives 
for December and January) discuss issues around making GCC aware of 
floating-point state.  Given such awareness, GCC would know that arbitrary 
function calls could change the rounding mode (-frounding-math) and change 
or read the set of raised exception flags (-ftrapping-math) and so that 
floating-point operations can't generally be moved across them.

Similar to the handling of function calls, inline asms that read / write / 
clobber floating-point state registers should also be handled accordingly.  
There may be issues for platforms where there is no name for the relevant 
control register that can be used when describing the effects of an asm to 
GCC, but as long as there is a name for that register, it should be 
possible to make GCC know which asms are relevant to floating-point state 
(and otherwise, GCC could simply be conservative about moving 
floating-point operations across asms).

> How about the idea to provide some kind of barrier that can prevent
> such a hoisting from happening?

In the absence of proper GCC support for floating-point state, see the 
tricks used in glibc libm to control where an expression is evaluated in 
relation to rounding-mode changes (using empty asms with appropriate 
inputs and outputs).

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to