Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(39)

Issue 5488057: code review 5488057: math: regularize build (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 5 months ago by rsc
Modified:
13 years, 5 months ago
Reviewers:
CC:
golang-dev, r2, cw, iant, r
Visibility:
Public.

Description

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.

Patch Set 1 #

Patch Set 2 : diff -r 7aaa206cb48f https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 7aaa206cb48f https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 9f58ab1aad74 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+789 lines, -681 lines) Patch
M src/pkg/math/Makefile View 1 3 chunks +24 lines, -48 lines 0 comments Download
M src/pkg/math/abs.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/abs_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/abs_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/all_test.go View 1 2 3 2 chunks +36 lines, -2 lines 0 comments Download
M src/pkg/math/asin.go View 1 2 chunks +8 lines, -2 lines 0 comments Download
A src/pkg/math/asin_amd64.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
A src/pkg/math/asin_arm.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
R src/pkg/math/asin_decl.go View 1 1 chunk +0 lines, -8 lines 0 comments Download
M src/pkg/math/atan.go View 1 1 chunk +3 lines, -1 line 0 comments Download
M src/pkg/math/atan2.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/atan2_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/atan2_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/atan2_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
A src/pkg/math/atan_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/atan_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/atan_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/dim.go View 1 3 chunks +10 lines, -4 lines 0 comments Download
A src/pkg/math/dim_386.s View 1 2 3 1 chunk +12 lines, -0 lines 0 comments Download
A src/pkg/math/dim_arm.s View 1 2 3 1 chunk +12 lines, -0 lines 0 comments Download
R src/pkg/math/dim_decl.go View 1 1 chunk +0 lines, -9 lines 0 comments Download
M src/pkg/math/exp.go View 1 1 chunk +182 lines, -1 line 0 comments Download
R src/pkg/math/exp2.go View 1 1 chunk +0 lines, -10 lines 0 comments Download
A src/pkg/math/exp2_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/exp2_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/exp2_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
A src/pkg/math/exp_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/exp_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
R src/pkg/math/exp_port.go View 1 1 chunk +0 lines, -191 lines 0 comments Download
R src/pkg/math/exp_test.go View 1 1 chunk +0 lines, -10 lines 0 comments Download
M src/pkg/math/expm1.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/expm1_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/expm1_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/expm1_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
A src/pkg/math/export_test.go View 1 1 chunk +12 lines, -0 lines 0 comments Download
M src/pkg/math/floor.go View 1 3 chunks +11 lines, -3 lines 0 comments Download
A src/pkg/math/floor_amd64.s View 1 1 chunk +12 lines, -0 lines 0 comments Download
A src/pkg/math/floor_arm.s View 1 1 chunk +12 lines, -0 lines 0 comments Download
R src/pkg/math/floor_decl.go View 1 1 chunk +0 lines, -9 lines 0 comments Download
M src/pkg/math/frexp.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/frexp_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/frexp_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/frexp_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/hypot.go View 1 2 chunks +46 lines, -1 line 0 comments Download
A src/pkg/math/hypot_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/hypot_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
R src/pkg/math/hypot_port.go View 1 1 chunk +0 lines, -63 lines 0 comments Download
R src/pkg/math/hypot_test.go View 1 1 chunk +0 lines, -9 lines 0 comments Download
M src/pkg/math/ldexp.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/ldexp_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/ldexp_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/ldexp_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/log.go View 1 1 chunk +3 lines, -1 line 0 comments Download
M src/pkg/math/log10.go View 1 1 chunk +10 lines, -2 lines 0 comments Download
A src/pkg/math/log10_amd64.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
A src/pkg/math/log10_arm.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
R src/pkg/math/log10_decl.go View 1 1 chunk +0 lines, -8 lines 0 comments Download
M src/pkg/math/log1p.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/log1p_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/log1p_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/log1p_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
A src/pkg/math/log_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/log_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/mod.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/mod_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/mod_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/mod_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/modf.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/modf_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/modf_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/modf_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/remainder.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/remainder_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/remainder_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/remainder_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/sin.go View 1 2 chunks +6 lines, -2 lines 0 comments Download
A src/pkg/math/sin_amd64.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
A src/pkg/math/sin_arm.s View 1 1 chunk +9 lines, -0 lines 0 comments Download
R src/pkg/math/sin_decl.go View 1 1 chunk +0 lines, -8 lines 0 comments Download
M src/pkg/math/sincos.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/sincos_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/sincos_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/math/sqrt.go View 1 1 chunk +139 lines, -1 line 0 comments Download
R src/pkg/math/sqrt_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
R src/pkg/math/sqrt_port.go View 1 1 chunk +0 lines, -147 lines 0 comments Download
R src/pkg/math/sqrt_test.go View 1 1 chunk +0 lines, -9 lines 0 comments Download
M src/pkg/math/tan.go View 1 1 chunk +3 lines, -1 line 0 comments Download
A src/pkg/math/tan_amd64.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
A src/pkg/math/tan_arm.s View 1 1 chunk +6 lines, -0 lines 0 comments Download
R src/pkg/math/tan_decl.go View 1 1 chunk +0 lines, -7 lines 0 comments Download
M src/pkg/runtime/arm/softfloat.c View 1 2 chunks +2 lines, -2 lines 0 comments Download

Messages

Total messages: 9
rsc
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 5 months ago (2011-12-13 04:50:25 UTC) #1
r2
Can you please explain what you did, and why? -rob
13 years, 5 months ago (2011-12-13 06:30:45 UTC) #2
cw
I like the consistency of the filenames with this, but I wonder do the introduced ...
13 years, 5 months ago (2011-12-13 06:38:12 UTC) #3
iant
LGTM
13 years, 5 months ago (2011-12-13 06:40:46 UTC) #4
rsc
On Tue, Dec 13, 2011 at 01:30, Rob 'Commander' Pike <r@google.com> wrote: > Can you ...
13 years, 5 months ago (2011-12-13 18:17:23 UTC) #5
r2
thanks. can you put this text into the CL please? -rob
13 years, 5 months ago (2011-12-13 18:19:05 UTC) #6
rsc
On Tue, Dec 13, 2011 at 13:19, Rob 'Commander' Pike <r@google.com> wrote: > thanks. can ...
13 years, 5 months ago (2011-12-13 18:22:12 UTC) #7
r
LGTM
13 years, 5 months ago (2011-12-13 18:22:33 UTC) #8
rsc
13 years, 5 months ago (2011-12-13 20:20:14 UTC) #9
*** Submitted as http://code.google.com/p/go/source/detail?r=af839530a31e ***

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
http://codereview.appspot.com/5488057
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b