aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
AgeCommit message (Collapse)Author
2025-07-19cmd/internal/obj: enable got pcrel itype in fips140 for riscv64Meng Zhuo
This CL enable R_RISCV_GOT_PCREL_ITYPE in fips140 Fixes #74662 Change-Id: Ic189c4e352517ae74034f207a5f944b610f2eb73 Reviewed-on: https://go-review.googlesource.com/c/go/+/688635 Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Julian Zhu <jz531210@gmail.com>
2025-07-16cmd/link, runtime: on Wasm, put only function index in method table and func ↵Cherry Mui
table In the type descriptor's method table, it contains relative PCs of the methods (relative to the start of the text section) stored as 32-bit offsets. On Wasm, a PC is PC_F<<16 + PC_B, where PC_F is the function index, and PC_B is the block index. When there are more than 65536 functions, the PC will not fit into 32-bit (and relative to the section start doesn't help). Since there are no more bits for the function index, and the method table always targets the entry of a method, we put just the PC_F there, and rewrite back to a full PC at run time when we need the PC. This way we can have more than 65536 functions. The func table also contains 32-bit relative PCs, and it also always points to function entries. Do the same there, as well as other places where we use relative text offsets. Also add the relocation type in the relocation overflow error message. Also add check for function too big on Wasm. If a function has more than 65536 blocks, PC_B will overflow and PC = PC_F<<16 + PC_B will points to the wrong function. Fixes #64856. Change-Id: If9c307e9fb1641f367a5f19c39f88f455805d0bb Reviewed-on: https://go-review.googlesource.com/c/go/+/552835 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-07-16cmd/internal/obj/wasm: use 64-bit instructions for indirect callsCherry Mui
Currently, on Wasm, an indirect call is compiled to // function index = PC>>16, PC is already on stack I32WrapI64 I32Const $16 ShrU // set PC_B to 0 ... // actual call CallIndirect Specifically, the function index is extracted from bits 16-31 of the "PC". When there are more than 65536 functions, this will overflow and wrap around, causing wrong function being called. This CL changes it to use 64-bit operations to extract the function index from the "PC", so there are enough bits to for it. For #64856. Change-Id: I83c11db4b78cf66250e88ac02a82bd13730a8914 Reviewed-on: https://go-review.googlesource.com/c/go/+/567896 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-07-15cmd/internal/doc: upgrade godoc pkgsite to 01b046eMichael Matloob
Increase the dependency on the doc tool to bring in the fixes to CL 687918 and CL 687976. Fixes golang/go#74459 Change-Id: I9cdefdfd9792a142ad14bae3d4f7bb9d8256a246 Reviewed-on: https://go-review.googlesource.com/c/go/+/687997 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-07-07cmd/internal/doc: fix GOROOT skew and path joining bugsMichael Matloob
Use the goCmd() function to get the go command to invoke, so that when GOROOT is set, the go command that's invoked uses the same GOROOT. Otherwise there will be skew between the go command and the tools and runtime. Also use the environment when determining GOPROXY and GOMODCACHE, and use url.Join so the slashes in 'http://' aren't collapsed into one. Change-Id: Ie36ca2fffdb015a7f5f9bd7f514850e41fad2c1a Reviewed-on: https://go-review.googlesource.com/c/go/+/685319 Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-06-29cmd/doc: fix -http on Windowsqmuntal
On Windows, GOMODCACHE almost never starts with a slash, and "go doc -http" constructs a GOPROXY URL by doing "file://" + GOMODCACHE, resulting in an invalid file URI. For example, if GOMODCACHE is "C:\foo", then the file URI should be "file:///C:/foo", but it becomes "file://C:/foo" instead, where "C:" is understood as a host name, not a drive letter. Fixes #74137. Change-Id: I23e776e0f649a0062e01d1a4a6ea8268ba467331 Reviewed-on: https://go-review.googlesource.com/c/go/+/684575 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-06-09cmd/internal/doc: increase version of pkgsite doc command that's runMichael Matloob
This will incorporate the changes in CL 675957, CL 677596, and CL 675958. For #73848 Change-Id: Ie3d313e055a36b5b7aafec4a7462a1ced8a9f923 Reviewed-on: https://go-review.googlesource.com/c/go/+/680176 Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-06-03cmd/doc: build cmd/doc directly into the go commandMichael Matloob
There are a couple of places where our tests expect that 'go doc' doesn't need to do a build. Invoke the cmd/doc code directly by the go command instead of starting the doc tool in a separate process so we can preserve that property. This change moves most of the doc code into the package cmd/internal/doc, and exposes a Main function from that function that's called both by the cmd/doc package, and by go doc. This change makes couple of additional changes to intergrate doc into the go command: The counter.Open call and the increment of invocations counter are only needed by cmd/doc. The go command will open the counters file and increment a counter for the doc subcommand. We add a cmd_go_bootstrap tagged variant of the file that defines go doc so that we don't end up linking net into the bootstrap version of the go command. We don't need doc in that version of the command. We create a new flagSet rather than using flag.CommandLine because when running as part of the go command, the flags to "go doc" won't be the top level flags. We change TestGoListTest in go_test.go to use gofmt instead of doc as an example of a main package in cmd with an in-package test. For #71867 Change-Id: I3e3df83e5fa266559606fdc086b461165e09f037 Reviewed-on: https://go-review.googlesource.com/c/go/+/677775 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Matloob <matloob@google.com>
2025-05-29cmd/internal/obj/s390x: fix potential recursive String callMichael Anthony Knyszek
This String method can potentially recurse infinitely, since %#x will apparently call String if the method exists. This isn't well documented, but cmd/vet will be updated soon to check this (when we update the vendored x/tools dependency) so cut off the recursion by converting to the underlying type first. Change-Id: Ia6fc046c9eb56a5dd6a33772afd23da443a06116 Reviewed-on: https://go-review.googlesource.com/c/go/+/677261 Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-21testing: add AttrDamien Neil
Add a new Attr method to testing.TB that emits a test attribute. An attribute is an arbitrary key/value pair. Fixes #43936 Change-Id: I7ef299efae41f2cf39f2dc61ad4cdd4c3975cdb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/662437 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-05-21internal/runtime/cgroup: add line-by-line reader using a single scratch bufferMichael Pratt
Change-Id: I6a6a636ca21edcc6f16705fbb72a5241d4f7f22d Reviewed-on: https://go-review.googlesource.com/c/go/+/668637 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-21cmd/internal/obj/loong64: remove unused register alias definitionsGuoqi Chen
Change-Id: Ie788747372cd47cb3780e75b35750bb08bd166fc Reviewed-on: https://go-review.googlesource.com/c/go/+/542835 Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> Auto-Submit: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-21cmd/internal/obj/riscv: fix vector integer multiply addMark Ryan
The RISC-V integer vector multiply add instructions are not encoded correctly; the first and second arguments are swapped. For example, the instruction VMACCVV V1, V2, V3 encodes to b620a1d7 or vmacc.vv v3,v1,v2 and not b61121d7 or vmacc.vv v3,v2,v1 as expected. This is inconsistent with the argument ordering we use for 3 argument vector instructions, in which the argument order, as given in the RISC-V specifications, is reversed, and also with the vector FMA instructions which have the same argument ordering as the vector integer multiply add instructions in the "The RISC-V Instruction Set Manual Volume I". For example, in the ISA manual we have the following instruction definitions ; Integer multiply-add, overwrite addend vmacc.vv vd, vs1, vs2, vm # vd[i] = +(vs1[i] * vs2[i]) + vd[i] ; FP multiply-accumulate, overwrites addend vfmacc.vv vd, vs1, vs2, vm # vd[i] = +(vs1[i] * vs2[i]) + vd[i] It's reasonable to expect that the Go assembler would use the same argument ordering for both of these instructions. It currently does not. We fix the issue by switching the argument ordering for the vector integer multiply add instructions to match those of the vector FMA instructions. Change-Id: Ib98e9999617f991969e5c831734b3bb3324439f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/670335 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-05-20cmd/internal/testdir: filter out errors outside input file setJake Bailey
When an errorcheck test uses -m and instantiates an imported generic function, the errors will include -m messages from the imported package (since the new function has not previously been walked). These errors cannot be matched since we can't write errors in files outside the test input. To fix this (and enable the other CLs in this stack), drop any unmatched errors that occur in files outside those in the input set. Change-Id: I2fcf0dd4693125d2e5823ea4437011730d8b1b1f Reviewed-on: https://go-review.googlesource.com/c/go/+/672515 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2025-05-19runtime: move atoi to internal/runtime/strconvMichael Pratt
Moving to a smaller package allows its use in other internal/runtime packages. This isn't internal/strconvlite since it can't be used directly by strconv. For #73193. Change-Id: I6a6a636c9c8b3f06b5fd6c07fe9dd5a7a37d1429 Reviewed-on: https://go-review.googlesource.com/c/go/+/672697 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2025-05-15cmd/internal/obj/loong64: change the plan9 format of the prefetch ↵Guoqi Chen
instruction PRELDX before: MOVV $n + $offset, Roff PRELDX (Rbase)(Roff), $hint after: PRELDX offset(Rbase), $n, $hint This instruction is supported in CL 671875, but is not actually used Change-Id: I943d488ea6dc77781cd796ef480a89fede666bab Reviewed-on: https://go-review.googlesource.com/c/go/+/673155 Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-05-14cmd/internal/script: fix copying directory when symlink failsIan Alexander
The change fixes `linkOrCopy` to work on systems wihtout symlinks, when copying directories. This was originally noticed on Windows systems when the user did not have admin privs. Fixes #73692 Change-Id: I8ca66d65e99433ad38e70314abfabafd43794b79 Reviewed-on: https://go-review.googlesource.com/c/go/+/672275 Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-14cmd/intarnal/obj: add new assembly format for VANDV and VANDB on loong64Xiaolin Zhao
In order to make it easier to write in assembly and to be consistent with the usage of general instructions, a new assembly format is added for the instructions VANDV and VANDB. It also works for instructions XVAND{V,B}, [X]V{OR,XOR,NOR,ANDN,ORN}V and [X]V{OR,XOR,NOR}B. Change-Id: Ia75d607ac918950e58840ec627aaf0be45d837fe Reviewed-on: https://go-review.googlesource.com/c/go/+/671316 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-12cmd/internal/obj/loong64: Add preld{,x} instructions supportGuoqi Chen
Go asm syntax: PRELD 16(R4), $8 PRELDX (R4)(R5), $8 Equivalent platform assembler syntax: preld $8, $r4, 16 preldx $8, $r4, $r5 Change-Id: Ie81d22ebaf4153388a7e9d8fa0f618a0ae7a1c9f Reviewed-on: https://go-review.googlesource.com/c/go/+/671875 Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn> Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-11cmd/internal/obj/loong64: add [X]VFCLASS.{S/D} instructionsXiaolin Zhao
Go asm syntax: VFCLASS{F/D} VJ, VD XVFCLASS{F/D} XJ, XD Equivalent platform assembler syntax: vfclass.{s/d} vd, vj xvfclass.{s/d} xd, xj Change-Id: Iec373f393be315696d1fefc747a4a5882f993195 Reviewed-on: https://go-review.googlesource.com/c/go/+/670256 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dustin Turner <dustin.turner44@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: abner chenc <chenguoqi@loongson.cn>
2025-05-08cmd/internal/obj/loong64: add [X]VF{ADD/SUB/MUL/DIV}.{S/D} instructionsXiaolin Zhao
Go asm syntax: V{ADD/SUB/MUL/DIV}{F/D} VK, VJ, VD XV{ADD/SUB/MUL/DIV}{F/D} XK, XJ, XD Equivalent platform assembler syntax: vf{add/sub/mul/div}.{s/d} vd, vj, vk xvf{add/sub/mul/div}.{s/d} xd, xj, xk Change-Id: I4607884212167ac97d7b6448ea3c849fc0fdd506 Reviewed-on: https://go-review.googlesource.com/c/go/+/670255 Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-05-08runtime: schedule cleanups across multiple goroutinesMichael Anthony Knyszek
This change splits the finalizer and cleanup queues and implements a new lock-free blocking queue for cleanups. The basic design is as follows: The cleanup queue is organized in fixed-sized blocks. Individual cleanup functions are queued, but only whole blocks are dequeued. Enqueuing cleanups places them in P-local cleanup blocks. These are flushed to the full list as they get full. Cleanups can only be enqueued by an active sweeper. Dequeuing cleanups always dequeues entire blocks from the full list. Cleanup blocks can be dequeued and executed at any time. The very last active sweeper in the sweep phase is responsible for flushing all local cleanup blocks to the full list. It can do this without any synchronization because the next GC can't start yet, so we can be very certain that nobody else will be accessing the local blocks. Cleanup blocks are stored off-heap because the need to be allocated by the sweeper, which is called from heap allocation paths. As a result, the GC treats cleanup blocks as roots, just like finalizer blocks. Flushes to the full list signal to the scheduler that cleanup goroutines should be awoken. Every time the scheduler goes to wake up a cleanup goroutine and there were more signals than goroutines to wake, it then forwards this signal to runtime.AddCleanup, so that it creates another goroutine the next time it is called, up to gomaxprocs goroutines. The signals here are a little convoluted, but exist because the sweeper and the scheduler cannot safely create new goroutines. For #71772. For #71825. Change-Id: Ie839fde2b67e1b79ac1426be0ea29a8d923a62cc Reviewed-on: https://go-review.googlesource.com/c/go/+/650697 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
2025-05-08cmd/internal/obj/riscv: reject invalid vadc/vsbc encodingsMark Ryan
The RISC-V Instruction Set Manual Volume states that "for vadc and vsbc, the instruction encoding is reserved if the destination vector register is v0". The assembler currently allows instructions like VADCVVM V1, V2, V0, V0 to be assembled. It's not clear what the behaviour of such instructions will be on target hardware so it's best to disallow them. For reference, binutils (2.44-3.fc42) allows the instruction vadc.vvm v0, v4, v8, v0 to be assembled and the instruction actually executes on a Banana PI F3 without crashing. However, clang (20.1.2) refuses to assemble the instruction, producing the following error. error: the destination vector register group cannot be V0 vadc.vvm v0, v4, v8, v0 ^ Change-Id: Ia913cbd864ae8dbcf9227f69b963c93a99481cff Reviewed-on: https://go-review.googlesource.com/c/go/+/669315 Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Joel Sing <joel@sing.id.au>
2025-05-08cmd/internal/obj/riscv: fix LMUL encoding for MF2 and MF8Mark Ryan
The encodings for the riscv64 special operands SPOP_MF2 and SPOP_MF8 are incorrect, i.e., their values are swapped. This leads to incorrect encodings for the VSETVLI and VSETIVLI instructions. The assembler currently encodes VSETVLI X10, E32, MF8, TA, MA, X12 as VSETVLI X10, E32, MF2, TA, MA, X12 We update the encodings for SPOP_MF2 and SPOP_MF8 so that they match the LMUL table in section "31.3.4. Vector type register, vtype" of the "RISC-V Instruction Set Manual Volume 1". Change-Id: Ic73355533d7c2a901ee060b35c2f7af6d58453e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/670016 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Joel Sing <joel@sing.id.au>
2025-05-07cmd/internal/obj/loong64: add [X]VFRINT[{RNE/RZ/RP/RM}].{S/D} instructionsXiaolin Zhao
Go asm syntax: VFRINT[{RNE/RZ/RP/RM}]{F/D} VJ, VD XVFRINT[{RNE/RZ/RP/RM}]{F/D} XJ, XD Equivalent platform assembler syntax: vfrint[{rne/rz/rp/rm}].{s/d} vd, vj xvfrint[{rne/rz/rp/rm}].{s/d} xd, xj Change-Id: I4ed8782289ae3329d675239f799d5f75b1adc4ad Reviewed-on: https://go-review.googlesource.com/c/go/+/670235 Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-05-05Revert "cmd/compile: allow all of the preamble to be preemptible"Keith Randall
This reverts commits 3f3782feed6e0726ddb08afd32dad7d94fbb38c6 (CL 648518) b386b628521780c048af14a148f373c84e687b26 (CL 668475) Fixes #73542 Change-Id: I218851c5c0b62700281feb0b3f82b6b9b97b910d Reviewed-on: https://go-review.googlesource.com/c/go/+/670055 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-02cmd/internal/obj/riscv: add support for vector permutation instructionsJoel Sing
Add support for vector permutation instructions to the RISC-V assembler. This includes integer scalar move, floating point scalar move, slide up and slide down, register gather, compression and whole vector register move instructions. Change-Id: I1da9f393091504fd81714006355725b8b9ecadea Reviewed-on: https://go-review.googlesource.com/c/go/+/646780 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
2025-05-02cmd/internal/obj/riscv: add support for vector mask instructionsJoel Sing
Add support for vector mask instructions to the RISC-V assembler. These allow manipulation of vector masks and include mask register logical instructions, population count and find-first bit set instructions. Change-Id: I3ab3aa0f918338aee9b37ac5a2b2fdc407875072 Reviewed-on: https://go-review.googlesource.com/c/go/+/646779 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-05-02cmd/internal/obj/riscv: add support for vector reduction instructionsJoel Sing
Add support for vector reduction instructions to the RISC-V assembler, including single-width integer reduction, widening integer reduction, single-width floating-point reduction and widening floating-point reduction. Change-Id: I8f17bef11389f3a017e0430275023fc5d75936e3 Reviewed-on: https://go-review.googlesource.com/c/go/+/646778 Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-05-01cmd/compile,internal/cpu,runtime: intrinsify math/bits.OnesCount on riscv64Joel Sing
For riscv64/rva22u64 and above, we can intrinsify math/bits.OnesCount using the CPOP/CPOPW machine instructions. Since the native Go implementation of OnesCount is relatively expensive, it is also worth emitting a check for Zbb support when compiled for rva20u64. On a Banana Pi F3, with GORISCV64=rva22u64: │ oc.1 │ oc.2 │ │ sec/op │ sec/op vs base │ OnesCount-8 16.930n ± 0% 4.389n ± 0% -74.08% (p=0.000 n=10) OnesCount8-8 5.642n ± 0% 5.016n ± 0% -11.10% (p=0.000 n=10) OnesCount16-8 9.404n ± 0% 5.015n ± 0% -46.67% (p=0.000 n=10) OnesCount32-8 13.165n ± 0% 4.388n ± 0% -66.67% (p=0.000 n=10) OnesCount64-8 16.300n ± 0% 4.388n ± 0% -73.08% (p=0.000 n=10) geomean 11.40n 4.629n -59.40% On a Banana Pi F3, compiled with GORISCV64=rva20u64 and with Zbb detection enabled: │ oc.3 │ oc.4 │ │ sec/op │ sec/op vs base │ OnesCount-8 16.930n ± 0% 5.643n ± 0% -66.67% (p=0.000 n=10) OnesCount8-8 5.642n ± 0% 5.642n ± 0% ~ (p=0.447 n=10) OnesCount16-8 10.030n ± 0% 6.896n ± 0% -31.25% (p=0.000 n=10) OnesCount32-8 13.170n ± 0% 5.642n ± 0% -57.16% (p=0.000 n=10) OnesCount64-8 16.300n ± 0% 5.642n ± 0% -65.39% (p=0.000 n=10) geomean 11.55n 5.873n -49.16% On a Banana Pi F3, compiled with GORISCV64=rva20u64 but with Zbb detection disabled: │ oc.3 │ oc.5 │ │ sec/op │ sec/op vs base │ OnesCount-8 16.93n ± 0% 29.47n ± 0% +74.07% (p=0.000 n=10) OnesCount8-8 5.642n ± 0% 5.643n ± 0% ~ (p=0.191 n=10) OnesCount16-8 10.03n ± 0% 15.05n ± 0% +50.05% (p=0.000 n=10) OnesCount32-8 13.17n ± 0% 18.18n ± 0% +38.04% (p=0.000 n=10) OnesCount64-8 16.30n ± 0% 21.94n ± 0% +34.60% (p=0.000 n=10) geomean 11.55n 15.84n +37.16% For hardware without Zbb, this adds ~5ns overhead, while for hardware with Zbb we achieve a performance gain up of up to 11ns. It is worth noting that OnesCount8 is cheap enough that it is preferable to stick with the generic version in this case. Change-Id: Id657e40e0dd1b1ab8cc0fe0f8a68df4c9f2d7da5 Reviewed-on: https://go-review.googlesource.com/c/go/+/660856 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-01cmd/internal/obj/riscv: add support for vector floating-point instructionsJoel Sing
Add support for vector floating-point instructions to the RISC-V assembler. This includes single-width and widening addition and subtraction, multiplication and division, fused multiply-addition, comparison, min/max, sign-injection, classification and type conversion instructions. Change-Id: I8bceb1c5d7eead0561ba5407ace00805a6144f51 Reviewed-on: https://go-review.googlesource.com/c/go/+/646777 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
2025-04-30cmd/go, cmd/internal/objabi: detect "devel" version by substringDmitri Shuralyov
These were the remaining instances in the main Go repo I found where a Go version like "devel go1.25-9ce47e66e8 Wed Mar 26 03:48:50 2025 -0700" is considered to be a development version rather than a release version, but the version "go1.25-devel_9ce47e66e8 Wed Mar 26 03:48:50 2025 -0700" is not. Update this in preparation of the move of "devel" from front to middle. For #73372. For #73369. Change-Id: If5442ecb0751c08b3a1b4d1148193e501700b956 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/668355 Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-28cmd/internal/obj/loong64: fix the error parameters when calling ↵Guoqi Chen
UnspillRegisterArgs This bug was introduced in CL 648518. Fixes #73518. Change-Id: I4988dd0b636c6a6a48d2aa2e2ae868e43f69995a Reviewed-on: https://go-review.googlesource.com/c/go/+/668475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meidan Li <limeidan@loongson.cn> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com>
2025-04-25cmd/compile: allow all of the preamble to be preemptibleKeith Randall
We currently make some parts of the preamble unpreemptible because it confuses morestack. See comments in the code. Instead, have morestack handle those weird cases so we can remove unpreemptible marks from most places. This CL makes user functions preemptible everywhere if they have no write barriers (at least, on x86). In cmd/go the fraction of functions that need preemptible markings drops from 82% to 36%. Makes the cmd/go binary 0.3% smaller. Update #35470 Change-Id: Ic83d5eabfd0f6d239a92e65684bcce7e67ff30bb Reviewed-on: https://go-review.googlesource.com/c/go/+/648518 Auto-Submit: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-04-24cmd/internal/obj: add new assembly format for BFPT and BFPF on loong64Guoqi Chen
On loong64, BFPT and BFPF are mapped to the platform assembly as follows: Go asm syntax: BFPT FCCx, offs21 BFPF FCCx, offs21 Equivalent platform assembler syntax: bcnez cj, offs21 bceqz cj, offs21 If the condition register is not specified, it defaults to FCC0. Change-Id: I2cc3df62a9c55d4b5eb124789358983c6737319c Reviewed-on: https://go-review.googlesource.com/c/go/+/667456 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Meidan Li <limeidan@loongson.cn>
2025-04-23runtime: move sizeclass defs to new package internal/runtime/gcMichael Anthony Knyszek
We will want to reference these definitions from new generator programs, and this is a good opportunity to cleanup all these old C-style names. Change-Id: Ifb06f0afc381e2697e7877f038eca786610c96de Reviewed-on: https://go-review.googlesource.com/c/go/+/655275 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-04-16all: use strings.ReplaceAll where applicableMarcel Meyer
``` find . \ -not -path './.git/*' \ -not -path './test/*' \ -not -path './src/cmd/vendor/*' \ -not -wholename './src/strings/example_test.go' \ -type f \ -exec \ sed -i -E 's/strings\.Replace\((.+), -1\)/strings\.ReplaceAll\(\1\)/g' {} \; ``` Change-Id: I59e2e91b3654c41a32f17dd91ec56f250198f0d6 GitHub-Last-Rev: 0868b1eccc945ca62a5ed0e56a4054994d4bd659 GitHub-Pull-Request: golang/go#73370 Reviewed-on: https://go-review.googlesource.com/c/go/+/665395 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Robert Griesemer <gri@google.com>
2025-04-15cmd/internal/obj/loong64: add support for {V,XV}SET{EQ,NE}Z.V series ↵limeidan
instructions Change-Id: If3794dfde3ff461662c8a493ff51d0c779e81bca Reviewed-on: https://go-review.googlesource.com/c/go/+/664795 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-13cmd: fix DWARF gen bug with packages that use assemblyThan McIntosh
When the compiler builds a Go package with DWARF 5 generation enabled, it emits relocations into various generated DWARF symbols (ex: SDWARFFCN) that use the R_DWTXTADDR_* flavor of relocations. The specific size of this relocation is selected based on the total number of functions in the package -- if the package is tiny (just a couple funcs) we can use R_DWTXTADDR_U1 relocs (which target just a byte); if the package is larger we might need to use the 2-byte or 3-byte flavor of this reloc. Prior to this patch, the strategy used to pick the right relocation size was flawed in that it didn't take into account packages with assembly code. For example, if you have a package P with 200 funcs written in Go source and 200 funcs written in assembly, you can't use the R_DWTXTADDR_U1 reloc flavor for indirect text references since the real function count for the package (asm + go) exceeds 255. The new strategy (with this patch) is to have the compiler look at the "symabis" file to determine the count of assembly functions. For the assembler, rather than create additional plumbing to pass in the Go source func count we just use an dummy (artificially high) function count so as to select a relocation that will be large enough. Fixes #72810. Updates #26379. Change-Id: I98d04f3c6aacca1dafe1f1610c99c77db290d1d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/663235 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
2025-04-09cmd/internal/obj/wasm: use i64 for large return addrZxilly
Use i64 to avoid overflow when getting PC_F from the return addr. Fixes #73246 Change-Id: I5683dccf7eada4b8536edf53e2e83116a2f6d943 GitHub-Last-Rev: 267d9a1a031868430d0af530de14229ee1ae8609 GitHub-Pull-Request: golang/go#73277 Reviewed-on: https://go-review.googlesource.com/c/go/+/663995 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-04-09cmd/compile: set unalignedOK to make memcombine work properly on loong64limeidan
goos: linux goarch: loong64 pkg: unicode/utf8 cpu: Loongson-3A6000-HV @ 2500.00MHz │ old │ new │ │ sec/op │ sec/op vs base │ ValidTenASCIIChars 7.604n ± 0% 6.805n ± 0% -10.51% (p=0.000 n=10) Valid100KASCIIChars 37.41µ ± 0% 16.58µ ± 0% -55.67% (p=0.000 n=10) ValidTenJapaneseChars 60.84n ± 0% 58.62n ± 0% -3.64% (p=0.000 n=10) ValidLongMostlyASCII 113.5µ ± 0% 113.5µ ± 0% ~ (p=0.303 n=10) ValidLongJapanese 204.6µ ± 0% 206.8µ ± 0% +1.07% (p=0.000 n=10) ValidStringTenASCIIChars 7.604n ± 0% 6.803n ± 0% -10.53% (p=0.000 n=10) ValidString100KASCIIChars 38.05µ ± 0% 17.14µ ± 0% -54.97% (p=0.000 n=10) ValidStringTenJapaneseChars 60.58n ± 0% 59.48n ± 0% -1.82% (p=0.000 n=10) ValidStringLongMostlyASCII 113.5µ ± 0% 113.4µ ± 0% -0.10% (p=0.000 n=10) ValidStringLongJapanese 205.9µ ± 0% 207.3µ ± 0% +0.67% (p=0.000 n=10) geomean 3.324µ 2.756µ -17.08% Change-Id: Id43b6e2e41907bd4b92f421dacde31f048db47d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/662495 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Keith Randall <khr@google.com>
2025-04-03cmd/internal/obj/arm64: return a bit shift from movconJoel Sing
Return the shift in bits from movcon, rather than returning an index. This allows a number of multiplications to be removed, making the code more readable. Scale down to an index only when encoding. Change-Id: I1be91eb526ad95d389e2f8ce97212311551790df Reviewed-on: https://go-review.googlesource.com/c/go/+/650939 Auto-Submit: Joel Sing <joel@sing.id.au> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-04-03cmd/internal/obj/arm64: deduplicate con32classJoel Sing
Teach conclass how to handle 32 bit values and deduplicate the code between con32class and conclass. Change-Id: I9c5eea31d443fd4c2ce700c6ea21e1d0bef665b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/650938 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Joel Sing <joel@sing.id.au>
2025-04-03cmd/internal/obj/arm64: simplify conclassJoel Sing
Reduce repetition by pulling some common conversions into variables. Change-Id: I8c1cc806236b5ecdadf90f4507923718fa5de9b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/650937 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-04-01cmd/internal/obj/riscv: add support for vector fixed-point arithmetic ↵Joel Sing
instructions Add support for vector fixed-point arithmetic instructions to the RISC-V assembler. This includes single width saturating addition and subtraction, averaging addition and subtraction and scaling shift instructions. Change-Id: I9aa27e9565ad016ba5bb2b479e1ba70db24e4ff5 Reviewed-on: https://go-review.googlesource.com/c/go/+/646776 Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-29cmd/internal/obj/arm64: factor out constant classification codeJoel Sing
This will allow for further improvements and deduplication. Change-Id: I9374fc2d16168ced06f3fcc9e558a9c85e24fd01 Reviewed-on: https://go-review.googlesource.com/c/go/+/650936 Reviewed-by: Fannie Zhang <Fannie.Zhang@arm.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-03-29cmd/internal/obj/riscv: add support for vector integer arithmetic instructionsJoel Sing
Add support for vector integer arithmetic instructions to the RISC-V assembler. This includes vector addition, subtraction, integer extension, add-with-carry, subtract-with-borrow, bitwise logical operations, comparison, min/max, integer division and multiplication instructions. Change-Id: I8c191ef8e31291e13743732903e4f12356133a46 Reviewed-on: https://go-review.googlesource.com/c/go/+/646775 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
2025-03-27cmd/internal/obj/riscv,internal/bytealg: synthesize MIN/MAX/MINU/MAXU ↵Joel Sing
instructions Provide a synthesized version of the MIN/MAX/MINU/MAXU instructions if they're not natively available. This allows these instructions to be used in assembly unconditionally. Use MIN in internal/bytealg.compare. Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Change-Id: I8a5a3a59f0a9205e136fc3d673b23eaf3ca469f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/653295 Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-27cmd/internal/obj/riscv: improve constant constructionJoel Sing
Attempt to construct large constants that have a consecutive sequence of ones from a small negative constant, with a logical right and/or left shift. This allows for a large range of mask like constants to be constructed with only two or three instructions, avoiding the need to load from memory. Change-Id: I35a77fecdd2df0ed3f33b772d518f85119d4ff66 Reviewed-on: https://go-review.googlesource.com/c/go/+/652778 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Mark Ryan <markdryan@rivosinc.com> Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
2025-03-26cmd/internal/obj/arm64: add support for BTI instructionJoel Sing
Add support for the `BTI' instruction to the arm64 assembler. This instruction provides Branch Target Identification for targets of indirect branches. A BTI can be marked with a target type of 'C' (call), 'J' (jump) or 'JC' (jump or call). Updates #66054 Change-Id: I1cf31a0382207bb75b9b2deb49ac298a59c00d8a Reviewed-on: https://go-review.googlesource.com/c/go/+/646781 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Marvin Drees <marvin.drees@9elements.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>