<pre class="notranslate">From Charlie Dorian:

I continued exploring using constants versus array elements in a
polynomial evaluation with the 8g compiler. I added a fourth function
to test,
   func poly1(x float64) float64 {
     return x * ((x*P[0]+P[1])*x+P[2]) / ((x*Q[0]+Q[1])*x+Q[2])
   }
   func poly2(x float64) float64 {
     p := (x*P[0]+P[1])*x+P[2]; q := (x*Q[0]+Q[1])*x+Q[2]
     return x * p / q
   }
   func poly3(x float64) float64 {
     p := (x*P0+P1)*x+P2; q := (x*Q0+Q1)*x+Q2
     return x * p / q
   }
   func poly4(x float64) float64 {
     return x * ((x*P0+P1)*x+P2) / ((x*Q0+Q1)*x+Q2)
   }
timed them (subtracting the function call overhead, results were
5.56ns, 7.01ns, 7.54ns and 5.30ns) and examined the assembly code the
compiler produced.

This time, 8g produces perfect code for poly4. As before, poly2 and
poly3 had additional code for the temporaries that was not yet
optimized away.

However, 8g produces extraneous instructions for poly1. For example:
   ...
   0005 (p.go:50) LEAL    P+0(SB),BX
   0006 (p.go:50) MOVL    BX,AX
   0007 (p.go:50) FMOVD   (BX),F0
   0008 (p.go:50) FMULD   x+0(FP),F0
   0009 (p.go:50) LEAL    P+0(SB),BX
   0010 (p.go:50) ADDL    $8,BX
   0011 (p.go:50) MOVL    BX,AX
   0012 (p.go:50) FMOVD   (BX),F0
   ...
The AX register is never later referenced. I tested the potential
improvement by a straightforward conversion of poly1 to assembly, so
it now looked like:
   ...
   LEAL    ·P+0(SB),BX
   FMOVD   (BX),F0
   FMULD   x+0(FP),F0
   LEAL    ·P+0(SB),BX
   ADDL    $8,BX
   FMOVD   (BX),F0
   ...
It took 4.36ns. In other words, for 386 code, using an array was 22
percent faster than using constants.

In summary, once 6g and 8g are improved, using arrays in source code
will produce the fastest polynomial evaluations, because, they're
faster for the 386 and the same as constants for the amd64.</pre>
<pre class="notranslate">Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
<a href="http://golang.org/doc/devel/release.html" rel="nofollow">http://golang.org/doc/devel/release.html</a>  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?
I installed Go using the installer, which by default installs go to /usr/local/go . If I
try to use the -a build flag for go install, I get a permission denied error (because I
as a user don't have permission to write to /usr/local). I'm not sure what the right
solution to this is, but it would be nice to have some kind of workaround where I can
re-install all non std lib packages (or where I could re-install the standard library). 

What is the expected output?
brendan:~/Documents/mygo/bin$ go install -a github.com/gonum/floats
should work fine (or maybe with a different flag)

What do you see instead?
brendan:~/Documents/mygo/bin$ go install -a github.com/gonum/floats
go install runtime: open /usr/local/go/pkg/darwin_amd64/runtime.a: permission denied

Which compiler are you using (5g, 6g, 8g, gccgo)?
gc

Which operating system are you using?
darwin

Which version are you using?  (run 'go version')
go version go1.1.2 darwin/amd64

Please provide any additional information below.
<a href="https://groups.google.com/forum/#" rel="nofollow">https://groups.google.com/forum/#</a>!searchin/golang-nuts/runtime$20permission$20denied/golang-nuts/yniBC9gM9I0/6sqirDNIF08J


At the moment I can get around it by cleaning the contents of the package install
folder, but it would be nice to not have to do so.</pre>