1
0
mirror of https://github.com/golang/go synced 2024-09-29 14:24:32 -06:00
Commit Graph

52685 Commits

Author SHA1 Message Date
Keith Randall
f566fe3910 runtime: make racereadrange ABIinternal
CL 266638 marked racewriterange (and some other race functions) as
ABIinternal but missed racereadrange.

arm64 and ppc64le (the other two register ABI platforms at the moment)
already have racereadrange marked as such.

The other two instrumented calls are to racefuncenter/racefuncexit.
Do you think they would need this treatment as well? arm64 already does,
but amd64 and ppc64le do not.

Fixes #51459

Change-Id: I3f54e1298433b6d67bfe18120d9f86205ff66a73
Reviewed-on: https://go-review.googlesource.com/c/go/+/393154
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-05-09 16:59:57 +00:00
Cherry Mui
9ae7dc3040 cmd/compile: fix If lowering on ARM64
On ARM64, an If block is lowered to (NZ cond yes no). This is
incorrect because cond is a boolean value and therefore only the
last byte is meaningful (same as AMD64, see ARM64Ops.go). But here
we are comparing a full register width with 0. Correct it by
comparing only the last bit.

Fixes #52788.

Change-Id: I2cacf9f3d2f45e149c361a290f511b2d4ed845c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/405114
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-05-09 16:02:28 +00:00
Meng Zhuo
53f13128a7 internal/abi, internal/buildcfg: enable regabi on riscv64 by default
This CL we turn regabi on by default.
Later CLs will clean up fallback code.

name                   old time/op    new time/op    delta
BinaryTree17              35.2s ± 2%     31.0s ± 1%  -11.87%  (p=0.008 n=5+5)
Fannkuch11                10.8s ± 1%     11.0s ± 1%   +1.73%  (p=0.008 n=5+5)
FmtFprintfEmpty           379ns ± 2%     389ns ± 4%     ~     (p=0.095 n=5+5)
FmtFprintfString          746ns ± 5%     693ns ± 2%   -7.10%  (p=0.008 n=5+5)
FmtFprintfInt             769ns ± 3%     744ns ± 2%   -3.23%  (p=0.032 n=5+5)
FmtFprintfIntInt         1.14µs ± 3%    1.09µs ± 4%   -4.51%  (p=0.032 n=5+5)
FmtFprintfPrefixedInt    5.04µs ± 0%    4.53µs ± 1%  -10.14%  (p=0.008 n=5+5)
FmtFprintfFloat          1.82µs ± 4%    1.67µs ± 4%   -8.12%  (p=0.008 n=5+5)
FmtManyArgs              3.92µs ± 3%    3.67µs ± 2%   -6.20%  (p=0.008 n=5+5)
GobDecode                 137ms ± 1%     132ms ± 1%   -4.13%  (p=0.008 n=5+5)
GobEncode                93.9ms ± 1%    89.3ms ± 2%   -4.84%  (p=0.008 n=5+5)
Gzip                      2.54s ± 1%     2.59s ± 1%   +1.95%  (p=0.008 n=5+5)
Gunzip                    1.39s ± 1%     1.35s ± 0%   -3.07%  (p=0.008 n=5+5)
HTTPClientServer          416µs ± 1%     397µs ± 0%   -4.39%  (p=0.016 n=5+4)
JSONEncode                202ms ± 1%     196ms ± 2%   -2.76%  (p=0.008 n=5+5)
JSONDecode                478ms ± 2%     435ms ± 4%   -8.97%  (p=0.008 n=5+5)
Mandelbrot200            44.1ms ± 0%    44.1ms ± 0%     ~     (p=0.151 n=5+5)
GoParse                  33.7ms ± 1%    31.5ms ± 1%   -6.55%  (p=0.008 n=5+5)
RegexpMatchEasy0_32       624ns ± 6%     548ns ± 6%  -12.08%  (p=0.008 n=5+5)
RegexpMatchEasy0_1K      4.49µs ± 1%    3.59µs ± 1%  -20.21%  (p=0.008 n=5+5)
RegexpMatchEasy1_32       654ns ± 4%     556ns ± 2%  -15.01%  (p=0.008 n=5+5)
RegexpMatchEasy1_1K      6.21µs ± 2%    4.96µs ± 3%  -20.22%  (p=0.008 n=5+5)
RegexpMatchMedium_32     9.78µs ± 5%    8.03µs ± 4%  -17.96%  (p=0.008 n=5+5)
RegexpMatchMedium_1K      280µs ± 4%     223µs ± 5%  -20.42%  (p=0.008 n=5+5)
RegexpMatchHard_32       17.0µs ± 3%    15.2µs ± 3%  -10.63%  (p=0.008 n=5+5)
RegexpMatchHard_1K        520µs ± 4%     485µs ± 6%   -6.76%  (p=0.008 n=5+5)
Revcomp                   35.2s ± 1%     35.2s ± 1%     ~     (p=0.690 n=5+5)
Template                  686ms ± 2%     610ms ± 3%  -11.09%  (p=0.008 n=5+5)
TimeParse                1.91µs ± 2%    1.78µs ± 1%   -6.86%  (p=0.008 n=5+5)
TimeFormat               3.04µs ± 2%    2.84µs ± 3%   -6.71%  (p=0.008 n=5+5)

