Last active
April 19, 2023 07:40
-
-
Save regorov/168cdc4bf820dc8b57c00f810004886c to your computer and use it in GitHub Desktop.
golang: impact using defer to generated asm code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"sync" | |
) | |
var mx sync.Mutex | |
func main() { | |
x := 0 | |
x = f1(x) | |
println(x) | |
x = f2(x) | |
println(x) | |
} | |
//go:noinline | |
func f1(i int) int { | |
mx.Lock() | |
defer mx.Unlock() | |
return i+1 | |
} | |
//go:noinline | |
func f2(i int) int { | |
mx.Lock() | |
res := i+1 | |
mx.Unlock() | |
} | |
[gera@t460p gouth]$ go tool objdump -s main.f1 ./main | |
TEXT main.f1(SB) /home/gera/go/src/gouth/main.go | |
main.go:20 0x455ba0 493b6610 CMPQ 0x10(R14), SP | |
main.go:20 0x455ba4 0f86ca000000 JBE 0x455c74 | |
main.go:20 0x455baa 4883ec40 SUBQ $0x40, SP | |
main.go:20 0x455bae 48896c2438 MOVQ BP, 0x38(SP) | |
main.go:20 0x455bb3 488d6c2438 LEAQ 0x38(SP), BP | |
main.go:20 0x455bb8 49c7c500000000 MOVQ $0x0, R13 | |
main.go:20 0x455bbf 4c896c2430 MOVQ R13, 0x30(SP) | |
main.go:20 0x455bc4 c644240f00 MOVB $0x0, 0xf(SP) | |
main.go:20 0x455bc9 48c744241000000000 MOVQ $0x0, 0x10(SP) | |
main.go:21 0x455bd2 90 NOPL | |
main.go:20 0x455bd3 4889c1 MOVQ AX, CX | |
mutex.go:74 0x455bd6 31c0 XORL AX, AX | |
mutex.go:74 0x455bd8 488d1d59250900 LEAQ main.mx(SB), BX | |
mutex.go:74 0x455bdf be01000000 MOVL $0x1, SI | |
mutex.go:74 0x455be4 f00fb133 LOCK CMPXCHGL SI, 0(BX) | |
mutex.go:74 0x455be8 0f94c3 SETE BL | |
mutex.go:74 0x455beb 84db TESTL BL, BL | |
mutex.go:74 0x455bed 751b JNE 0x455c0a | |
main.go:20 0x455bef 48894c2418 MOVQ CX, 0x18(SP) | |
mutex.go:81 0x455bf4 488d053d250900 LEAQ main.mx(SB), AX | |
mutex.go:81 0x455bfb 0f1f440000 NOPL 0(AX)(AX*1) | |
mutex.go:81 0x455c00 e8fbf8ffff CALL sync.(*Mutex).lockSlow(SB) | |
main.go:23 0x455c05 488b4c2418 MOVQ 0x18(SP), CX | |
main.go:22 0x455c0a 440f117c2420 MOVUPS X15, 0x20(SP) | |
main.go:22 0x455c10 488d0589000000 LEAQ main.f1.func1(SB), AX | |
main.go:22 0x455c17 4889442420 MOVQ AX, 0x20(SP) | |
main.go:22 0x455c1c 488d0515250900 LEAQ main.mx(SB), AX | |
main.go:22 0x455c23 4889442428 MOVQ AX, 0x28(SP) | |
main.go:22 0x455c28 488d442420 LEAQ 0x20(SP), AX | |
main.go:22 0x455c2d 4889442430 MOVQ AX, 0x30(SP) | |
main.go:22 0x455c32 c644240f01 MOVB $0x1, 0xf(SP) | |
main.go:23 0x455c37 488d4101 LEAQ 0x1(CX), AX | |
main.go:23 0x455c3b 4889442410 MOVQ AX, 0x10(SP) | |
main.go:23 0x455c40 c644240f00 MOVB $0x0, 0xf(SP) | |
main.go:23 0x455c45 488b542430 MOVQ 0x30(SP), DX | |
main.go:23 0x455c4a 488b02 MOVQ 0(DX), AX | |
main.go:23 0x455c4d ffd0 CALL AX | |
main.go:23 0x455c4f 488b442410 MOVQ 0x10(SP), AX | |
main.go:23 0x455c54 488b6c2438 MOVQ 0x38(SP), BP | |
main.go:23 0x455c59 4883c440 ADDQ $0x40, SP | |
main.go:23 0x455c5d c3 RET | |
main.go:23 0x455c5e 6690 NOPW | |
main.go:23 0x455c60 e81b4dfdff CALL runtime.deferreturn(SB) | |
main.go:23 0x455c65 488b442410 MOVQ 0x10(SP), AX | |
main.go:23 0x455c6a 488b6c2438 MOVQ 0x38(SP), BP | |
main.go:23 0x455c6f 4883c440 ADDQ $0x40, SP | |
main.go:23 0x455c73 c3 RET | |
main.go:20 0x455c74 4889442408 MOVQ AX, 0x8(SP) | |
main.go:20 0x455c79 e802c6ffff CALL runtime.morestack_noctxt.abi0(SB) | |
main.go:20 0x455c7e 488b442408 MOVQ 0x8(SP), AX | |
main.go:20 0x455c83 e918ffffff JMP main.f1(SB) | |
main.go:22 0x455ca0 493b6610 CMPQ 0x10(R14), SP | |
main.go:22 0x455ca4 762a JBE 0x455cd0 | |
main.go:22 0x455ca6 4883ec10 SUBQ $0x10, SP | |
main.go:22 0x455caa 48896c2408 MOVQ BP, 0x8(SP) | |
main.go:22 0x455caf 488d6c2408 LEAQ 0x8(SP), BP | |
main.go:22 0x455cb4 4d8b6620 MOVQ 0x20(R14), R12 | |
main.go:22 0x455cb8 4d85e4 TESTQ R12, R12 | |
main.go:22 0x455cbb 751a JNE 0x455cd7 | |
main.go:22 0x455cbd 488b4208 MOVQ 0x8(DX), AX | |
main.go:22 0x455cc1 e8dafaffff CALL sync.(*Mutex).Unlock(SB) | |
main.go:22 0x455cc6 488b6c2408 MOVQ 0x8(SP), BP | |
main.go:22 0x455ccb 4883c410 ADDQ $0x10, SP | |
main.go:22 0x455ccf c3 RET | |
main.go:22 0x455cd0 e80bc5ffff CALL runtime.morestack.abi0(SB) | |
main.go:22 0x455cd5 ebc9 JMP main.f1.func1(SB) | |
main.go:22 0x455cd7 4c8d6c2418 LEAQ 0x18(SP), R13 | |
main.go:22 0x455cdc 0f1f4000 NOPL 0(AX) | |
main.go:22 0x455ce0 4d392c24 CMPQ R13, 0(R12) | |
main.go:22 0x455ce4 75d7 JNE 0x455cbd | |
main.go:22 0x455ce6 49892424 MOVQ SP, 0(R12) | |
main.go:22 0x455cea ebd1 JMP 0x455cbd | |
gera@t460p gouth]$ go tool objdump -s main.f2 ./main | |
TEXT main.f2(SB) /home/gera/go/src/gouth/main.go | |
main.go:27 0x455d00 493b6610 CMPQ 0x10(R14), SP | |
main.go:27 0x455d04 767d JBE 0x455d83 | |
main.go:27 0x455d06 4883ec18 SUBQ $0x18, SP | |
main.go:27 0x455d0a 48896c2410 MOVQ BP, 0x10(SP) | |
main.go:27 0x455d0f 488d6c2410 LEAQ 0x10(SP), BP | |
main.go:27 0x455d14 4889442420 MOVQ AX, 0x20(SP) | |
main.go:28 0x455d19 4889c1 MOVQ AX, CX | |
mutex.go:74 0x455d1c 31c0 XORL AX, AX | |
mutex.go:74 0x455d1e 488d1513240900 LEAQ main.mx(SB), DX | |
mutex.go:74 0x455d25 be01000000 MOVL $0x1, SI | |
mutex.go:74 0x455d2a f00fb132 LOCK CMPXCHGL SI, 0(DX) | |
mutex.go:74 0x455d2e 400f94c6 SETE SI | |
mutex.go:74 0x455d32 4084f6 TESTL SI, SI | |
mutex.go:74 0x455d35 751a JNE 0x455d51 | |
mutex.go:81 0x455d37 488d05fa230900 LEAQ main.mx(SB), AX | |
mutex.go:81 0x455d3e 6690 NOPW | |
mutex.go:81 0x455d40 e8bbf7ffff CALL sync.(*Mutex).lockSlow(SB) | |
main.go:29 0x455d45 488b4c2420 MOVQ 0x20(SP), CX | |
mutex.go:74 0x455d4a 488d15e7230900 LEAQ main.mx(SB), DX | |
main.go:30 0x455d51 90 NOPL | |
mutex.go:210 0x455d52 beffffffff MOVL $-0x1, SI | |
mutex.go:210 0x455d57 f00fc132 LOCK XADDL SI, 0(DX) | |
mutex.go:210 0x455d5b 8d5eff LEAL -0x1(SI), BX | |
mutex.go:210 0x455d5e 6690 NOPW | |
mutex.go:211 0x455d60 85db TESTL BX, BX | |
mutex.go:211 0x455d62 7411 JE 0x455d75 | |
mutex.go:214 0x455d64 488d05cd230900 LEAQ main.mx(SB), AX | |
mutex.go:214 0x455d6b e890faffff CALL sync.(*Mutex).unlockSlow(SB) | |
main.go:29 0x455d70 488b4c2420 MOVQ 0x20(SP), CX | |
main.go:29 0x455d75 488d4101 LEAQ 0x1(CX), AX | |
main.go:31 0x455d79 488b6c2410 MOVQ 0x10(SP), BP | |
main.go:31 0x455d7e 4883c418 ADDQ $0x18, SP | |
main.go:31 0x455d82 c3 RET | |
main.go:27 0x455d83 4889442408 MOVQ AX, 0x8(SP) | |
main.go:27 0x455d88 e8f3c4ffff CALL runtime.morestack_noctxt.abi0(SB) | |
main.go:27 0x455d8d 488b442408 MOVQ 0x8(SP), AX | |
main.go:27 0x455d92 e969ffffff JMP main.f2(SB) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment