-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add implementation of emscripten_memcpy_big based on bulk memory. #19128
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifdef __wasm64__ | ||
#define PTR i64 | ||
#else | ||
#define PTR i32 | ||
#endif | ||
|
||
.globl emscripten_memcpy_big | ||
emscripten_memcpy_big: | ||
.functype emscripten_memcpy_big (PTR, PTR, PTR) -> () | ||
local.get 0 | ||
local.get 1 | ||
local.get 2 | ||
memory.copy 0, 0 | ||
end_function |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,44 @@ | ||
// XXX EMSCRIPTEN ASAN: build an uninstrumented version of memset | ||
#if defined(__EMSCRIPTEN__) && defined(__has_feature) | ||
#if __has_feature(address_sanitizer) | ||
#define memset __attribute__((no_sanitize("address"))) emscripten_builtin_memset | ||
sbc100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
#include "emscripten_internal.h" // for emscripten_memset_big | ||
|
||
#if defined(__has_feature) && __has_feature(address_sanitizer) | ||
// build an uninstrumented version of memset | ||
__attribute__((no_sanitize("address"))) void *__musl_memset(void *str, int c, size_t n); | ||
__attribute__((no_sanitize("address"))) void *__memset(void *str, int c, size_t n); | ||
#endif | ||
|
||
#ifdef EMSCRIPTEN_OPTIMIZE_FOR_OZ | ||
__attribute__((__weak__)) void *__musl_memset(void *str, int c, size_t n); | ||
__attribute__((__weak__)) void *__memset(void *str, int c, size_t n); | ||
|
||
#include <stddef.h> | ||
#ifdef EMSCRIPTEN_OPTIMIZE_FOR_OZ | ||
|
||
void *memset(void *str, int c, size_t n) { | ||
void *__memset(void *str, int c, size_t n) { | ||
unsigned char *s = (unsigned char *)str; | ||
#pragma clang loop unroll(disable) | ||
while(n--) *s++ = c; | ||
return str; | ||
} | ||
|
||
#elif defined(__wasm_bulk_memory__) | ||
|
||
#define memset __musl_memset | ||
#include "musl/src/string/memset.c" | ||
#undef memset | ||
|
||
void *__memset(void *str, int c, size_t n) { | ||
if (n >= 512) { | ||
emscripten_memset_big(str, c, n); | ||
return str; | ||
} | ||
return __musl_memset(str, c, n); | ||
} | ||
|
||
#else | ||
|
||
#define memset __memset | ||
#include "musl/src/string/memset.c" | ||
#undef memset | ||
|
||
#endif | ||
|
||
weak_alias(__memset, emscripten_builtin_memset); | ||
weak_alias(__memset, memset); |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifdef __wasm64__ | ||
#define PTR i64 | ||
#else | ||
#define PTR i32 | ||
#endif | ||
|
||
.globl emscripten_memset_big | ||
emscripten_memset_big: | ||
.functype emscripten_memset_big (PTR, i32, PTR) -> () | ||
local.get 0 | ||
local.get 1 | ||
local.get 2 | ||
memory.fill 0 | ||
end_function |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
const char *hello = "hello"; | ||
const char *world = "world"; | ||
|
||
int main() { | ||
char buffer[100]; | ||
memset(buffer, 'a', 100); | ||
memcpy(buffer, hello, strlen(hello) + 1); | ||
assert(strcmp(buffer, hello) == 0); | ||
return 0; | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.