name                   old speed      new speed      delta
GobDecode              5.59MB/s ± 1%  5.84MB/s ± 1%   +4.40%  (p=0.008 n=5+5)
GobEncode              8.17MB/s ± 1%  8.59MB/s ± 3%   +5.14%  (p=0.008 n=5+5)
Gzip                   7.65MB/s ± 1%  7.50MB/s ± 1%   -1.96%  (p=0.008 n=5+5)
Gunzip                 13.9MB/s ± 1%  14.4MB/s ± 0%   +3.16%  (p=0.008 n=5+5)
JSONEncode             9.63MB/s ± 1%  9.90MB/s ± 2%   +2.83%  (p=0.008 n=5+5)
JSONDecode             4.06MB/s ± 2%  4.46MB/s ± 4%   +9.90%  (p=0.008 n=5+5)
GoParse                1.72MB/s ± 1%  1.84MB/s ± 1%   +6.85%  (p=0.008 n=5+5)
RegexpMatchEasy0_32    51.4MB/s ± 6%  58.4MB/s ± 6%  +13.72%  (p=0.008 n=5+5)
RegexpMatchEasy0_1K     228MB/s ± 1%   286MB/s ± 1%  +25.32%  (p=0.008 n=5+5)
RegexpMatchEasy1_32    48.9MB/s ± 4%  57.5MB/s ± 2%  +17.63%  (p=0.008 n=5+5)
RegexpMatchEasy1_1K     165MB/s ± 2%   207MB/s ± 3%  +25.37%  (p=0.008 n=5+5)
RegexpMatchMedium_32   3.27MB/s ± 5%  3.99MB/s ± 5%  +21.87%  (p=0.008 n=5+5)
RegexpMatchMedium_1K   3.66MB/s ± 4%  4.60MB/s ± 5%  +25.61%  (p=0.008 n=5+5)
RegexpMatchHard_32     1.88MB/s ± 3%  2.10MB/s ± 3%  +12.03%  (p=0.008 n=5+5)
RegexpMatchHard_1K     1.97MB/s ± 4%  2.11MB/s ± 6%   +7.31%  (p=0.008 n=5+5)
Revcomp                7.23MB/s ± 1%  7.23MB/s ± 1%     ~     (p=0.810 n=5+5)
Template               2.83MB/s ± 2%  3.18MB/s ± 4%  +12.52%  (p=0.008 n=5+5)

Change-Id: Ie02aa5ebe60607dbb5007da0efae731c36e96399
Reviewed-on: https://go-review.googlesource.com/c/go/+/402374
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: mzh <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-09 15:37:44 +00:00
miller
5020397677 path/filepath: simplify EvalSymlinks for plan9
Plan 9 doesn't have symbolic links, so EvalSymlinks can be simplified
just to check validity of the path and call Clean. This saves a lot
of redundant file system activity.

Updates #50775

Change-Id: I84c24ef1d5e6e38fd19df2d37c72fbf883f0140d
Reviewed-on: https://go-review.googlesource.com/c/go/+/404954
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David du Colombier <0intro@gmail.com>
Reviewed-by: David du Colombier <0intro@gmail.com>
2022-05-09 14:44:54 +00:00
Than McIntosh
c4311a47a0 internal/cpu: revise test to make it work properly with -cover
Fix up a test to insure that it does the right thing when
"go test -cover" is in effect.

Fixes #52761.

Change-Id: I0c141181e2dcaefd592fb04813f812f2800511da
Reviewed-on: https://go-review.googlesource.com/c/go/+/404715
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-05-09 12:32:48 +00:00
Archana R
7ca1e2aa56 internal/bytealg: optimize index function for ppc64le/power9
Optimized index2to16 loop by unrolling the loop by 4.
Multiple benchmark tests show performance improvement on
POWER9. Similar improvements are seen on POWER10. Added
tests to ensure changes work fine.

name            old time/op   new time/op    delta
Index/10         18.3ns ± 0%    19.7ns ±25%     ~
Index/32         75.3ns ± 0%    69.2ns ± 0%   -8.22%
Index/4K         5.53µs ± 0%    3.69µs ± 0%  -33.20%
Index/4M         5.64ms ± 0%    3.75ms ± 0%  -33.55%
Index/64M        92.9ms ± 0%    61.6ms ± 0%  -33.69%
IndexHard2       1.41ms ± 0%    0.93ms ± 0%  -33.75%
CountHard2       1.41ms ± 0%    0.93ms ± 0%  -33.75%

Change-Id: If9331df6a141a4716724b8cb648d2b91bdf17e5f
Reviewed-on: https://go-review.googlesource.com/c/go/+/377016
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Archana Ravindar <aravind5@in.ibm.com>
2022-05-09 12:02:02 +00:00
Paul E. Murphy
c386269ed8 cmd/compile: schedule carry chain arithmetic disjointly
This results in a 1.7-2.4x improvement in native go crypto/elliptic
multiplication operations on PPC64, and similar improvements might
be possible on other architectures which use flags or similar to
represent the carry bit in SSA form.

If it is possible, schedule carry chains independently of each
other to avoid clobbering the carry flag. This is very expensive.

This is done by:

1. Identifying carry bit using, but not creating ops, and lowering
   their priority below all other ops which do not need to be
   placed at the top of a block. This effectively ensures only
   one carry chain will be placed at a time in most important
   cases (crypto/elliptic/internal/fiat contains most of them).

2. Raising the priority of carry bit generating ops to schedule
   later in a block to ensure they are placed as soon as they
   are ready.

Likewise, tuple ops which separate carrying ops are scored
similar to 2 above. This prevents unrelated ops from being
scheduled between carry-dependent operations. This occurs
when unrelated ops are ready to schedule alongside such
tuple ops. This reduces the chances a flag clobbering op
might be placed between two carry-dependent operations.

With PPC64 Add64/Sub64 lowering into SSA and this patch, the net
performance difference in crypto/elliptic benchmarks on P9/ppc64le
are:

name                                old time/op    new time/op    delta
ScalarBaseMult/P256                   46.3µs ± 0%    46.9µs ± 0%   +1.34%
ScalarBaseMult/P224                    356µs ± 0%     209µs ± 0%  -41.14%
ScalarBaseMult/P384                   1.20ms ± 0%    0.57ms ± 0%  -52.14%
ScalarBaseMult/P521                   3.38ms ± 0%    1.44ms ± 0%  -57.27%
ScalarMult/P256                        199µs ± 0%     199µs ± 0%   -0.17%
ScalarMult/P224                        357µs ± 0%     212µs ± 0%  -40.56%
ScalarMult/P384                       1.20ms ± 0%    0.58ms ± 0%  -51.86%
ScalarMult/P521                       3.37ms ± 0%    1.44ms ± 0%  -57.32%
MarshalUnmarshal/P256/Uncompressed    2.59µs ± 0%    2.52µs ± 0%   -2.63%
MarshalUnmarshal/P256/Compressed      2.58µs ± 0%    2.52µs ± 0%   -2.06%
MarshalUnmarshal/P224/Uncompressed    1.54µs ± 0%    1.40µs ± 0%   -9.42%
MarshalUnmarshal/P224/Compressed      1.54µs ± 0%    1.39µs ± 0%   -9.87%
MarshalUnmarshal/P384/Uncompressed    2.40µs ± 0%    1.80µs ± 0%  -24.93%
MarshalUnmarshal/P384/Compressed      2.35µs ± 0%    1.81µs ± 0%  -23.03%
MarshalUnmarshal/P521/Uncompressed    3.79µs ± 0%    2.58µs ± 0%  -31.81%
MarshalUnmarshal/P521/Compressed      3.80µs ± 0%    2.60µs ± 0%  -31.67%

Note, P256 uses an asm implementation, thus, little variation is expected.

Updates #40171

Change-Id: I810850e8ff429505424c92d6fe37f99aaa0c6e84
Reviewed-on: https://go-review.googlesource.com/c/go/+/393656
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
2022-05-08 20:12:35 +00:00
Wayne Zuo
1efe38750a cmd/compile: teach prove about and operation
For this code:
z &= 63
_ = x<<z | x>>(64-z)
Now can prove 'x<<z' in bound. In ppc64 lowering pass, it will not
produce an extra '(ANDconst <typ.Int64> [63] z)' causing
codegen/rotate.go failed. Just remove the type check in rewrite rules
as the workaround.

Removes 32 bounds checks during make.bat.

Fixes #52563.

Change-Id: I14ed2c093ff5638dfea7de9bc7649c0f756dd71a
Reviewed-on: https://go-review.googlesource.com/c/go/+/404315
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-08 20:10:06 +00:00
Robert Griesemer
3391517c0e cmd/compile: don't crash in size computation for invalid type
An invalid program may produce invalid types. If the program
calls unsafe.Sizeof on such a type, which is a compile-time
computation, the size-computation must be able to handle it.
Add the invalid type to the list of permissible basic types
and give it a size of 1 (word).

Fixes #52748.

Change-Id: I6c409628f9b77044758caf71cdcb199f9e77adea
Reviewed-on: https://go-review.googlesource.com/c/go/+/404894
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-08 17:29:15 +00:00
Jinzhu
1b86ef47de A+C: add Jinzhu Zhang
Change-Id: I655095874a90fc3e390df5609e68f0e48a042fea
GitHub-Last-Rev: 6d3199b4cf
GitHub-Pull-Request: golang/go#52759
Reviewed-on: https://go-review.googlesource.com/c/go/+/404814
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-08 17:28:26 +00:00
Ryan Leung
dd8d425fed all: fix some lint issues
Make some code more simple.

Change-Id: I801adf0dba5f6c515681345c732dbb907f945419
GitHub-Last-Rev: a505146bac
GitHub-Pull-Request: golang/go#49626
Reviewed-on: https://go-review.googlesource.com/c/go/+/364634
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-08 17:27:54 +00:00
Ian Lance Taylor
df57592276 archive/zip: permit zip files to have prefixes
A Java jar file is a zip file, but it can have a prefix that is a bash
script that unpacks the zip file. Most zip programs ignore such prefixes.
This CL changes the archive/zip package to do the same.

Fixes #10464
Fixes #51337

Change-Id: I976e9c64684644317bd21077bc5b4a2baf626ee6
Reviewed-on: https://go-review.googlesource.com/c/go/+/387976
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-08 17:26:10 +00:00
Jason7602
507a44dc22 sync: remove the redundant logic on sync.(*Pool).Put
When the procUnpin is placed after shared.pushHead, there is
no need for x as a flag to indicate the previous process.

This CL can make the logic clear, and at the same time reduce
a redundant judgment.

Change-Id: I34ec9ba4cb5b5dbdf13a8f158b90481fed248cf5
Reviewed-on: https://go-review.googlesource.com/c/go/+/360059
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-08 17:23:05 +00:00
rlanhellas
4c565a5561 time: return ENOENT instead of ERROR_PATH_NOT_FOUND in windows
When using windows some users got a weird error (File not found) when the timezone database is not found. It happens because some methods in the time package don't treat ERROR_PATH_NOT_FOUND and ENOTDIR. To solve it was added a conversion to ENOTENT error.

Fixes #50248

Change-Id: I11c84cf409e01eafb932aea43c7293c8218259b8
GitHub-Last-Rev: fe7fff90cb
GitHub-Pull-Request: golang/go#50906
Reviewed-on: https://go-review.googlesource.com/c/go/+/381957
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-08 17:19:07 +00:00
Patrick Pokatilo
0ad74fd1dc cmd/cgo: add line info for return statements
When calling a C function, line information will be
incorrect if the function call's closing parenthesis
is not on the same line as the last argument. We add
a comment with the line info for the return statement
to guide debuggers to the correct line.

Fixes #49839.

Change-Id: I8bc2ce35fec9cbcafbbe8536d5a79dc487eb24bb
GitHub-Last-Rev: 8b28646d2e
GitHub-Pull-Request: golang/go#49840
Reviewed-on: https://go-review.googlesource.com/c/go/+/367454
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-08 17:18:37 +00:00
Nathan VanBenschoten
831f116828 math/big: don't force second arg to Jacobi and Int.ModSqrt to escape
This CL updates big.Jacobi to avoid forcing its y argument to escape
to the heap. The argument was escaping because it was being passed
through an empty interface to fmt.Sprintf during an assertion failure.
As a result, callers of Jacobi and Int.ModSqrt (which calls Jacobi)
could not keep this value on the stack.

