Skip to content

Commit cc6f53e

Browse files
[wasm][stdlib] Add wasi-libc support for Heap.cpp
Pointers returned by malloc() are 16-byte aligned on wasi-libc, even it's 32-bit architecture. See wasi-libc's dlmalloc configuration: https://github.com/WebAssembly/wasi-libc/blob/aecd368c6dedc417037afa136139eccc4490e56e/dlmalloc/src/dlmalloc.c#L31
1 parent 964a51f commit cc6f53e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stdlib/public/runtime/Heap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ using namespace swift;
3232
/// On Apple platforms, \c malloc() is always 16-byte aligned.
3333
static constexpr size_t MALLOC_ALIGN_MASK = 15;
3434

35-
#elif defined(__linux__) || defined(_WIN32)
35+
#elif defined(__linux__) || defined(_WIN32) || defined(__wasi__)
3636
/// On Linux and Windows, \c malloc() returns 16-byte aligned pointers on 64-bit
3737
/// and 8-byte aligned pointers on 32-bit.
38-
#if defined(__LP64) || defined(_WIN64)
38+
/// On wasi-libc, pointers are 16-byte aligned even though 32-bit for SIMD access.
39+
#if defined(__LP64) || defined(_WIN64) || defined(__wasi__)
3940
static constexpr size_t MALLOC_ALIGN_MASK = 15;
4041
#else
4142
static constexpr size_t MALLOC_ALIGN_MASK = 7;

0 commit comments

Comments
 (0)