]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use CBZ/CBNZ in linux/arm64 assembly code
authorXiangdong Ji <xiangdong.ji@arm.com>
Thu, 21 Nov 2019 07:46:37 +0000 (07:46 +0000)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 3 Mar 2020 09:29:47 +0000 (09:29 +0000)
Replace compare and branch on zero/non-zero instructions in linux/arm64
assembly files with CBZ/CBNZ.

Change-Id: I4dbf56678f85827e83b5863804368bc28a4603b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/209617
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/runtime/asm_arm64.s
src/runtime/race_arm64.s
src/runtime/rt0_linux_arm64.s
src/runtime/sys_linux_arm64.s
src/runtime/tls_arm64.s

index 0be06d124e508664a2a6364116e689f9f165347f..6b3d1e779e6efef12b41c3507f5c722b54727342 100644 (file)
@@ -27,8 +27,7 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
 
        // if there is a _cgo_init, call it using the gcc ABI.
        MOVD    _cgo_init(SB), R12
-       CMP     $0, R12
-       BEQ     nocgo
+       CBZ     R12, nocgo
 
        MRS_TPIDR_R0                    // load TLS base pointer
        MOVD    R0, R3                  // arg 3: TLS base pointer
@@ -114,8 +113,7 @@ TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8
        MOVD    ZR, gobuf_ret(R3)
        // Assert ctxt is zero. See func save.
        MOVD    gobuf_ctxt(R3), R0
-       CMP     $0, R0
-       BEQ     2(PC)
+       CBZ     R0, 2(PC)
        CALL    runtime·badctxt(SB)
        RET
 
@@ -448,8 +446,7 @@ CALLFN(·call1073741824, 1073741832 )
 // func memhash32(p unsafe.Pointer, h uintptr) uintptr
 TEXT runtime·memhash32(SB),NOSPLIT|NOFRAME,$0-24
        MOVB    runtime·useAeshash(SB), R0
-       CMP     $0, R0
-       BEQ     noaes
+       CBZ     R0, noaes
        MOVD    p+0(FP), R0
        MOVD    h+8(FP), R1
        MOVD    $ret+16(FP), R2
@@ -474,8 +471,7 @@ noaes:
 // func memhash64(p unsafe.Pointer, h uintptr) uintptr
 TEXT runtime·memhash64(SB),NOSPLIT|NOFRAME,$0-24
        MOVB    runtime·useAeshash(SB), R0
-       CMP     $0, R0
-       BEQ     noaes
+       CBZ     R0, noaes
        MOVD    p+0(FP), R0
        MOVD    h+8(FP), R1
        MOVD    $ret+16(FP), R2
@@ -500,8 +496,7 @@ noaes:
 // func memhash(p unsafe.Pointer, h, size uintptr) uintptr
 TEXT runtime·memhash(SB),NOSPLIT|NOFRAME,$0-32
        MOVB    runtime·useAeshash(SB), R0
-       CMP     $0, R0
-       BEQ     noaes
+       CBZ     R0, noaes
        MOVD    p+0(FP), R0
        MOVD    s+16(FP), R1
        MOVD    h+8(FP), R3
@@ -513,8 +508,7 @@ noaes:
 // func strhash(p unsafe.Pointer, h uintptr) uintptr
 TEXT runtime·strhash(SB),NOSPLIT|NOFRAME,$0-24
        MOVB    runtime·useAeshash(SB), R0
-       CMP     $0, R0
-       BEQ     noaes
+       CBZ     R0, noaes
        MOVD    p+0(FP), R10 // string pointer
        LDP     (R10), (R0, R1) //string data/ length
        MOVD    h+8(FP), R3
@@ -548,8 +542,7 @@ TEXT aeshashbody<>(SB),NOSPLIT|NOFRAME,$0
        B       aes129plus
 
 aes0to15:
-       CMP     $0, R1
-       BEQ     aes0
+       CBZ     R1, aes0
        VEOR    V2.B16, V2.B16, V2.B16
        TBZ     $3, R1, less_than_8
        VLD1.P  8(R0), V2.D[0]
@@ -879,8 +872,7 @@ TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0
        MOVD    $0, (g_sched+gobuf_ret)(g)
        // Assert ctxt is zero. See func save.
        MOVD    (g_sched+gobuf_ctxt)(g), R0
