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

Use emscripten_stack_set_limits in wasm_worker_initialize.S #22755

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Oct 16, 2024

Followup to #22683. This change avoids making __stack_base and __stack_end into public/external symbols and avoids reimplementing emscripten_stack_set_limits.

This is a minor code size win too.

Copy link
Collaborator

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one tiny nitpick. With those globals being refactored out, I'm wondering what is left before this could just be a simple C function instead of being written in assembly. I see that there is still a global reference to a __stack_pointer that is needed here. I wonder if it would be possible to expose a function that is just emscripten_reset_stack_pointer or something like that, which would just set __stack_pointer to __stack_base? (Also probably not for this PR, I'm just thinking out loud a bit).

system/lib/wasm_worker/wasm_worker_initialize.S Outdated Show resolved Hide resolved
@sbc100
Copy link
Collaborator Author

sbc100 commented Oct 17, 2024

LGTM, with one tiny nitpick. With those globals being refactored out, I'm wondering what is left before this could just be a simple C function instead of being written in assembly. I see that there is still a global reference to a __stack_pointer that is needed here. I wonder if it would be possible to expose a function that is just emscripten_reset_stack_pointer or something like that, which would just set __stack_pointer to __stack_base? (Also probably not for this PR, I'm just thinking out loud a bit).

The problem is that you cannot safely call any C function until the stack pointer has been set. I mean in theory you could try to second guess the C compiler and try to write your C function in way you are think it won't itself use the stack pointer, but its very fragile. Better to write these very low level startup routines asm I think

@sbc100 sbc100 force-pushed the emscripten_stack_set_limits branch from fd63f2d to e481c5f Compare October 17, 2024 17:03
"a.wasm": 1879,
"a.wasm.gz": 1066,
"total": 3277,
"total_gz": 2032
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - I'm puzzled to understand how this saved code size though..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also a little surprised.

My initial guess was that perhaps emscripten_stack_set_limits was being included prior to this change and so this change reduces overall duplication... but I don't think thats true. I could investigate further but but this seems like a win so I think we just take it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the earlier sizes were out of date, was there still possibility for slack %?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i double checked that. I normally rebaseline all tests before landing changes like this, just to be sure I'm seeing the real deltas.

Followup to emscripten-core#22683.  This change avoids making __stack_base and
__stack_end into public/external symbols and avoids reimplementing
`emscripten_stack_set_limits`.
@sbc100 sbc100 force-pushed the emscripten_stack_set_limits branch from e481c5f to 68c43f8 Compare October 17, 2024 18:03
@sbc100 sbc100 enabled auto-merge (squash) October 17, 2024 18:05
@sbc100 sbc100 merged commit ac83519 into emscripten-core:main Oct 17, 2024
28 checks passed
@sbc100 sbc100 deleted the emscripten_stack_set_limits branch October 17, 2024 19:53
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.

3 participants