Noticed when working on https://github.com/cockroachdb/apd/pull/103.

Change-Id: I5db9ee2149bf13b921886929425861721b53b085
GitHub-Last-Rev: 3ee07b5dc3
GitHub-Pull-Request: golang/go#50527
Reviewed-on: https://go-review.googlesource.com/c/go/+/377014
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2022-05-08 17:15:30 +00:00
Heisenberg
b8d55a7604 compress/flate: cancel redundant operations
The assignment operation in the program seems to be redundant, the first judgment will continue to overwrite the previous value.
The subsequent slicing operation will cut all the values without frequency.

Change-Id: Id59fc36dd5bacfde881edaf0d9c1af5348286611
Reviewed-on: https://go-review.googlesource.com/c/go/+/244157
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joe Tsai <joetsai@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-05-08 17:05:16 +00:00
Keith Randall
eed77574d0 cmd/compile: trying to linkname a method is not an ICE, just an error
Fixes #52774

Change-Id: I853f462146d10e44a35e5a8716d41f32b6052fd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/404936
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@google.com>
2022-05-08 15:55:23 +00:00
Paul E. Murphy
a131fd1313 crypto/aes: enable asm block ciphers for ppc64
This does not enable GCM or CBC variants for ppc64, they
require more work to support bi-endian.

Updates #18499

Change-Id: Ic2bbe81c60107abc0a4803d8b9a833213286b1d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/404395
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
2022-05-07 10:56:06 +00:00
michael
130775cd16 net: improve error handling in dnsclient_unix.go
In the file net/dnsclient_unix.go in the function newRequest
error handling is missing after calling b.Finish(). If
the implementation of dnsmessage.Builder.Finish changes
it is theoretically possible that the missing error handling
introduces a nil pointer exception.

Fixes #50946

Change-Id: I3f0785f71def6649d6089d0af71c9e50f5ccb259
GitHub-Last-Rev: 2a2197f7e6
GitHub-Pull-Request: golang/go#50948
Reviewed-on: https://go-review.googlesource.com/c/go/+/381966
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-07 00:24:17 +00:00
Bryan C. Mills
4e79f06dac os/exec: refactor goroutine communication in Wait
This provides clearer synchronization invariants: if it occurs at all,
the call to c.Process.Kill always occurs before Wait returns. It also
allows any unexpected errors from the goroutine to be propagated back
to Wait.

For #50436.

Change-Id: I7ddadc73e6e67399596e35393f5845646f6111ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/401896
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-05-06 22:04:35 +00:00
tenkoh
d7a03da8ed cmd/go: mod tidy returns proper error with /tmp/go.mod
`go mod tidy` results in panic due to nil pointer dereference with the
current implementation. Though the panic occurs only in a limited situation
described as below, we had better fix it.

Situation:
- go.mod is in the exactly system's temporary directory (i.e. temp root)
- `go mod tidy` in temp root or in the child directory not having go.mod

No go.mod are found in the situation (i.e. *modFile is nil), however,
*modFile is referred without nil check.

Although just adding nil check works well, the better solution is using
ModFile() function. It works as same as the current implementation and,
in addition, it has either nil check and user friendly error indication.
With using it, users can get a proper error message like "go.mod file not
found in current directory or any parent directory" instead of a panic.

Fixes #51992

Change-Id: I2ba26762778acca6cd637c8eb8c615fb747063f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/400554
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-06 21:51:47 +00:00
Wayne Zuo
ac39dbdf58 cmd/compile: allow exporting .rcvr ident
Noder pass will build a closure to implement generic function
instantiation which may produce `.dict` and `.rcvr` ident.
Since we allow `.dict` during exporting, we should allow `.rcvr` too.

Fixes #52241.

Change-Id: Ifc3912ba5155b5ac1887f20830da64f4fb3fceb6
Reviewed-on: https://go-review.googlesource.com/c/go/+/404314
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-05-06 21:07:37 +00:00
Cherry Mui
12420f9c01 cmd/link: resolve relocations to .TOC. symbol
CL 404296 breaks the PPC64LE build because the .TOC. symbol is
visibility hidden and was skipped from the "unresolved symbol"
check (the check needs to be fix). In face, the .TOC. symbol is
special in that it doesn't have a type but we have special logic
to assign a value to it in the address pass. So we can actually
resolve a relocation to .TOC.. We already have a special case
for PIE. It also applies to non-PIE as well.

Fix PPC64LE builds.

Change-Id: Iaf7e36f10c4d0a40fc56b2135e5ff38815e203b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/404302
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 20:41:13 +00:00
David Taylor
a4af356075 crypto/tls: avoid extra allocations in steady-state Handshake calls
The Read and Write methods of *tls.Conn call Handshake
unconditionally, every time they are called, expecting it to only
perform a new handshake if required.

However in go 1.17 handshakeContext was extended to set up a
cancelable Context, and importantly did so prior to checking if a
handshake is required. This thus causes it to allocate on every call,
even in those that are no-ops when called in a Read or Write on an
established connection, sometimes leading to very large numbers of
allocations during reads.

This change adds an early return, prior to setting up the context or
proceeding into the handshakeMutex and checking the handshake error, if
the handshake status atomic indicates handshake is already complete.

