]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make procyieldAsm no longer loop infinitely if passed 0
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 17 Oct 2025 20:02:55 +0000 (20:02 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 21 Oct 2025 03:28:55 +0000 (20:28 -0700)
Change-Id: I9f01692373623687e09bee54efebaac0ee361f81
Reviewed-on: https://go-review.googlesource.com/c/go/+/712664
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/asm_386.s
src/runtime/asm_amd64.s
src/runtime/asm_arm64.s
src/runtime/asm_ppc64x.s
src/runtime/stubs.go

index a54ca110e537670a0a48fc1b5d8461e9e1d65285..03f1a46b55913ff6bbda5bcd1984b0b0fdd38e0d 100644 (file)
@@ -599,10 +599,13 @@ CALLFN(·call1073741824, 1073741824)
 
 TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0
        MOVL    cycles+0(FP), AX
+       TESTL   AX, AX
+       JZ      done
 again:
        PAUSE
        SUBL    $1, AX
        JNZ     again
+done:
        RET
 
 TEXT ·publicationBarrier(SB),NOSPLIT,$0-0
index dbf54487a7f5028be93341001939f3851c9b244d..a4c6c53a900ce00ae993bf803630cb0f2563f265 100644 (file)
@@ -817,10 +817,13 @@ CALLFN(·call1073741824, 1073741824)
 
 TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0
        MOVL    cycles+0(FP), AX
+       TESTL   AX, AX
+       JZ      done
 again:
        PAUSE
        SUBL    $1, AX
        JNZ     again
+done:
        RET
 
 
index 94a5b9ee6c866554e41efefaeb46ef4c49393d4b..8bbb6b8a8786d88af53354b8bdd8f3df35d195a6 100644 (file)
@@ -1038,10 +1038,12 @@ aesloop:
 
 TEXT runtime·procyieldAsm(SB),NOSPLIT,$0-0
        MOVWU   cycles+0(FP), R0
+       CBZ     R0, done
 again:
        YIELD
        SUBW    $1, R0
        CBNZ    R0, again
+done:
        RET
 
 // Save state of caller into g->sched,
index e461764e55d21306bfee376d54c2a23c610ef1d4..aaa2e4346c7a411b7d8ac38ca019722b6e4cd747 100644 (file)
@@ -614,6 +614,8 @@ CALLFN(·call1073741824, 1073741824)
 
 TEXT runtime·procyieldAsm(SB),NOSPLIT|NOFRAME,$0-4
        MOVW    cycles+0(FP), R7
+       CMP     $0, R7
+       BEQ     done
        // POWER does not have a pause/yield instruction equivalent.
        // Instead, we can lower the program priority by setting the
        // Program Priority Register prior to the wait loop and set it
@@ -625,6 +627,7 @@ again:
        CMP     $0, R7
        BNE     again
        OR      R6, R6, R6      // Set PPR priority back to medium-low
+done:
        RET
 
 // Save state of caller into g->sched,
index 1692283541372e856834c19771191ef26e1b9e30..d5a35d15b25141d817a49c6cc78ffca0c783878b 100644 (file)
@@ -283,13 +283,6 @@ func procyield(cycles uint32) {
 }
 
 // procyieldAsm is the assembly implementation of procyield.
-//
-// It may loop infinitely if called with cycles == 0. Prefer
-// procyield, which will compile down to nothing in such cases,
-// instead.
-//
-// FIXME: The implementation really should not loop infinitely if
-// the number of cycles is 0.
 func procyieldAsm(cycles uint32)
 
 type neverCallThisFunction struct{}