-       CMP     $0, R0
-       BEQ     2(PC)
+       CBZ     R0, 2(PC)
        CALL    runtime·badctxt(SB)
        RET
 
@@ -893,8 +885,7 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20
        MOVD    arg+8(FP), R0
 
        MOVD    RSP, R2         // save original stack pointer
-       CMP     $0, g
-       BEQ     nosave
+       CBZ     g, nosave
        MOVD    g, R4
 
        // Figure out if we need to switch to m->g0 stack.
@@ -990,8 +981,7 @@ TEXT ·cgocallback_gofunc(SB),NOSPLIT,$24-32
 
        // Load g from thread-local storage.
        MOVB    runtime·iscgo(SB), R3
-       CMP     $0, R3
-       BEQ     nocgo
+       CBZ     R3, nocgo
        BL      runtime·load_g(SB)
 nocgo:
 
@@ -1000,8 +990,7 @@ nocgo:
        // In this case, we're running on the thread stack, so there's
        // lots of space, but the linker doesn't know. Hide the call from
        // the linker analysis by using an indirect call.
-       CMP     $0, g
-       BEQ     needm
+       CBZ     g, needm
 
        MOVD    g_m(g), R8
        MOVD    R8, savedm-8(SP)
@@ -1092,8 +1081,7 @@ havem:
        // If the m on entry was nil, we called needm above to borrow an m
        // for the duration of the call. Since the call is over, return it with dropm.
        MOVD    savedm-8(SP), R6
-       CMP     $0, R6
-       BNE     droppedm
+       CBNZ    R6, droppedm
        MOVD    $runtime·dropm(SB), R0
        BL      (R0)
 droppedm:
index 46224f8d73cc51cd8f6d2d234d44f46c9512ac9c..9b909ac021698d7d551c1d42c3c055a794bf9248 100644 (file)
@@ -421,8 +421,7 @@ TEXT        runtime·racecallbackthunk(SB), NOSPLIT|NOFRAME, $0
        // First, code below assumes that we are on curg, while raceGetProcCmd
        // can be executed on g0. Second, it is called frequently, so will
        // benefit from this fast path.
-       CMP     $0, R0
-       BNE     rest
+       CBNZ    R0, rest
        MOVD    g, R13
        load_g
        MOVD    g_m(g), R0
index a6bc99df569309e056a5fc7d4308da63b52cdc92..f48a8d61902e42d3630b763e3c7ec6d888b34ec7 100644 (file)
@@ -44,8 +44,7 @@ TEXT _rt0_arm64_linux_lib(SB),NOSPLIT,$184
 
        // Create a new thread to do the runtime initialization and return.
        MOVD    _cgo_sys_thread_create(SB), R4
-       CMP     $0, R4
-       BEQ     nocgo
+       CBZ     R4, nocgo
        MOVD    $_rt0_arm64_linux_lib_go(SB), R0
        MOVD    $0, R1
        SUB     $16, RSP                // reserve 16 bytes for sp-8 where fp may be saved.
index b9588cec301fc2636eeb8fda30cd06422646c619..b23e3b9a113d74f4e6ecf9df7198bc2a1add40a0 100644 (file)
@@ -419,8 +419,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$192
        // first save R0, because runtime·load_g will clobber it
        MOVW    R0, 8(RSP)
        MOVBU   runtime·iscgo(SB), R0
-       CMP     $0, R0
-       BEQ     2(PC)
+       CBZ     R0, 2(PC)
        BL      runtime·load_g(SB)
 
        MOVD    R1, 16(RSP)
index fb8627db29bd29826b0c9cb9a0807526099309b8..999914d6550ad5b74c99211f9eeac5a9f6f12d25 100644 (file)
@@ -10,8 +10,7 @@
 
 TEXT runtime·load_g(SB),NOSPLIT,$0
        MOVB    runtime·iscgo(SB), R0
-       CMP     $0, R0
-       BEQ     nocgo
+       CBZ     R0, nocgo
 
        MRS_TPIDR_R0
 #ifdef GOOS_darwin
@@ -27,8 +26,7 @@ nocgo:
 
 TEXT runtime·save_g(SB),NOSPLIT,$0
        MOVB    runtime·iscgo(SB), R0
-       CMP     $0, R0
-       BEQ     nocgo
+       CBZ     R0, nocgo
 
        MRS_TPIDR_R0
 #ifdef GOOS_darwin