name                                     old allocs/op  new allocs/op  delta
Throughput/MaxPacket/1MB/TLSv12-10          1.07k ± 0%     0.62k ± 0%  -42.16%  (p=0.000 n=4+5)
Throughput/MaxPacket/1MB/TLSv13-10          1.70k ± 0%     1.25k ± 0%     ~     (p=0.079 n=4+5)
Throughput/MaxPacket/2MB/TLSv12-10          1.62k ± 0%     0.73k ± 0%  -55.18%  (p=0.008 n=5+5)
Throughput/MaxPacket/2MB/TLSv13-10          2.26k ± 0%     1.36k ± 0%  -39.64%  (p=0.008 n=5+5)
Throughput/MaxPacket/4MB/TLSv12-10          2.74k ± 0%     0.95k ± 0%  -65.35%  (p=0.008 n=5+5)
Throughput/MaxPacket/4MB/TLSv13-10          3.37k ± 0%     1.58k ± 0%  -53.15%  (p=0.008 n=5+5)
Throughput/MaxPacket/8MB/TLSv12-10          4.96k ± 0%     1.39k ± 0%  -72.06%  (p=0.016 n=4+5)
Throughput/MaxPacket/8MB/TLSv13-10          5.60k ± 0%     2.01k ± 0%  -64.05%  (p=0.008 n=5+5)
Throughput/MaxPacket/16MB/TLSv12-10         9.42k ± 0%     2.27k ± 1%  -75.92%  (p=0.016 n=4+5)
Throughput/MaxPacket/16MB/TLSv13-10         10.0k ± 0%      2.9k ± 0%  -71.39%  (p=0.008 n=5+5)
Throughput/MaxPacket/32MB/TLSv12-10         18.3k ± 0%      4.0k ± 0%  -77.97%  (p=0.008 n=5+5)
Throughput/MaxPacket/32MB/TLSv13-10         18.9k ± 0%      4.6k ± 0%  -75.62%  (p=0.008 n=5+5)
Throughput/MaxPacket/64MB/TLSv12-10         36.2k ± 0%      7.5k ± 0%  -79.15%  (p=0.008 n=5+5)
Throughput/MaxPacket/64MB/TLSv13-10         36.7k ± 0%      8.1k ± 0%  -78.06%  (p=0.008 n=5+5)
Throughput/DynamicPacket/1MB/TLSv12-10      1.12k ± 0%     0.63k ± 0%  -44.20%  (p=0.008 n=5+5)
Throughput/DynamicPacket/1MB/TLSv13-10      1.76k ± 0%     1.26k ± 0%  -28.22%  (p=0.016 n=5+4)
Throughput/DynamicPacket/2MB/TLSv12-10      1.68k ± 0%     0.74k ± 0%  -56.11%  (p=0.008 n=5+5)
Throughput/DynamicPacket/2MB/TLSv13-10      2.32k ± 0%     1.37k ± 0%  -40.80%  (p=0.008 n=5+5)
Throughput/DynamicPacket/4MB/TLSv12-10      2.80k ± 0%     0.96k ± 0%  -65.81%  (p=0.008 n=5+5)
Throughput/DynamicPacket/4MB/TLSv13-10      3.43k ± 0%     1.59k ± 0%  -53.57%  (p=0.008 n=5+5)
Throughput/DynamicPacket/8MB/TLSv12-10      5.03k ± 0%     1.39k ± 0%  -72.27%  (p=0.008 n=5+5)
Throughput/DynamicPacket/8MB/TLSv13-10      5.66k ± 0%     2.02k ± 0%  -64.27%  (p=0.008 n=5+5)
Throughput/DynamicPacket/16MB/TLSv12-10     9.48k ± 0%     2.28k ± 1%  -75.98%  (p=0.008 n=5+5)
Throughput/DynamicPacket/16MB/TLSv13-10     10.1k ± 0%      2.9k ± 0%  -71.34%  (p=0.008 n=5+5)
Throughput/DynamicPacket/32MB/TLSv12-10     18.4k ± 0%      4.0k ± 0%  -78.13%  (p=0.008 n=5+5)
Throughput/DynamicPacket/32MB/TLSv13-10     19.0k ± 0%      4.6k ± 0%  -75.54%  (p=0.008 n=5+5)
Throughput/DynamicPacket/64MB/TLSv12-10     36.2k ± 0%      7.6k ± 1%  -79.02%  (p=0.008 n=5+5)
Throughput/DynamicPacket/64MB/TLSv13-10     36.8k ± 0%      8.2k ± 1%  -77.76%  (p=0.008 n=5+5)

Fixes #50657

Change-Id: Iacb1f9bf7802022960d9dbce141b8c0587a614d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/379034
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
2022-05-06 20:17:52 +00:00
Than McIntosh
054323d809 debug/pe: rework reading of aux symbols to fix endianity problems
This patch reworks CL 394534 to fix things so that reading auxiliary
symbol info works properly in a cross-endian mode (running
debug/pe-based tool on a big-endian system). The previous
implementation read in all symbol records using the primary symbol
format, then just used a pointer cast to convert to the auxiliary
format, which doesn't play well if host and target have different
endianness.

Fixes #52079.

Change-Id: I143d94d9313a265f11ca7befd254bdb150698834
Reviewed-on: https://go-review.googlesource.com/c/go/+/397485
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-06 18:07:48 +00:00
Paul E. Murphy
f495b36ccd crypto/aes: rewrite ppc64le block crypting
This unrolls the counter loop and simplifies the load/storing
of text/ciphertext and keys by using unaligned VSX memory
operations.

Performance delta on POWER9:

name     old time/op   new time/op    delta
Encrypt   19.9ns ± 0%    14.9ns ± 0%  -24.95%
Decrypt   19.8ns ± 0%    14.6ns ± 0%  -26.12%

Change-Id: Iba98d5c1d88c6bead45bc04c97ae64bcb6fc9f21
Reviewed-on: https://go-review.googlesource.com/c/go/+/404354
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:56:48 +00:00
Paul E. Murphy
9c9090eb1d cmd/link: generate PPC64 ABI register save/restore functions if needed
They are usually needed when internally linking gcc code
compiled with -Os. These are typically generated by ld
or gold, but are missing when linking internally.

