Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up CallbackSystem::run method #7

Merged
merged 5 commits into from
Oct 30, 2023
Merged

Cleaned up CallbackSystem::run method #7

merged 5 commits into from
Oct 30, 2023

Conversation

vultix
Copy link
Contributor

@vultix vultix commented Sep 1, 2023

Just some small cleanup to make CallbackSystem::run have fewer branches and IMO simplify it a bit.

ASM before (160 lines):

bevy_eventlistener_core::callbacks::CallbackSystem::run:
 sub     sp, sp, #128
 stp     x29, x30, [sp, #112]
 add     x29, sp, #112
 str     x0, [sp, #8]
 str     x1, [sp, #16]
 sturb   wzr, [x29, #-17]
 sturb   wzr, [x29, #-18]
 bl      __ZN23bevy_eventlistener_core9callbacks14CallbackSystem14is_initialized17hde01dbcc5bb54d25E
 tbz     w0, #0, LBB22_2
 b       LBB22_1
LBB22_1:
 ldr     x8, [sp, #8]
 ldr     x8, [x8]
 subs    x8, x8, #2
 cset    w8, eq
 tbnz    w8, #0, LBB22_24
 b       LBB22_25
LBB22_2:
 ldr     x0, [sp, #8]
 mov     w8, #1
 sturb   w8, [x29, #-18]
 add     x1, sp, #24
 str     xzr, [sp, #24]
 bl      __ZN4core3mem4swap17h9768ad68f6db01b6E
 b       LBB22_5
LBB22_3:
 ldr     x8, [sp, #24]
 subs    x8, x8, #1
 cset    w8, eq
 tbnz    w8, #0, LBB22_16
 b       LBB22_17
LBB22_4:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB22_3
LBB22_5:
 ldr     x8, [sp, #24]
 subs    x8, x8, #1
 cset    w8, ne
 tbnz    w8, #0, LBB22_7
 b       LBB22_6
LBB22_6:
 ldr     x1, [sp, #16]
 sturb   wzr, [x29, #-18]
 mov     w8, #1
 sturb   w8, [x29, #-17]
 ldr     x9, [sp, #32]
 ldr     x8, [sp, #40]
 str     x9, [sp, #48]
 str     x8, [sp, #56]
 ldr     x0, [sp, #48]
 ldr     x8, [sp, #56]
 ldr     x8, [x8, #104]
 blr     x8
 b       LBB22_10
LBB22_7:
 ldr     x8, [sp, #24]
 subs    x8, x8, #1
 cset    w8, eq
 tbnz    w8, #0, LBB22_20
 b       LBB22_21
LBB22_8:
 ldurb   w8, [x29, #-17]
 tbnz    w8, #0, LBB22_14
 b       LBB22_3
LBB22_9:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB22_8
LBB22_10:
 ldr     x0, [sp, #8]
 sturb   wzr, [x29, #-17]
 ldr     x9, [sp, #48]
 ldr     x8, [sp, #56]
 stur    x9, [x29, #-40]
 stur    x8, [x29, #-32]
 mov     w8, #2
 stur    x8, [x29, #-48]
 bl      __ZN4core3ptr71drop_in_place$LT$bevy_eventlistener_core..callbacks..CallbackSystem$GT$17h72d559a889af9b7cE
 b       LBB22_13
LBB22_11:
 ldr     x9, [sp, #8]
 ldur    q0, [x29, #-48]
 str     q0, [x9]
 ldur    x8, [x29, #-32]
 str     x8, [x9, #16]
 b       LBB22_8
LBB22_12:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB22_11
LBB22_13:
 ldr     x9, [sp, #8]
 ldur    q0, [x29, #-48]
 str     q0, [x9]
 ldur    x8, [x29, #-32]
 str     x8, [x9, #16]
 sturb   wzr, [x29, #-17]
 b       LBB22_7
LBB22_14:
 add     x0, sp, #48
 bl      __ZN4core3ptr147drop_in_place$LT$alloc..boxed..Box$LT$dyn$u20$bevy_ecs..system..system..System$u2b$Out$u20$$u3d$$u20$$LP$$RP$$u2b$In$u20$$u3d$$u20$$LP$$RP$$GT$$GT$17hbc1ade13abce4d42E
 b       LBB22_3
LBB22_15:
 bl      __ZN4core9panicking19panic_cannot_unwind17h911ff5cd61f62d63E
LBB22_16:
 ldurb   w8, [x29, #-18]
 tbnz    w8, #0, LBB22_19
 b       LBB22_18
LBB22_17:
 add     x0, sp, #24
 bl      __ZN4core3ptr71drop_in_place$LT$bevy_eventlistener_core..callbacks..CallbackSystem$GT$17h72d559a889af9b7cE
 b       LBB22_18
LBB22_18:
 ldur    x0, [x29, #-16]
 bl      __Unwind_Resume
LBB22_19:
 add     x8, sp, #24
 add     x0, x8, #8
 bl      __ZN4core3ptr147drop_in_place$LT$alloc..boxed..Box$LT$dyn$u20$bevy_ecs..system..system..System$u2b$Out$u20$$u3d$$u20$$LP$$RP$$u2b$In$u20$$u3d$$u20$$LP$$RP$$GT$$GT$17hbc1ade13abce4d42E
 b       LBB22_18
LBB22_20:
 ldurb   w8, [x29, #-18]
 tbnz    w8, #0, LBB22_23
 b       LBB22_22
LBB22_21:
 add     x0, sp, #24
 bl      __ZN4core3ptr71drop_in_place$LT$bevy_eventlistener_core..callbacks..CallbackSystem$GT$17h72d559a889af9b7cE
 b       LBB22_22
LBB22_22:
 sturb   wzr, [x29, #-18]
 b       LBB22_1
LBB22_23:
 add     x8, sp, #24
 add     x0, x8, #8
 bl      __ZN4core3ptr147drop_in_place$LT$alloc..boxed..Box$LT$dyn$u20$bevy_ecs..system..system..System$u2b$Out$u20$$u3d$$u20$$LP$$RP$$u2b$In$u20$$u3d$$u20$$LP$$RP$$GT$$GT$17hbc1ade13abce4d42E
 b       LBB22_22
LBB22_24:
 ldr     x1, [sp, #16]
 ldr     x8, [sp, #8]
 ldr     x0, [x8, #8]
 ldr     x8, [x8, #16]
 ldr     x8, [x8, #88]
 blr     x8
 ldr     x8, [sp, #8]
 ldr     x1, [sp, #16]
 ldr     x0, [x8, #8]
 ldr     x8, [x8, #16]
 ldr     x8, [x8, #96]
 blr     x8
 b       LBB22_25
LBB22_25:
 ldp     x29, x30, [sp, #112]
 add     sp, sp, #128
 ret

ASM after (130 lines):

bevy_eventlistener_core::callbacks::CallbackSystem::run:
 sub     sp, sp, #144
 stp     x29, x30, [sp, #128]
 add     x29, sp, #128
 str     x0, [sp]
 str     x1, [sp, #8]
 sturb   wzr, [x29, #-17]
 add     x8, sp, #40
 bl      __ZN4core3mem4take17hd9ecf489a6ec01b4E
 ldr     x8, [sp, #40]
 str     x8, [sp, #16]
 subs    x8, x8, #0
 cset    w8, eq
 tbnz    w8, #0, LBB19_4
 b       LBB19_1
LBB19_1:
 ldr     x8, [sp, #16]
 subs    x8, x8, #1
 cset    w8, eq
 tbnz    w8, #0, LBB19_5
 b       LBB19_2
LBB19_2:
 b       LBB19_6
LBB19_4:
 sturb   wzr, [x29, #-17]
 b       LBB19_21
LBB19_5:
 ldr     x1, [sp, #8]
 ldr     x9, [sp, #48]
 ldr     x8, [sp, #56]
 str     x9, [sp, #64]
 str     x8, [sp, #72]
 ldr     x0, [sp, #64]
 ldr     x8, [sp, #72]
 ldr     x8, [x8, #104]
 blr     x8
 b       LBB19_10
LBB19_6:
 ldr     x9, [sp, #48]
 ldr     x8, [sp, #56]
 mov     w10, #1
 sturb   w10, [x29, #-17]
 str     x9, [sp, #24]
 str     x8, [sp, #32]
 b       LBB19_7
LBB19_7:
 ldr     x1, [sp, #8]
 ldr     x0, [sp, #24]
 ldr     x8, [sp, #32]
 ldr     x8, [x8, #88]
 blr     x8
 b       LBB19_15
LBB19_8:
 add     x0, sp, #64
 bl      __ZN4core3ptr147drop_in_place$LT$alloc..boxed..Box$LT$dyn$u20$bevy_ecs..system..system..System$u2b$Out$u20$$u3d$$u20$$LP$$RP$$u2b$In$u20$$u3d$$u20$$LP$$RP$$GT$$GT$17hbc1ade13abce4d42E
 b       LBB19_12
LBB19_9:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB19_8
LBB19_10:
 mov     w8, #1
 sturb   w8, [x29, #-17]
 ldr     x9, [sp, #64]
 ldr     x8, [sp, #72]
 str     x9, [sp, #24]
 str     x8, [sp, #32]
 b       LBB19_7
LBB19_11:
 bl      __ZN4core9panicking19panic_cannot_unwind17h911ff5cd61f62d63E
LBB19_12:
 ldur    x0, [x29, #-16]
 bl      __Unwind_Resume
LBB19_13:
 ldurb   w8, [x29, #-17]
 tbnz    w8, #0, LBB19_20
 b       LBB19_12
LBB19_14:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB19_13
LBB19_15:
 ldr     x1, [sp, #8]
 ldr     x0, [sp, #24]
 ldr     x8, [sp, #32]
 ldr     x8, [x8, #96]
 blr     x8
 b       LBB19_16
LBB19_16:
 ldr     x0, [sp]
 sturb   wzr, [x29, #-17]
 ldr     x9, [sp, #24]
 ldr     x8, [sp, #32]
 stur    x9, [x29, #-40]
 stur    x8, [x29, #-32]
 mov     w8, #2
 stur    x8, [x29, #-48]
 bl      __ZN4core3ptr71drop_in_place$LT$bevy_eventlistener_core..callbacks..CallbackSystem$GT$17h72d559a889af9b7cE
 b       LBB19_19
LBB19_17:
 ldr     x9, [sp]
 ldur    q0, [x29, #-48]
 str     q0, [x9]
 ldur    x8, [x29, #-32]
 str     x8, [x9, #16]
 b       LBB19_13
LBB19_18:
 stur    x0, [x29, #-16]
 mov     x8, x1
 stur    w8, [x29, #-8]
 b       LBB19_17
LBB19_19:
 ldr     x9, [sp]
 ldur    q0, [x29, #-48]
 str     q0, [x9]
 ldur    x8, [x29, #-32]
 str     x8, [x9, #16]
 sturb   wzr, [x29, #-17]
 b       LBB19_21
LBB19_20:
 add     x0, sp, #24
 bl      __ZN4core3ptr147drop_in_place$LT$alloc..boxed..Box$LT$dyn$u20$bevy_ecs..system..system..System$u2b$Out$u20$$u3d$$u20$$LP$$RP$$u2b$In$u20$$u3d$$u20$$LP$$RP$$GT$$GT$17hbc1ade13abce4d42E
 b       LBB19_12
LBB19_21:
 ldp     x29, x30, [sp, #128]
 add     sp, sp, #144
 ret

@aevyrie aevyrie merged commit 4ff7482 into aevyrie:main Oct 30, 2023
6 checks passed
@aevyrie
Copy link
Owner

aevyrie commented Oct 30, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants