From 52b457d6f320c3491ab14a71afc3c7416b36430c Mon Sep 17 00:00:00 2001 From: Xiangdong Ji Date: Thu, 21 Nov 2019 07:46:37 +0000 Subject: [PATCH] runtime: use CBZ/CBNZ in linux/arm64 assembly code 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 TryBot-Result: Gobot Gobot Reviewed-by: Tobias Klauser --- src/runtime/asm_arm64.s | 36 ++++++++++++----------------------- src/runtime/race_arm64.s | 3 +-- src/runtime/rt0_linux_arm64.s | 3 +-- src/runtime/sys_linux_arm64.s | 3 +-- src/runtime/tls_arm64.s | 6 ++---- 5 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 0be06d124e..6b3d1e779e 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -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: diff --git a/src/runtime/race_arm64.s b/src/runtime/race_arm64.s index 46224f8d73..9b909ac021 100644 --- a/src/runtime/race_arm64.s +++ b/src/runtime/race_arm64.s @@ -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 diff --git a/src/runtime/rt0_linux_arm64.s b/src/runtime/rt0_linux_arm64.s index a6bc99df56..f48a8d6190 100644 --- a/src/runtime/rt0_linux_arm64.s +++ b/src/runtime/rt0_linux_arm64.s @@ -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. diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index b9588cec30..b23e3b9a11 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -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) diff --git a/src/runtime/tls_arm64.s b/src/runtime/tls_arm64.s index fb8627db29..999914d655 100644 --- a/src/runtime/tls_arm64.s +++ b/src/runtime/tls_arm64.s @@ -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 -- 2.50.0