1
0
mirror of https://github.com/golang/go synced 2024-10-04 08:31:22 -06:00
Commit Graph

161 Commits

Author SHA1 Message Date
Charles L. Dorian
a5c4e0fa2a math: update definition of NaN in assembly language files
R=rsc, minux.ma, golang-dev, nigeltao
CC=golang-dev
https://golang.org/cl/6461047
2012-08-09 09:40:05 +10:00
Shenghou Ma
6e9506a7b4 math, runtime: use a NaN that matches gcc's
our old choice is not working properly at least on VFPv2 in
ARM1136JF-S (it's not preserved across float64->float32 conversions).

        Fixes #3745.

R=dave, rsc
CC=golang-dev
https://golang.org/cl/6344078
2012-08-07 09:57:14 +08:00
Robert Griesemer
6a135a0894 mat/big: more optimal Karatsuba threshold
benchmark           old ns/op    new ns/op    delta
BenchmarkHilbert      6253043      6267289   +0.23%
BenchmarkMul         45355940     39490633  -12.93%

R=r
CC=golang-dev
https://golang.org/cl/6355104
2012-07-12 14:19:09 -07:00
Robert Griesemer
98ca655919 math/big: minor performance tuning
Reuse temporary slice to avoid extra allocations
(originally done correctly by remyoudompheng@gmail.com
in https://golang.org/cl/6345075/).

benchmark           old ns/op    new ns/op    delta
BenchmarkHilbert      6252790      6262304   +0.15%
BenchmarkMul         45827438     45301002   -1.15%

R=r
CC=golang-dev
https://golang.org/cl/6346097
2012-07-12 14:12:50 -07:00
Rémy Oudompheng
ac12131649 math/big: correct quadratic space complexity in Mul.
The previous implementation used to have a O(n) recursion
depth for unbalanced inputs. A test is added to check that a
reasonable amount of bytes is allocated in this case.

Fixes #3807.

R=golang-dev, dsymonds, gri
CC=golang-dev, remy
https://golang.org/cl/6345075
2012-07-12 10:18:24 -07:00
Matthew William Jibson
f83a47cbb9 doc: various "the the" and other typos
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/6355076
2012-07-08 11:57:04 +10:00
Rémy Oudompheng
1a0a09dafe math/rand: avoid use of math.Pow in tests.
The use of math.Pow for mere squaring can be extremely
slow on soft-float ARM. Even on systems with hardware
floating-point, a speedup in test duration is observed.

On amd64
Before: ok      math/rand       2.009s
After:  ok      math/rand       0.340s

Fixes #3740.

R=dave, golang-dev, r, r
CC=golang-dev
https://golang.org/cl/6348061
2012-07-04 00:38:01 +02:00
David G. Andersen
917f764382 math/big: Remove unnecessary test from nat.go multiplication
The switch at the beginning of the function already ensures n > 1,
so testing for n < 2 is redundant.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/6350051
2012-07-02 15:30:00 -07:00
Charles L. Dorian
35c3afdb62 math: improve Atan, Asin and Acos accuracy
pkg/math/all_test.go tests Atan (and therefore Asin and Acos) to a
relative accuracy of 4e-16, but the test vector misses values where
the old algorithm was in error by more than that. For example:

x            newError   oldError
0.414215746  1.41e-16  -4.24e-16
0.414216076  1.41e-16  -4.24e-16
0.414217632  1.41e-16  -4.24e-16
0.414218770  1.41e-16  -4.24e-16
0.414225466  0         -5.65e-16
0.414226244  1.41e-16  -4.24e-16
0.414228756  0         -5.65e-16
0.414235089  0         -5.65e-16
0.414237070  0         -5.65e-16

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/6302093
2012-06-24 19:39:07 -04:00
Robert Griesemer
10b88888f6 math/big: correctly test for positive inputs in Int.GCD
Also: better GCD tests.

R=rsc
CC=golang-dev
https://golang.org/cl/6295076
2012-06-13 13:54:36 -07:00
Robert Griesemer
f4240666be math/big: fix binaryGCD
R=rsc
CC=golang-dev
https://golang.org/cl/6297085
2012-06-13 10:29:06 -07:00
Robert Griesemer
b7c5e23df0 math/big: various cleanups
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/6295072
2012-06-13 09:37:47 -07:00
Christopher Swenson
38735b957c math/big: Implemented binary GCD algorithm
benchmark                    old ns/op    new ns/op    delta
BenchmarkGCD10x10                 4383         2126  -51.49%
BenchmarkGCD10x100                5612         2124  -62.15%
BenchmarkGCD10x1000               8843         2622  -70.35%
BenchmarkGCD10x10000             17025         6576  -61.37%
BenchmarkGCD10x100000           118985        48130  -59.55%
BenchmarkGCD100x100              45328        11683  -74.23%
BenchmarkGCD100x1000             50141        12678  -74.72%
BenchmarkGCD100x10000           110314        26719  -75.78%
BenchmarkGCD100x100000          630000       156041  -75.23%
BenchmarkGCD1000x1000           654809       137973  -78.93%
BenchmarkGCD1000x10000          985683       159951  -83.77%
BenchmarkGCD1000x100000        4920792       366399  -92.55%
BenchmarkGCD10000x10000       16848950      3732062  -77.85%
BenchmarkGCD10000x100000      55401500      4675876  -91.56%
BenchmarkGCD100000x100000   1126775000    258951800  -77.02%

R=gri, rsc, bradfitz, remyoudompheng, mtj
CC=golang-dev
https://golang.org/cl/6305065
2012-06-13 09:31:20 -07:00
Robert Griesemer
008c62b2cd math/big: optimize common case of Int.Bit(0)
R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/6306069
2012-06-12 09:36:35 -07:00
Robert Griesemer
014d036d84 math/big: added nat.trailingZeroBits, simplified some code
Will simplify implementation of binaryGCD.

R=rsc, cswenson
CC=golang-dev
https://golang.org/cl/6299064
2012-06-08 13:00:49 -07:00
Robert Griesemer
cc1890cbe3 math/big: improved karatsuba calibration code, better mul benchmark
An attempt to profit from CL 6176043 (fix to superpolinomial
runtime of karatsuba multiplication) and determine a better
karatsuba threshold. The result indicates that 32 is still
a reasonable value. Left the threshold as is (== 32), but
made some minor changes to the calibrate code which are
worthwhile saving (use of existing benchmarking code for
better results, better use of package time).

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6260062
2012-06-04 09:48:27 -07:00
Shenghou Ma
d186d07eda cmd/5a, cmd/5l, math: add CLZ instruction for ARM
Supported in ARMv5 and above.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6284043
2012-06-03 03:08:49 +08:00
Charles L. Dorian
322057cbfc math: amd64 versions of Ceil, Floor and Trunc
Ceil  to 4.81 from 20.6 ns/op
Floor to 4.37 from 13.5 ns/op
Trunc to 3.97 from 14.3 ns/op
Also changed three MOVSDs to MOVAPDs in log_amd64.s

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/6262048
2012-06-02 13:06:12 -04:00
Robert Griesemer
07612b8db0 math/big: make Rat.Denom() always return a reference
The documentation says so, but in the case of a normalized
integral Rat, the denominator was a new value. Changed the
internal representation to use an Int to represent the
denominator (with the sign ignored), so a reference to it
can always be returned.

Clarified documentation and added test cases.

Fixes #3521.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6237045
2012-05-24 10:49:38 -07:00
Robert Griesemer
13a59b8c6d math/big: implement JSON un/marshaling support for Ints
Also: simplified some existing tests.

No support for Rats for now because the precision-preserving
default notation (fractions of the form a/b) is not a valid
JSON value.

Fixes #3657.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/6211079
2012-05-22 17:20:37 -07:00
Rémy Oudompheng
018c60bd8f math/big: fix superpolynomial complexity in Karatsuba algorithm.
benchmark                     old ns/op    new ns/op    delta
BenchmarkExp3Power0x10              732          734   +0.27%
BenchmarkExp3Power0x40              834          836   +0.24%
BenchmarkExp3Power0x100            1600         1579   -1.31%
BenchmarkExp3Power0x400            3478         3417   -1.75%
BenchmarkExp3Power0x1000          19388        19229   -0.82%
BenchmarkExp3Power0x4000         160274       156881   -2.12%
BenchmarkExp3Power0x10000       1552050      1372058  -11.60%
BenchmarkExp3Power0x40000      27328710     15216920  -44.32%
BenchmarkExp3Power0x100000    612349000    131407100  -78.54%
BenchmarkExp3Power0x400000  44073524000   1122195000  -97.45%

R=golang-dev, mtj, gri, rsc
CC=golang-dev, remy
https://golang.org/cl/6176043
2012-05-04 19:05:26 +02:00
Shenghou Ma
e7e7b1c55c math: ARM assembly implementation for Abs
Obtained on 700MHz OMAP4460:
benchmark       old ns/op    new ns/op    delta
BenchmarkAbs           61           23  -61.63%

R=dave, remyoudompheng, mtj, rsc
CC=golang-dev
https://golang.org/cl/6094047
2012-04-23 23:47:36 +08:00
Charles L. Dorian
f27348776f math: make function documentation more regular
R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5994043
2012-04-06 14:01:12 -04:00
Charles L. Dorian
5496e94187 math: update Gamma special cases
Match new C99 values for special cases.

Fixes #2977.

R=rsc, golang-dev
CC=golang-dev
https://golang.org/cl/5972058
2012-04-04 09:45:22 -04:00
Robert Griesemer
d724631a53 all: various typos
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5820045
2012-03-13 17:29:07 -07:00
Robert Griesemer
28e0e18863 math: slightly more readable comments
Replaced /*-style comments with line comments;
there are two many *'s already in those lines.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5699051
2012-02-23 10:17:24 -08:00
Russ Cox
0e70f2722b all: shorten some of the longer tests
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5675092
2012-02-18 16:24:23 -05:00
Rob Pike
7d1c5328ed math/rand: Intn etc. should panic if their argument is <= 0.
I am making a unilateral decision here. I could also settle for returning 0,
as long it's documented, but I argue that it's equivalent to an index
out of bounds.

Fixes #2892.

R=golang-dev, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5676079
2012-02-18 08:53:03 +11:00
Andrew Gerrand
11e113db57 godoc: make example code more readable with new comment convention
go/doc: move Examples to go/ast
cmd/go: use go/doc to read examples
src/pkg: update examples to use new convention

This is to make whole file examples more readable. When presented as a
complete function, preceding an Example with its output is confusing.
The new convention is to put the expected output in the final comment
of the example, preceded by the string "output:" (case insensitive).

An idiomatic example looks like this:

// This example demonstrates Foo by doing bar and quux.
func ExampleFoo() {
        // example body that does bar and quux

        // Output:
        // example output
}

R=rsc, gri
CC=golang-dev
https://golang.org/cl/5673053
2012-02-16 11:50:28 +11:00
Shenghou Ma
9a4487458a all: update 'gotest' to 'go test'
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5645099
2012-02-13 13:58:17 -05:00
Rob Pike
13443ccc2a math: fix gamma doc, link to OEIS
Fixes #2940.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5645078
2012-02-10 15:56:51 +11:00
Robert Griesemer
d0607221fa math/big: more accurate package comment
Fix some receiver names for consistency.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5624043
2012-02-03 10:17:19 -08:00
Robert Griesemer
b80c7e5dfd math/big: API, documentation cleanup
Fixes #2863.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5620058
2012-02-02 19:21:55 -08:00
Robert Griesemer
25787acb3c math/big: document Word type
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5615050
2012-02-02 14:43:55 -08:00
Robert Griesemer
71c19b610f mat/big: add raw access to Int bits
This is a minimal API extension, it makes it possible
to implement missing Int functionality externally w/o
compromising efficiency. It is the hope that this will
reduce the number of feature requests going directly
into the big package.

Also: Fixed some naming inconsistencies: The receiver
is only called z when it is also the result.

R=golang-dev, agl
CC=golang-dev
https://golang.org/cl/5607055
2012-02-01 11:43:40 -08:00
Luuk van Dijk
8dd3de4d4b pkg/math: undo manual inlining of IsInf and IsNaN
R=rsc
CC=golang-dev
https://golang.org/cl/5484076
2012-02-01 16:08:31 +01:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
Consequently, remove many package Makefiles,
and shorten the few that remain.

gomake becomes 'go tool make'.

Turn off test phases of run.bash that do not work,
flagged with $BROKEN.  Future CLs will restore these,
but this seemed like a big enough CL already.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
2012-01-30 23:43:46 -05:00
Robert Griesemer
8a90a8861f math/big: test both bitLen and bitLen_g
Also: simpler, more direct test.

R=golang-dev, dave.andersen
CC=golang-dev
https://golang.org/cl/5573070
2012-01-26 10:08:21 -08:00
David G. Andersen
1e09031f7f math/big: return type of bitLen is an int; use MOVL on amd64.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5577050
2012-01-25 16:09:12 -08:00
David G. Andersen
316f81bb1d math/big: assembly versions of bitLen for x86-64, 386, and ARM.
Roughly 2x speedup for the internal bitLen function in arith.go.  Added TestWordBitLen test.

Performance differences against the new version of
bitLen generic:

x86-64 Macbook pro (current tip):

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0             6            4  -37.40%
big.BenchmarkBitLen1             6            2  -51.79%
big.BenchmarkBitLen2             6            2  -65.04%
big.BenchmarkBitLen3             6            2  -66.10%
big.BenchmarkBitLen4             6            2  -60.96%
big.BenchmarkBitLen5             6            2  -55.80%
big.BenchmarkBitLen8             6            2  -56.19%
big.BenchmarkBitLen9             6            2  -64.73%
big.BenchmarkBitLen16            7            2  -68.84%
big.BenchmarkBitLen17            6            2  -67.11%
big.BenchmarkBitLen31            7            2  -61.57%

386 Intel Atom (current tip):
benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            23           20  -13.04%
big.BenchmarkBitLen1            23           20  -14.77%
big.BenchmarkBitLen2            24           20  -19.28%
big.BenchmarkBitLen3            25           20  -21.57%
big.BenchmarkBitLen4            24           20  -16.94%
big.BenchmarkBitLen5            25           20  -20.78%
big.BenchmarkBitLen8            24           20  -19.28%
big.BenchmarkBitLen9            25           20  -20.47%
big.BenchmarkBitLen16           26           20  -23.37%
big.BenchmarkBitLen17           26           20  -25.09%
big.BenchmarkBitLen31           32           20  -35.51%

ARM v5 SheevaPlug, previous weekly patched with bitLen:
benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            50           29  -41.73%
big.BenchmarkBitLen1            51           29  -42.75%
big.BenchmarkBitLen2            59           29  -50.08%
big.BenchmarkBitLen3            60           29  -50.75%
big.BenchmarkBitLen4            59           29  -50.08%
big.BenchmarkBitLen5            60           29  -50.75%
big.BenchmarkBitLen8            59           29  -50.08%
big.BenchmarkBitLen9            60           29  -50.75%
big.BenchmarkBitLen16           69           29  -57.35%
big.BenchmarkBitLen17           70           29  -57.89%
big.BenchmarkBitLen31           95           29  -69.07%

R=golang-dev, minux.ma, gri
CC=golang-dev
https://golang.org/cl/5574054
2012-01-25 15:04:16 -08:00
Andrew Gerrand
ddd67f2ecd math/big: add examples for Rat and Int's SetString and Scan methods
R=golang-dev, bradfitz, rsc, r, gri, r
CC=golang-dev
https://golang.org/cl/5543047
2012-01-25 10:29:44 +11:00
David G. Andersen
1dc37bbf46 math/big: slight improvement to algorithm used for internal bitLen function
The bitLen function currently shifts out blocks of 8 bits at a time.
This change replaces this sorta-linear algorithm with a log(N)
one (shift out 16 bits, then 8, then 4, then 2, then 1).
I left the start of it linear at 16 bits at a time so that
the function continues to work with 32 or 64 bit values
without any funkiness.
The algorithm is similar to several of the nlz ("number of
leading zeros") algorithms from "Hacker's Delight" or the
"bit twiddling hacks" pages.

Doesn't make a big difference to the existing benchmarks, but
I'm using the code in a different context that calls bitLen
much more often, so it seemed worthwhile making the existing
codebase faster so that it's a better building block.

Microbenchmark results on a 64-bit Macbook Pro using 6g from weekly.2012-01-20:

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0             4            6  +50.12%
big.BenchmarkBitLen1             4            6  +33.91%
big.BenchmarkBitLen2             6            6   +3.05%
big.BenchmarkBitLen3             7            6  -19.05%
big.BenchmarkBitLen4             9            6  -30.19%
big.BenchmarkBitLen5            11            6  -42.23%
big.BenchmarkBitLen8            16            6  -61.78%
big.BenchmarkBitLen9             5            6  +18.29%
big.BenchmarkBitLen16           18            7  -60.99%
big.BenchmarkBitLen17            7            6   -4.64%
big.BenchmarkBitLen31           19            7  -62.49%

On an ARM machine (with the previous weekly):

benchmark                old ns/op    new ns/op    delta
big.BenchmarkBitLen0            37           50  +36.56%
big.BenchmarkBitLen1            59           51  -13.69%
big.BenchmarkBitLen2            74           59  -20.40%
big.BenchmarkBitLen3            92           60  -34.89%
big.BenchmarkBitLen4           110           59  -46.09%
big.BenchmarkBitLen5           127           60  -52.68%
big.BenchmarkBitLen8           181           59  -67.24%
big.BenchmarkBitLen9            78           60  -23.05%
big.BenchmarkBitLen16          199           69  -65.13%
big.BenchmarkBitLen17           91           70  -23.17%
big.BenchmarkBitLen31          210           95  -54.43%

R=golang-dev, dave, edsrzf, gri
CC=golang-dev
https://golang.org/cl/5570044
2012-01-23 13:46:28 -08:00
Dmitriy Vyukov
f2f0059307 math/rand: decrease test duration in short mode
TestNonStandardNormalValues runs 1.5s,
the change reduces it to 0.2s in short mode.
The problem is with slow machines, emulators and dynamic tools.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5540065
2012-01-19 16:17:44 +04:00
Scott Lawrence
5163e7aa27 math/rand: document default initial seed for global generator
Fixes #2044.

R=golang-dev
CC=golang-dev
https://golang.org/cl/5541056
2012-01-16 18:13:34 -05:00
Shenghou Ma
4cfa9e3c61 doc: fix comments referring to removed API funcs
The strconv package has removed Atob, AtoF{64,32} and Ftoa.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5540057
2012-01-14 10:59:45 -08:00
Robert Griesemer
b4be65bc7f math/big: simplify fast string conversion
- use slice ops for convertWords instead of lo/hi boundaries
- always compute leading zeroes (simplifies logic significantly),
  but remove them once, at the end (since leafSize is small, the
  worst-case scenario is not adding significant overhead)
- various comment cleanups (specifically, replaced direct -> iterative,
  and indirect -> recursive)
- slightly faster overall for -bench=String

(This CL incorporates the changes re: my comments to CL 5418047
https://golang.org/cl/5418047/ )

benchmark                          old ns/op    new ns/op    delta
big.BenchmarkString10Base2               519          527   +1.54%
big.BenchmarkString100Base2             2279         2158   -5.31%
big.BenchmarkString1000Base2           18475        17323   -6.24%
big.BenchmarkString10000Base2         178248       166219   -6.75%
big.BenchmarkString100000Base2       1548494      1431587   -7.55%
big.BenchmarkString10Base8               415          422   +1.69%
big.BenchmarkString100Base8             1025          978   -4.59%
big.BenchmarkString1000Base8            6822         6428   -5.78%
big.BenchmarkString10000Base8          64598        61065   -5.47%
big.BenchmarkString100000Base8        593788       549150   -7.52%
big.BenchmarkString10Base10              654          645   -1.38%
big.BenchmarkString100Base10            1863         1835   -1.50%
big.BenchmarkString1000Base10          12099        11981   -0.98%
big.BenchmarkString10000Base10         57601        56888   -1.24%
big.BenchmarkString100000Base10     20123120     19827890   -1.47%
big.BenchmarkString10Base16              358          362   +1.12%
big.BenchmarkString100Base16             815          776   -4.79%
big.BenchmarkString1000Base16           4710         4421   -6.14%
big.BenchmarkString10000Base16         43938        40968   -6.76%
big.BenchmarkString100000Base16       406307       373930   -7.97%

R=michael.jones, mtj
CC=golang-dev
https://golang.org/cl/5432090
2012-01-09 11:20:09 -08:00
Charles L. Dorian
149d3f06d8 math: fix typo in all_test.go
Logb errors were reported as Ilogb errors.

R=rsc, golang-dev, gri
CC=golang-dev
https://golang.org/cl/5517045
2012-01-05 11:04:14 -08:00
Robert Griesemer
fc78c5aa00 math/big: Rand shouldn't hang if argument is also receiver.
Fixes #2607.

R=rsc
CC=golang-dev
https://golang.org/cl/5489109
2011-12-22 14:15:41 -08:00
Rob Pike
6b772462e4 panics: use the new facilities of testing.B instead
Lots of panics go away.
Also fix a name error in html/template.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5498045
2011-12-20 10:36:25 -08:00
Robert Griesemer
541b67d051 go/printer, gofmt: fine tuning of line spacing
- no empty lines inside empty structs and interfaces
- top-level declarations are separated by a blank line if
  a) they are of different kind (e.g. const vs type); or
  b) there are documentation comments associated with a
     declaration (this is new)
- applied gofmt -w misc src

The actual changes are in go/printer/nodes.go:397-400 (empty structs/interfaces),
and go/printer/printer.go:307-309 (extra line break). The remaining
changes are cleanups w/o changing the existing functionality.

Fixes issue  2570.

R=rsc
CC=golang-dev
https://golang.org/cl/5493057
2011-12-16 15:43:06 -08:00