Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-06 Thread Dorival Pedroso
Fixed. Cheers. On Sunday, August 6, 2017 at 12:23:57 PM UTC+10, Michael Jones wrote: > > Great. Hope it helps. I had a typo in power 0 (which is never called. > Change the return to 1.0. > > On Sat, Aug 5, 2017 at 6:50 PM wrote: > >> Thanks, Michael. >> >> I've created a

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-05 Thread Michael Jones
Great. Hope it helps. I had a typo in power 0 (which is never called. Change the return to 1.0. On Sat, Aug 5, 2017 at 6:50 PM wrote: > Thanks, Michael. > > I've created a tiny project with those files here: > https://github.com/cpmech/go-fast-math-experiments > > The output

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
Thanks, Peter. I actually don't mind a larger code if the performance can be improved. Also, we probably do computations more often with smaller integers (at least in my applications); that's why I overlooked the case greater than 10... But now I'm using your (+Michael Jones and others)

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Michael Jones
Dorival, There is a great deal to learn from this issue. Some interesting issues: Exponentiation by arbitrary real or complex powers is a little complicated to evaluate quickly with accuracy. Other than special cases, you're forced toward x**y ==> Exp(y*Log(x)), where each of Exp() and Log() are

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread peterGo
Dorival Pedroso, PowP has a lot of code. PowG is simpler and it is modestly slower for small values of n and much faster for larger values of n. func PowG(x float64, n uint32) float64 { y := 1.0 for i := n; i > 0; i >>= 1 { if i&1 == 1 { y *= x } x *=

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread pedroso
Since my ASM skills are limited, for positive integers, I'm planning on using: // PowP computes real raised to positive integer xⁿ func PowP(x float64, n uint32) (r float64) { if n == 0 { return 1.0 } if n == 1 { return x } if n == 2 { return x * x } if n == 3 { return x * x * x } if n == 4 { r

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
again i'm wrong :( On Friday, August 4, 2017 at 10:30:14 AM UTC+3, Sebastien Binet wrote: > > > > On Fri, Aug 4, 2017 at 9:24 AM, wrote: > >> Ok, >> i'm not right,pow in C is : >> float powf(float x, float y); >>long double powl(long double >> >> use float32 pow for

Re: [go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread Sebastien Binet
On Fri, Aug 4, 2017 at 9:24 AM, wrote: > Ok, > i'm not right,pow in C is : > float powf(float x, float y); >long double powl(long double > > use float32 pow for proper comparison or use powl for C double wersion. > C'pow is with doubles (like Go's math.Pow):

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
Ok, i'm not right,pow in C is : float powf(float x, float y); long double powl(long double use float32 pow for proper comparison or use powl for C double wersion. This is demonstartion how when you use go long time, you lose ability to read other languages :) On Friday, August 4,

[go-nuts] Re: How to optimize as with -O2 from Gcc? (50x speedup)

2017-08-04 Thread djadala
You are comparing apples to oranges( integer vs float64 pow), use integer pow and compare again: func Pow(a, b int) int { p := 1 for b > 0 { if b&1 != 0 { p *= a } b >>= 1 a *= a