]> Cypherpunks repositories - gostls13.git/commit
math: regularize build
authorRuss Cox <rsc@golang.org>
Tue, 13 Dec 2011 20:20:12 +0000 (15:20 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 13 Dec 2011 20:20:12 +0000 (15:20 -0500)
commitdd8dc6f0595ffc2c4951c0ce8ff6b63228effd97
treed95de611b9406a85f52eb19f951394cb353b324c
parent6f975fbb31d97606154b8e753389fb1410a91de6
math: regularize build

This will be nicer to the automatic tools.
It requires a few more assembly stubs
but fewer Go files.

There are a few instances where it looks like
there are new blobs of code, but they are just
being copied out of deleted files.

There is no new code here.

Suppose you have a portable implementation for Sin
and a 386-specific assembly one.  The old way to
do this was to write three files

sin_decl.go
   func Sin(x float64) float64  // declaration only
sin_386.s
   assembly implementation

sin_port.go
   func Sin(x float64) float64 { ... }  // pure-Go impl

and then link in either sin_decl.go+sin_386.s or
just sin_port.go.  The Makefile actually did the magic
of linking in only the _port.go files for those without
assembly and only the _decl.go files for those with
assembly, or at least some of that magic.

The biggest problem with this, beyond being hard
to explain to the build system, is that once you do
explain it to the build system, godoc knows which
of sin_port.go or sin_decl.go are involved on a given
architecture, and it (correctly) ignores the other.
That means you have to put identical doc comments
in both files.

The new approach, which is more like what we did
in the later packages math/big and sync/atomic,
is to have

sin.go
   func Sin(x float64) float64  // decl only
   func sin(x float64) float64 {...}  // pure-Go impl

sin_386.s
   // assembly for Sin (ignores sin)
sin_amd64.s
   // assembly for Sin: jmp sin
sin_arm.s
   // assembly for Sin: jmp sin

Once we abandon Makefiles we can put all the assembly
stubs in one source file, so the number of files will
actually go down.

Chris asked whether the branches cost anything.
Given that they are branching to pure-Go implementations
that are not typically known for their speed, the single
direct branch is not going to be noticeable.  That is,
it's on the slow path.

An alternative would have been to preserve the old
"only write assembly files when there's an implementation"
and still have just one copy of the declaration of Sin
(and thus one doc comment) by doing:

sin.go
   func Sin(x float64) float64 { return sin(x) }

sin_decl.go
   func sin(x float64) float64 // declaration only
sin_386.s
   // assembly for sin

sin_port.go
   func sin(x float64) float64 { portable code }

In this version everyone would link in sin.go and
then either sin_decl.go+sin_386.s or sin_port.go.

This has an extra function call on all paths, including
the "fast path" to get to assembly, and it triples the
number of Go files involved compared to what I did
in this CL.  On the other hand you don't have to
write assembly stubs.  After starting down this path
I decided that the assembly stubs were the easier
approach.

As for generating the assembly stubs on the fly, much
of the goal here is to eliminate magic from the build
process, so that zero-configuration tools like goinstall
or the new go tool can handle this package.

R=golang-dev, r, cw, iant, r
CC=golang-dev
https://golang.org/cl/5488057
84 files changed:
src/pkg/math/Makefile
src/pkg/math/abs.go
src/pkg/math/abs_arm.s [moved from src/pkg/math/log_decl.go with 51% similarity]
src/pkg/math/all_test.go
src/pkg/math/asin.go
src/pkg/math/asin_amd64.s [new file with mode: 0644]
src/pkg/math/asin_arm.s [new file with mode: 0644]
src/pkg/math/asin_decl.go [deleted file]
src/pkg/math/atan.go
src/pkg/math/atan2.go
src/pkg/math/atan2_amd64.s [moved from src/pkg/math/exp_decl.go with 51% similarity]
src/pkg/math/atan2_arm.s [moved from src/pkg/math/tan_decl.go with 51% similarity]
src/pkg/math/atan_amd64.s [new file with mode: 0644]
src/pkg/math/atan_arm.s [new file with mode: 0644]
src/pkg/math/dim.go
src/pkg/math/dim_386.s [new file with mode: 0644]
src/pkg/math/dim_arm.s [new file with mode: 0644]
src/pkg/math/dim_decl.go [deleted file]
src/pkg/math/exp.go
src/pkg/math/exp2.go [deleted file]
src/pkg/math/exp2_amd64.s [new file with mode: 0644]
src/pkg/math/exp2_arm.s [new file with mode: 0644]
src/pkg/math/exp_arm.s [new file with mode: 0644]
src/pkg/math/exp_port.go [deleted file]
src/pkg/math/exp_test.go [deleted file]
src/pkg/math/expm1.go
src/pkg/math/expm1_amd64.s [new file with mode: 0644]
src/pkg/math/expm1_arm.s [new file with mode: 0644]
src/pkg/math/expm1_decl.go [deleted file]
src/pkg/math/export_test.go [new file with mode: 0644]
src/pkg/math/floor.go
src/pkg/math/floor_amd64.s [new file with mode: 0644]
src/pkg/math/floor_arm.s [new file with mode: 0644]
src/pkg/math/floor_decl.go [deleted file]
src/pkg/math/frexp.go
src/pkg/math/frexp_amd64.s [new file with mode: 0644]
src/pkg/math/frexp_arm.s [new file with mode: 0644]
src/pkg/math/frexp_decl.go [deleted file]
src/pkg/math/hypot.go
src/pkg/math/hypot_arm.s [moved from src/pkg/math/atan_decl.go with 51% similarity]
src/pkg/math/hypot_decl.go [deleted file]
src/pkg/math/hypot_port.go [deleted file]
src/pkg/math/hypot_test.go [deleted file]
src/pkg/math/ldexp.go
src/pkg/math/ldexp_amd64.s [new file with mode: 0644]
src/pkg/math/ldexp_arm.s [new file with mode: 0644]
src/pkg/math/ldexp_decl.go [deleted file]
src/pkg/math/log.go
src/pkg/math/log10.go
src/pkg/math/log10_amd64.s [new file with mode: 0644]
src/pkg/math/log10_arm.s [new file with mode: 0644]
src/pkg/math/log10_decl.go [deleted file]
src/pkg/math/log1p.go
src/pkg/math/log1p_amd64.s [new file with mode: 0644]
src/pkg/math/log1p_arm.s [new file with mode: 0644]
src/pkg/math/log1p_decl.go [deleted file]
src/pkg/math/log_arm.s [new file with mode: 0644]
src/pkg/math/mod.go
src/pkg/math/mod_amd64.s [new file with mode: 0644]
src/pkg/math/mod_arm.s [new file with mode: 0644]
src/pkg/math/mod_decl.go [deleted file]
src/pkg/math/modf.go
src/pkg/math/modf_amd64.s [new file with mode: 0644]
src/pkg/math/modf_arm.s [new file with mode: 0644]
src/pkg/math/modf_decl.go [deleted file]
src/pkg/math/remainder.go
src/pkg/math/remainder_amd64.s [moved from src/pkg/math/atan2_decl.go with 50% similarity]
src/pkg/math/remainder_arm.s [new file with mode: 0644]
src/pkg/math/remainder_decl.go [deleted file]
src/pkg/math/sin.go
src/pkg/math/sin_amd64.s [moved from src/pkg/math/exp2_decl.go with 69% similarity]
src/pkg/math/sin_arm.s [moved from src/pkg/math/abs_decl.go with 71% similarity]
src/pkg/math/sin_decl.go [deleted file]
src/pkg/math/sincos.go
src/pkg/math/sincos_arm.s [new file with mode: 0644]
src/pkg/math/sincos_decl.go [deleted file]
src/pkg/math/sqrt.go
src/pkg/math/sqrt_decl.go [deleted file]
src/pkg/math/sqrt_port.go [deleted file]
src/pkg/math/sqrt_test.go [deleted file]
src/pkg/math/tan.go
src/pkg/math/tan_amd64.s [new file with mode: 0644]
src/pkg/math/tan_arm.s [new file with mode: 0644]
src/pkg/runtime/arm/softfloat.c