- Investigating clang's handling of memory builtins and bulk memory code generation in test/bulkmem

- Using bulk memory (via builtins) for memset/memcpy/memcmp
- Change build script to build wasm3 with optimizations on
This commit is contained in:
Martin Fouilleul 2023-06-25 17:31:24 +02:00
parent d0ad92f0b8
commit abb37537e9
4 changed files with 64 additions and 1 deletions

View File

@ -31,7 +31,7 @@ elif [ $target = wasm3 ] ; then
for file in ./ext/wasm3/source/*.c ; do
name=$(basename $file)
name=${name/.c/.o}
clang -c -g -foptimize-sibling-calls -Wno-extern-initializer -Dd_m3VerboseErrorMessages -o ./bin/obj/$name -I./ext/wasm3/source $file
clang -c -g -O2 -foptimize-sibling-calls -Wno-extern-initializer -Dd_m3VerboseErrorMessages -o ./bin/obj/$name -I./ext/wasm3/source $file
done
ar -rcs ./bin/libwasm3.a ./bin/obj/*.o
rm -rf ./bin/obj

View File

@ -18,6 +18,7 @@ wasmFlags="--target=wasm32 \
-Wl,--export-dynamic \
-g \
-O2 \
-mbulk-memory \
-D__ORCA__ \
-isystem ../../cstdlib/include -I ../../sdk -I../../milepost/ext -I ../../milepost -I ../../milepost/src -I ../../milepost/src/util -I ../../milepost/src/platform -I../.."

24
test/bulkmem/build.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail
if [[ -x /usr/local/opt/llvm/bin/clang ]]; then
CLANG=/usr/local/opt/llvm/bin/clang
elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then
CLANG=/opt/homebrew/opt/llvm/bin/clang
else
echo "Could not find Homebrew clang; this script will probably not work."
CLANG=clang
fi
wasmFlags="--target=wasm32 \
--no-standard-libraries \
-Wl,--no-entry \
-Wl,--export-all \
-Wl,--allow-undefined \
-g \
-mbulk-memory"
$CLANG $wasmFlags -o ./module.wasm main.c
wasm2wat module.wasm > module.wat

38
test/bulkmem/main.c Normal file
View File

@ -0,0 +1,38 @@
/************************************************************//**
*
* @file: main.c
* @author: Martin Fouilleul
* @date: 25/06/2023
*
*****************************************************************/
#include<stddef.h>
#include<stdint.h>
void* memset(void* b, int c, size_t n)
{
return(__builtin_memset(b, c, n));
}
void* memcpy(void* dst, const void* src, size_t n)
{
return(__builtin_memcpy(dst, src, n));
}
int _start()
{
uint8_t buffer[1024];
uint8_t dst[1024];
memset(buffer, 0xff, 1024);
if(buffer[32] != 0xff)
{
__builtin_unreachable();
}
memcpy(dst, buffer, 1024);
if(dst[32] != 0xff)
{
__builtin_unreachable();
}
return(0);
}