-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_wasmsimd.sh
executable file
·76 lines (65 loc) · 2.53 KB
/
build_wasmsimd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
if [ "$WORK_DIR" == "" ]; then
WORK_DIR=/home/wrv/research/wasmperf
fi
if [ "$WASI_SDK_PATH" == "" ]; then
WASI_SDK_PATH=${WORK_DIR}/wasi-sdk-21.0
fi
if [ "$SIMDE_PATH" == "" ]; then
SIMDE_PATH=${WORK_DIR}/simde-0.8.2
fi
echo Before: "$WASMSIMD_COMPILER_DEFINES"
if [ "$WASMSIMD_COMPILER_DEFINES" == "" ]; then
# Default to all existing optimizations
WASMSIMD_COMPILER_DEFINES=""
# Enable 64-bit registers in WASM
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DBITS=56"
# Use the hardcoded tree approach
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DUSE_GENERIC_TREE=0"
# Avoid indirect function calls by renaming functions
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DWEBP_WASM_DIRECT_FUNCTION_CALL -DWEBP_WASMSIMD_DIRECT_FUNCTION_CALL"
# Mimic WEBP_RESTRICT by aliasing VP8BitReader in VP8ParseIntraModeRow
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DWEBP_WASM_ALIAS_VP8PARSEINTRAMODEROW"
# Use VP8L Fast Loads to load 32 bits at time
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DVP8L_USE_FAST_LOAD"
# Enable direct calls in VP8L
WASMSIMD_COMPILER_DEFINES="${WASMSIMD_COMPILER_DEFINES} -DWEBP_WASM_DIRECT_FUNCTION_CALL -DWEBP_WASMSIMD_DIRECT_FUNCTION_CALL"
fi
echo After: "$WASMSIMD_COMPILER_DEFINES"
echo "Building WASMSIMD version of libwebp"
curprefix=$(pwd)/libwebp_wasmsimd
mkdir -p ${curprefix}
cd ${curprefix}
# If we're trying to recompile without changing the code, but changing
# only the feature flags, it won't work, so we clean it out :/
make clean
CFLAGS="-O2 ${WASMSIMD_COMPILER_DEFINES} -D_WASI_EMULATED_SIGNAL \
-msimd128 -DSIMDE_FLOAT16_API=1 -DWEBP_USE_SIMDE -DSIMDE_ENABLE_NATIVE_ALIASES -I${SIMDE_PATH}" \
LDFLAGS="-L${WASI_SDK_PATH}/share/wasi-sysroot/lib \
-Wl,--no-entry \
-Wl,--export-all \
-Wl,--growable-table $*" \
LD=${WASI_SDK_PATH}/bin/wasm-ld \
CC=${WASI_SDK_PATH}/bin/clang \
AR=${WASI_SDK_PATH}/bin/ar \
LIBS=-lwasi-emulated-signal \
STRIP=${WASI_SDK_PATH}/bin/strip \
RANLIB=${WASI_SDK_PATH}/bin/ranlib \
../configure \
--with-sysroot=${WASI_SDK_PATH}/share/wasi-sysroot \
--host=wasm64 \
--prefix=${curprefix} \
--disable-libwebpdemux \
--disable-libwebpmux \
--disable-libwebpdecoder \
--disable-png \
--disable-tiff \
--disable-jpeg \
--disable-threading \
--enable-sse4.1 \
--enable-sse2
# Apply patch to enable SSE4.1 and SSE2
sed -i 's|/\* #undef WEBP_HAVE_SSE41 \*/|#define WEBP_HAVE_SSE41 1|' src/webp/config.h
sed -i 's|/\* #undef WEBP_HAVE_SSE2 \*/|#define WEBP_HAVE_SSE2 1|' src/webp/config.h
make
make install
cd ..