help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -ffast-math option at compling octave in FreeBSD ports ?


From: Tatsuro MATSUOKA
Subject: Re: -ffast-math option at compling octave in FreeBSD ports ?
Date: Mon, 8 Dec 2008 11:50:50 +0900 (JST)

Hello 

To:address@hidden, address@hidden

cc.Thomas and Hajaek

First I would like to express thanks to Thomas and Hajaek for their replies.

Due to my writing being poor, I could not represent what I would like to say
correctly. 

I have a little knowledge about -ffast-math option in GCC and the option 
perhaps may causes troubles with in the numerical calculation. So this option 
should be treated with grate care.

The questioner in the octave thread in Japan seems to be user of the Free BSD.  
He felt that it was strange that --ffast-math option was described in the 
compiling octave in the package of octave in the FreeBSD port.

I feel that now this is matter of ML of FreeBSD  matter but not that of 
octave-help (and/or octave-maintainers).  

However I myself am not a FreeBSD user so that it would be grateful for me if 
somebody in these MLs who are users of FreeBSD will answer to his question:

Why are the -ffast-math option included in the compiling octave in the FreeBSD 
port of octave?

Regards

Tatsuro

--- Thomas Weber  wrote:
> On Sun, Dec 07, 2008 at 05:12:29PM +0900, Tatsuro MATSUOKA wrote:
> > Hello
> > 
> > In an octave thread in Japan, there was a report that asked the meaning 
> > -ffast-math option in FreeBSD ports.
> > 
> > It will be glad for me if there are some peple who will give me information 
> > about it.
> 
> It tries to exploit some processor features for faster mathematic
> functions, but breaks IEEE 754 for that. Citing gcc's manual:
> 
> ========================================================================
> This option causes the preprocessor macro __FAST_MATH__ to be defined.
> This option is not turned on by any `-O' option since it can result in
> incorrect output for programs which depend on an exact implementation of
> IEEE or ISO rules/specifications for math functions. It may, however,
> yield faster code for programs that do not require the guarantees of
> these specifications.
> ========================================================================
> 
> For details, you are probably best off asking on gcc's list.
> 
> The obvious question is now whether Octave and all used libraries work
> with -ffast-math. Sorry, I have no idea about that.
> 
>    Thomas

--- Jaroslav Hajek  wrote:
> On Sun, Dec 7, 2008 at 9:12 AM, Tatsuro MATSUOKA <address@hidden> wrote:
> > Hello
> >
> > In an octave thread in Japan, there was a report that asked the meaning 
> > -ffast-math option in FreeBSD ports.
> >
> > It will be glad for me if there are some peple who will give me information 
> > about it.
> >
> > Regards
> >
> > Tatsuro
> >
> > --------------------------------------
> > Power up the Internet with Yahoo! Toolbar.
> > http://pr.mail.yahoo.co.jp/toolbar/
> > _______________________________________________
> > Help-octave mailing list
> > address@hidden
> > https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> >
> 
> I'm not exactly an expert, but I'll try to explain:
> -ffast-math in GCC enables certain optimizations that can dramatically
> boost performance, but may slightly violate the expected semantics of
> a computation.
> 
> To get an idea what is allowed under -ffast-math, try this simple
> function with g++:
> 
> void dscal (double *x, int n, double a)
> {
>   for (int i = 0; i < n; i++)
>     x[i] /= a;
> }
> 
> compiled (to assembler) using "-O3 -fomit-frame-pointer"
> (I intentionally omit -funroll-loops so that the assembler stays readable)
> I get (g++ 4.3, old Intel Celeron):
>     movl    8(%esp), %ecx
>     movl    4(%esp), %edx
>     fldl    12(%esp)
>     testl    %ecx, %ecx
>     jle    .L8
>     xorl    %eax, %eax
>     .p2align 4,,7
> .L4:
>     fldl    (%edx,%eax,8)
>     fdiv    %st(1), %st
>     fstpl    (%edx,%eax,8)
>     addl    $1, %eax
>     cmpl    %ecx, %eax
>     jne    .L4
> .L8:
>     fstp    %st(0)
>     ret
> 
> whereas with "-O3 -fomit-frame-pointer -ffast-math" I get:
>     movl    8(%esp), %ecx
>     movl    4(%esp), %edx
>     fldl    12(%esp)
>     testl    %ecx, %ecx
>     jle    .L8
>     fld1
>     xorl    %eax, %eax
>     fdivp    %st, %st(1)
>     .p2align 4,,7
> .L4:
>     fldl    (%edx,%eax,8)
>     fmul    %st(1), %st
>     fstpl    (%edx,%eax,8)
>     addl    $1, %eax
>     cmpl    %ecx, %eax
>     jne    .L4
> .L8:
>     fstp    %st(0)
>     ret
> 
> 
> If you can read assembler at the basic level (like I do), you see that
> in the second case, the compiler essentially transformed the function
> like this:
> void dscal (double *x, int n, double a)
> {
>   double ainv = 1.0/a;
>   for (int i = 0; i < n; i++)
>     x[i] *= ainv;
> }
> 
> This is much faster, because division is much slower than
> multiplication, and can also be better vectorized using SSE
> instructions and loop unrolling.
> However, it may produce slightly different results, because, for instance, 
> while
> x / x is exactly 1 for any finite nonzero x, x * (1/x) is not (in FP math).
> Another thing is that with -ffast-math, compiler is allowed to assume
> that NaNs and Infs do not occur in expressions, and thus, for
> instance, replace "x-x" by 0. (which does not hold for x=NaN).
> 
> HTH,
> 
> -- 
> RNDr. Jaroslav Hajek
> computing expert
> Aeronautical Research and Test Institute (VZLU)
> Prague, Czech Republic
> url: www.highegg.matfyz.cz
>

--------------------------------------
Power up the Internet with Yahoo! Toolbar.
http://pr.mail.yahoo.co.jp/toolbar/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]