-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Allow SHARED_MEMORY flag to be used independently.
#22683
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
Changes from 11 commits
3845995
015f279
d69c14c
8f72acf
e739a23
979d9d8
1d48e33
a2618d9
a297e13
1faaf99
dcfad64
2b73900
0d4be85
e3b65b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| .extern __stack_pointer | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, one last change. Can we call this file
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
| .extern __stack_base | ||
| .extern __stack_end | ||
|
|
||
| #ifdef __wasm64__ | ||
| #define PTR i64 | ||
| #define ALIGN 3 | ||
| #define PTRSTORE .int64 | ||
| #else | ||
| #define PTR i32 | ||
| #define ALIGN 2 | ||
| #define PTRSTORE .int32 | ||
| #endif | ||
|
|
||
| .globaltype __stack_pointer, PTR | ||
| .globaltype __stack_end, PTR | ||
| .globaltype __stack_base, PTR | ||
|
|
||
| .globl _emscripten_wasm_worker_initialize | ||
| _emscripten_wasm_worker_initialize: | ||
| .functype _emscripten_wasm_worker_initialize (PTR /*stackLowestAddress*/, i32 /*stackSize*/) -> () | ||
|
|
||
| // __stack_end = stackLowestAddress + (__builtin_wasm_tls_size() + 15) & -16; | ||
| local.get 0 | ||
| .globaltype __tls_size, PTR, immutable | ||
| global.get __tls_size | ||
| PTR.add | ||
| PTR.const 0xf | ||
| PTR.add | ||
| PTR.const -0x10 | ||
| PTR.and | ||
| global.set __stack_end | ||
|
|
||
| // __stack_base = stackLowestAddress + stackSize; | ||
| local.get 0 | ||
| local.get 1 | ||
| #ifdef __wasm64__ | ||
| i64.extend_i32_u | ||
| #endif | ||
| PTR.add | ||
| global.set __stack_base | ||
|
|
||
| // TODO: We'd like to do this here to avoid JS side calls to __set_stack_limits. | ||
| // (or even better, we'd like to avoid duplicate versions of the stack variables) | ||
| // See https://github.com/emscripten-core/emscripten/issues/16496 | ||
| // global.get __stack_base | ||
| // global.get __stack_end | ||
| // .functype __set_stack_limits (PTR, PTR) -> () | ||
| // call __set_stack_limits | ||
|
|
||
| // __wasm_init_tls(stackLowestAddress); | ||
| local.get 0 | ||
| .functype __wasm_init_tls (PTR) -> () | ||
| call __wasm_init_tls | ||
|
|
||
| // N.b. The function __wasm_init_tls above does not need | ||
| // __stack_pointer initialized, and it destroys the value it was set to. | ||
| // So we must initialize __stack_pointer only *after* completing __wasm_init_tls: | ||
|
|
||
| // __stack_pointer = __stack_base; | ||
| global.get __stack_base | ||
| global.set __stack_pointer | ||
|
|
||
| end_function | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| hello world… | ||
| hello world… |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| first | ||
| result: 1 1 | ||
| second | ||
| result: 2 -1 | ||
| result: 2 -1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -725,7 +725,7 @@ def get_cflags(self): | |
| if self.is_mt: | ||
| cflags += ['-pthread', '-sWASM_WORKERS'] | ||
| if self.is_ww: | ||
| cflags += ['-sWASM_WORKERS'] | ||
| cflags += ['-sSHARED_MEMORY=1'] | ||
|
||
| return cflags | ||
|
|
||
| def get_base_name(self): | ||
|
|
@@ -742,12 +742,17 @@ def vary_on(cls): | |
|
|
||
| @classmethod | ||
| def get_default_variation(cls, **kwargs): | ||
| return super().get_default_variation(is_mt=settings.PTHREADS, is_ww=settings.WASM_WORKERS and not settings.PTHREADS, **kwargs) | ||
| return super().get_default_variation( | ||
| is_mt=settings.PTHREADS, | ||
| is_ww=settings.SHARED_MEMORY and not settings.PTHREADS, | ||
| **kwargs | ||
| ) | ||
|
|
||
| @classmethod | ||
| def variations(cls): | ||
| combos = super(MTLibrary, cls).variations() | ||
| # To save on # of variations, pthreads and Wasm workers when used together, just use pthreads variation. | ||
|
|
||
| # These are mutually exclusive, only one flag will be set at any give time. | ||
| return [combo for combo in combos if not combo['is_mt'] or not combo['is_ww']] | ||
|
|
||
|
|
||
|
|
@@ -1420,6 +1425,8 @@ def __init__(self, **kwargs): | |
|
|
||
| def get_cflags(self): | ||
| cflags = super().get_cflags() | ||
| if self.is_ww: | ||
| cflags += ['-sWASM_WORKERS'] | ||
|
||
| if self.debug: | ||
| cflags += ['-D_DEBUG'] | ||
| # library_wasm_worker.c contains an assert that a nonnull parameter | ||
|
|
@@ -1452,9 +1459,19 @@ def get_default_variation(cls, **kwargs): | |
| return super().get_default_variation(debug=settings.ASSERTIONS >= 1, **kwargs) | ||
|
|
||
| def get_files(self): | ||
| files = [] | ||
| if self.is_ww: | ||
| files = [ | ||
| 'library_wasm_worker.c', | ||
| 'wasm_worker.S', | ||
| ] | ||
| else: | ||
| files = [ | ||
| 'library_wasm_worker_stub.c' | ||
| ] | ||
| return files_in_path( | ||
| path='system/lib/wasm_worker', | ||
| filenames=['library_wasm_worker.c' if self.is_ww or self.is_mt else 'library_wasm_worker_stub.c']) | ||
| filenames=files) | ||
sbc100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def can_use(self): | ||
| # see src/library_wasm_worker.js | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love that these are now globals symbols...I wish we could find a way to avoid the need for divergence here between wasm workers and pthreads, but for now this seems reasonable.