The PPC64 ELF ABI describes a set of functions to save/restore
non-volatile, callee-save registers using R1/R0/R12:

 _savegpr0_n: Save Rn-R31 relative to R1, save LR (in R0), return
 _restgpr0_n: Restore Rn-R31 from R1, and return to saved LR
  _savefpr_n: Save Fn-F31 based on R1, and save LR (in R0), return
  _restfpr_n: Restore Fn-F31 from R1, and return to 16(R1)
 _savegpr1_n: Save Rn-R31 based on R12, return
 _restgpr1_n: Restore Rn-R31 based on R12, return
   _savevr_m: Save VRm-VR31 based on R0, R12 is scratch, return
   _restvr_m: Restore VRm-VR31 based on R0, R12 is scratch, return

 m is a value 20<=m<=31
 n is a value 14<=n<=31

Add several new functions similar to those suggested by the
PPC64 ELFv2 ABI. And update the linker to scan external relocs
for these calls, and redirect them to runtime.elf_<func>+offset
in runtime/asm_ppc64x.go.

Similarly, code which generates plt stubs is moved into
a dedicated function. This avoids an extra scan of relocs.

fixes #52336

Change-Id: I2f0f8b5b081a7b294dff5c92b4b1db8eba9a9400
Reviewed-on: https://go-review.googlesource.com/c/go/+/400796
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:56:28 +00:00
Paul E. Murphy
4a5711c3cf cmd/compile,cmd/asm: fix ppc64 usage of BI argument of BC opcode
Avoid coercing the CR bit into a GPR register type argument, and
move the existing usage to CRx_y register types. And, update the
compiler usage to this. This transformation is done internally,
so it should not alter existing assembly code.

Likewise, add assembly tests for all optab entries of BC/BR. This
found some cases which were not possible to realize with handwritten
asm, or assemble to something very unexpected if generated by the
compiler. The following optab entries are removed, and the cases
simplified or removed:

{as: ABR, a3: C_SCON, a6: C_LR, type_: 18, size: 4}

  This existed only to pass the BH hint to JMP (LR) from compiler
  generated code. It cannot be matched with asm. Instead, add and
  support 4-operand form "BC{,L} $BO, $BI, $BH, (LR)".

{as: ABR, a1: C_REG, a6: C_CTR, type_: 18, size: 4}

  Could be used like  "BR R1, (CTR)", but always compiles to bctr
  irrespective of arg 1. Any usage should be rewritten as "JMP (CTR)",
  or rewritten if this was not the intended behavior.

{as: ABR, a6: C_ZOREG, type_: 15, size: 8}:
{as: ABC, a6: C_ZOREG, type_: 15, size: 8},

  Not reachable: 0(reg) is coerced to reg in assembler frontend.

{as: ABC, a2: C_REG, a6: C_LR, type_: 18, size: 4}
{as: ABC, a2: C_REG, a6: C_CTR, type_: 18, size: 4}

  Only usable from the compiler. However, the compiler does not
  generate this form today. Without a BO operand (usually in a1), it
  is not clear what this should assemble to.

Change-Id: I1b5151f884a5877e4a610e6fd41261e8e64c5454
Reviewed-on: https://go-review.googlesource.com/c/go/+/357775
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-06 17:56:02 +00:00
Jason A. Donenfeld
091e913414 crypto/rand: fix race on r.used
This race is benign, but it still trips up the race detector, so turn
this into an atomic read.

Fixes #52739.

Change-Id: Ib53362286b456513c8c69d6d2d73c6c90ec095f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/404475
Auto-Submit: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
2022-05-06 17:41:30 +00:00
Cherry Mui
2049649e8b cmd/link: fix handling of visibility hidden symbols
There is a TODO comment that checking hidden visibility is
probably not the right thing to do. I think it is indeed not. Here
we are not referencing symbols across DSO boundaries, just within
an executable binary. The hidden visibility is for references from
another DSO. So it doesn't actually matter.

This makes cgo internal linking tests work on ARM64 with newer
GCC. It failed and was disabled due to a visibility hidden symbol
in libgcc.a that we didn't handle correctly. Specifically, the
problem is that we didn't mark visibility hidden symbol references
SXREF, which caused the loader to not think it is an unresolved
external symbol, which in turn made it not loading an object file
from the libgcc.a archive which contains the actual definition.
Later stage when we try to resolve the relocation, we couldn't
resolve it. Enable the test as it works now.

Fixes #39466.

Change-Id: I2759e3ae15e7a7a1ab9a820223b688ad894509ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/404296
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:37:38 +00:00
Ian Lance Taylor
280e640224 test: add test that crashed gofrontend
For #52535

Change-Id: I6798a8379163497ebebcdadf836b8569735c282b
Reviewed-on: https://go-review.googlesource.com/c/go/+/404496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-06 17:37:12 +00:00
Roland Shoemaker
0aee59736f crypto/x509: fix EKU nesting enforcement
The path building rework broke the enforcement of EKU nesting, this
change goes back to using the old method of enforcement, since it ends
up being more efficient to check the chains after building, rather than
at each step during path building.

Fixes #52659

Change-Id: Ic7c3717a10c33905677cf7bc4bc0a20f5f15f259
Reviewed-on: https://go-review.googlesource.com/c/go/+/403554
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
2022-05-06 17:05:06 +00:00
Robert Griesemer
5fcd1badf7 go/printer: fix printing for possibly ambiguous type constraints
This is a port of the printer changes from CLs 402256 and 404397
in the syntax package to go/printer, with adjustments for the
different AST structure and test framework.

For #52559.

Change-Id: Ib7165979a4bd9df91f7f0f1c23b756a41ca31eb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/404194
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-06 16:18:34 +00:00
Robert Griesemer
ea6c828455 cmd/compile/internal/syntax: fix printing of ambiguous constraint literals
Without this change, the type parameter list "[P T | T]" is printed
as "[P T | T,]" in an attempt to avoid an ambiguity. But the type
parameter P cannot syntactically combine with the constraint T | T
and make a new valid expression.

This change introduces a specific combinesWithName predicate that
reports whether a constraint expression can combine with a type
parameter name to form a new valid (value) expression.

Use combinesWithName to accurately determine when a comma is needed.

For #49482.

Change-Id: Id1d17a18f0c9af04495da7b0453e83798f32b04a
Reviewed-on: https://go-review.googlesource.com/c/go/+/404397
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-06 16:18:28 +00:00
Tobias Klauser
7f71e1fc28 runtime/cgo: remove memset in _cgo_sys_thread_start on linux
pthread_attr_init in glibc and musl libc already explicitly clear the
pthread_attr argument before setting it, see
https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_attr_init.c
and https://git.musl-libc.org/cgit/musl/log/src/thread/pthread_attr_init.c

It looks like pthread_attr_init has been implemented like this for a
long time in both libcs. The comment and memset in _cgo_sys_thread_start
probably stem from a time where not all libcs did the explicit memset in
pthread_attr_init.

Also, the memset in _cgo_sys_thread_start is not performed on all linux
platforms further indicating that this isn't an issue anymore.

Change-Id: I920148b5d24751195ced7af5bb7c52a7f8293259
Reviewed-on: https://go-review.googlesource.com/c/go/+/404275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-06 15:32:04 +00:00
Jorropo
119da6358b debug/buildinfo: avoid nil defererence for invalid XCOFF
I've made it return 0 following what the other DataStart implementation
do when they do not found the section.

Fixes #52718

Change-Id: I44292fed15bb21b9aba712ad15ed74e0ce231b5a
GitHub-Last-Rev: 081a35ebec
GitHub-Pull-Request: golang/go#52722
Reviewed-on: https://go-review.googlesource.com/c/go/+/404254
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-06 14:33:48 +00:00
zhangyunhao
f87e28d1b9 A: add ByteDance Ltd. (Corporate CLA)
Change-Id: Ia670d96ce4926c88d5d955d31dd89837b236a806
Reviewed-on: https://go-review.googlesource.com/c/go/+/403994
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: mzh <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 04:25:34 +00:00
Meng Zhuo
3ea3bc0e96 cmd/compile: update TestStmtLines threshold for riscv64
CL402374 default regabi for riscv64 but TestStmtLines
keep fail trybot within a tiny overlimit (2.006% > 2%).
This CL update this threshold to 3% for riscv64 as an
acceptable temporary solution.

Change-Id: I5c6f37099a76bc048998eb95f49944dbe55492f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/404195
Run-TryBot: mzh <mzh@golangcn.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-06 04:22:04 +00:00
Ian Lance Taylor
7dd9884562 sync/atomic: don't run 64-bit uintptr tests on 32-bit systems
The tests don't work on big-endian systems. This change handles more
of the tests added in CL 381317 like the other existing tests.

Fixes #52723

Change-Id: Ie9e048e75dbe0b5aca61b51cd0c50d7d878ff6d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/404495
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-06 02:40:50 +00:00
Lynn Boger
f99511d59b crypto/internal/nistec: re-enable ppc64le asm for P-256
Add support for ppc64le assembler to p256. Most of the changes
are due to the change in nistec interfaces.

There is a change to p256MovCond based on a reviewer's comment.

LXVD2X replaces the use of LXVW4X in one function.

In addition, some refactoring has been done to this file to
reduce size and improve readability:
- Eliminate the use of defines to switch between V and VSX
registers. V regs can be used for instructions some that
previously required VSX.
- Use XXPERMDI instead of VPERM to swap bytes loaded and
stored with LXVD2X and STXVD2X instructions. This eliminates
the need to load the byte swap string into a vector.
- Use VMRGEW and VMRGOW instead of VPERM in the VMULT
macros. This also avoids the need to load byte strings to
swap the high and low values.

These changes reduce the file by about 10% and shows an
improvement of about 2% at runtime.

For #52182

Change-Id: Ic48050fc81bb273b7b4023e54864f4255dcc2a4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/399755
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
2022-05-05 23:41:16 +00:00
Filippo Valsorda
86536b934a go/types,cmd/compile/internal/types2: fix TestStdlib
CL 402556 moved a special-cased package and broke the longtests.

Change-Id: I10b48e0912c1cee0eabc342ed1c1704ed79946bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/404474
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Auto-Submit: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 22:53:14 +00:00
Roland Shoemaker
bb1f441618 crypto/rand: properly handle large Read on windows
Use the batched reader to chunk large Read calls on windows to a max of
1 << 31 - 1 bytes. This prevents an infinite loop when trying to read
more than 1 << 32 -1 bytes, due to how RtlGenRandom works.

This change moves the batched function from rand_unix.go to rand.go,
since it is now needed for both windows and unix implementations.

Fixes #52561

Change-Id: Id98fc4b1427e5cb2132762a445b2aed646a37473
Reviewed-on: https://go-review.googlesource.com/c/go/+/402257
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 22:44:02 +00:00
Filippo Valsorda
7c74b0db8a crypto/ed25519/internal/edwards25519: move to crypto/internal/edwards25519
This will allow us to use crypto/internal/edwards25519/field from
crypto/ecdh to implement X25519, dropping the dependency on
golang.org/x/crypto/curve25519.

For #52182

Change-Id: I3be9debc6e13bf06944b98668f34313a975914d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/402556
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:53:10 +00:00
Filippo Valsorda
52de40120d crypto/elliptic/internal/nistec: move to crypto/internal/nistec
So it's reachable from crypto/ecdsa and the upcoming crypto/ecdh.

No code changes.

For #52182

Change-Id: Ie3216052f46c6ef7ec64d8b87a233a9c50c4b16a
Reviewed-on: https://go-review.googlesource.com/c/go/+/398674
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:53:03 +00:00
Filippo Valsorda
a218b3520a crypto/elliptic: panic when operating on invalid points
Fixes #50975
For #52182

Change-Id: I4a98d965436c7034877b8c0146bb0bd5b802d6fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/382995
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:52:55 +00:00
Filippo Valsorda
52e24b492d crypto/elliptic: implement UnmarshalCompressed in nistec
For #52182

Change-Id: If9eace36b757ada6cb5123cc60f1e10d4e8280c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/396935
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:52:46 +00:00
Filippo Valsorda
50b1add5a7 crypto/elliptic: precompute ScalarBaseMult doublings
name                    old time/op    new time/op    delta
pkg:crypto/ecdsa goos:darwin goarch:amd64
Sign/P224-16               250µs ± 2%      91µs ± 2%  -63.42%  (p=0.000 n=10+9)
Sign/P384-16               955µs ± 3%     311µs ± 2%  -67.48%  (p=0.000 n=10+10)
Sign/P521-16              2.74ms ± 2%    0.82ms ± 2%  -69.95%  (p=0.000 n=10+10)
Verify/P224-16             440µs ± 3%     282µs ± 5%  -35.94%  (p=0.000 n=9+10)
Verify/P384-16            1.72ms ± 2%    1.07ms ± 1%  -38.02%  (p=0.000 n=10+9)
Verify/P521-16            5.10ms ± 2%    3.18ms ± 3%  -37.70%  (p=0.000 n=10+10)
GenerateKey/P224-16        225µs ± 3%      67µs ± 4%  -70.42%  (p=0.000 n=9+10)
GenerateKey/P384-16        881µs ± 1%     241µs ± 2%  -72.67%  (p=0.000 n=10+10)
GenerateKey/P521-16       2.62ms ± 3%    0.69ms ± 3%  -73.78%  (p=0.000 n=10+9)
pkg:crypto/elliptic/internal/nistec goos:darwin goarch:amd64
ScalarMult/P224-16         219µs ± 4%     209µs ± 3%   -4.57%  (p=0.003 n=10+10)
ScalarMult/P384-16         838µs ± 2%     823µs ± 1%   -1.72%  (p=0.004 n=10+9)
ScalarMult/P521-16        2.48ms ± 2%    2.45ms ± 2%     ~     (p=0.052 n=10+10)
ScalarBaseMult/P224-16     214µs ± 4%      54µs ± 4%  -74.88%  (p=0.000 n=10+10)
ScalarBaseMult/P384-16     828µs ± 2%     196µs ± 3%  -76.38%  (p=0.000 n=10+10)
ScalarBaseMult/P521-16    2.50ms ± 3%    0.55ms ± 2%  -77.96%  (p=0.000 n=10+10)

Updates #52424
For #52182

Change-Id: I2be3c2b8cdeead512063ef489e43805f4ee71d0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/404174
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:34 +00:00
Filippo Valsorda
0b4f2416a2 crypto/elliptic: clean up and document P-256 assembly interface
For #52182

Change-Id: I8a68fda3e54bdea48b0dfe528fe293d47bdcd145
Reviewed-on: https://go-review.googlesource.com/c/go/+/396255
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:24 +00:00
Filippo Valsorda
10d1189464 crypto/elliptic: move P-256 amd64/arm64 assembly to nistec
The goal of this CL is to move the implementation to the new interface
with the least amount of changes possible. A follow-up CL will add
documentation and cleanup the assembly API.

  * SetBytes does the element and point validity checks now, which were
    previously implemented with big.Int.

  * p256BaseMult would return (0:0:1) if the scalar was zero, which is
    not a valid encoding of the point at infinity, but would get
    flattened into (0,0) by p256PointToAffine. The rest of the code can
    cope with any encoding with Z = 0, not just (t²:t³:0) with t != 0.

  * CombinedMult was only avoiding the big.Int and affine conversion
    overhead, which is now gone when operating entirely on nistec types,
    so it can be implemented entirely in the crypto/elliptic wrapper,
    and will automatically benefit all NIST curves.

  * Scalar multiplication can't operate on arbitrarily sized scalars (it
    was using big.Int to reduce them), which is fair enough. Changed the
    nistec point interface to let ScalarMult and ScalarBaseMult reject
    scalars. The crypto/elliptic wrapper still does the big.Int
    reduction as needed.

The ppc64le/s390x assembly is disabled but retained to make review of
the change that will re-enable it easier.

Very small performance changes, which we will more then recoup when
crypto/ecdsa moves to invoking nistec directly.

name                                  old time/op    new time/op    delta
pkg:crypto/elliptic goos:darwin goarch:arm64
ScalarBaseMult/P256-8                   11.3µs ± 0%    11.4µs ± 0%    +0.87%  (p=0.000 n=8+10)
ScalarMult/P256-8                       42.2µs ± 0%    42.2µs ± 0%      ~     (p=0.825 n=10+9)
MarshalUnmarshal/P256/Uncompressed-8     801ns ± 1%     334ns ± 0%   -58.29%  (p=0.000 n=9+10)
MarshalUnmarshal/P256/Compressed-8       798ns ± 0%     334ns ± 0%   -58.13%  (p=0.000 n=10+10)
pkg:crypto/ecdsa goos:darwin goarch:arm64
Sign/P256-8                             19.3µs ± 1%    19.4µs ± 0%    +0.81%  (p=0.003 n=8+9)
Verify/P256-8                           56.6µs ± 0%    56.3µs ± 1%    -0.48%  (p=0.003 n=7+10)
GenerateKey/P256-8                      11.9µs ± 0%    12.0µs ± 0%    +1.22%  (p=0.000 n=7+9)

For #52182

Change-Id: I0690a387e20018f38da55141c0d2659280b1a630
Reviewed-on: https://go-review.googlesource.com/c/go/+/395775
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:18 +00:00