Implement the segue optimization for LLVM AOT/JIT (#2230)
Segue is an optimization technology which uses x86 segment register to store the WebAssembly linear memory base address, so as to remove most of the cost of SFI (Software-based Fault Isolation) base addition and free up a general purpose register, by this way it may: - Improve the performance of JIT/AOT - Reduce the footprint of JIT/AOT, the JIT/AOT code generated is smaller - Reduce the compilation time of JIT/AOT This PR uses the x86-64 GS segment register to apply the optimization, currently it supports linux and linux-sgx platforms on x86-64 target. By default it is disabled, developer can use the option below to enable it for wamrc and iwasm(with LLVM JIT enabled): ```bash wamrc --enable-segue=[<flags>] -o output_file wasm_file iwasm --enable-segue=[<flags>] wasm_file [args...] ``` `flags` can be: i32.load, i64.load, f32.load, f64.load, v128.load, i32.store, i64.store, f32.store, f64.store, v128.store Use comma to separate them, e.g. `--enable-segue=i32.load,i64.store`, and `--enable-segue` means all flags are added. Acknowledgement: Many thanks to Intel Labs, UC San Diego and UT Austin teams for introducing this technology and the great support and guidance! Signed-off-by: Wenyong Huang <wenyong.huang@intel.com> Co-authored-by: Vahldiek-oberwagner, Anjo Lucas <anjo.lucas.vahldiek-oberwagner@intel.com>
This commit is contained in:
@ -16,6 +16,8 @@ libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chac
|
||||
sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \
|
||||
xchacha20"
|
||||
|
||||
PLATFORM=$(uname -s | tr A-Z a-z)
|
||||
|
||||
readonly WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc
|
||||
readonly OUT_DIR=$PWD/libsodium/zig-out/bin
|
||||
|
||||
@ -34,9 +36,16 @@ zig build -Drelease-fast -Denable_benchmarks=true -Dtarget=wasm32-wasi
|
||||
for case in ${libsodium_CASES}
|
||||
do
|
||||
${WAMRC_CMD} -o ${OUT_DIR}/${case}.aot ${OUT_DIR}/${case}.wasm
|
||||
|
||||
if [ "$?" != 0 ]; then
|
||||
echo -e "Error while compiling ${case}.wasm to ${case}.aot"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ ${PLATFORM} == "linux" ]]; then
|
||||
${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/${case}_segue.aot ${OUT_DIR}/${case}.wasm
|
||||
if [ "$?" != 0 ]; then
|
||||
echo -e "Error while compiling ${case}.wasm to ${case}_segue.aot"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
@ -13,12 +13,14 @@ libsodium_CASES="aead_aes256gcm2 aead_aes256gcm aead_chacha20poly13052 aead_chac
|
||||
scalarmult6 scalarmult7 scalarmult8 scalarmult_ed25519 scalarmult_ristretto255 \
|
||||
scalarmult secretbox2 secretbox7 secretbox8 secretbox_easy2 secretbox_easy \
|
||||
secretbox secretstream shorthash sign siphashx24 sodium_core sodium_utils2 \
|
||||
sodium_utils3 sodium_utils sodium_version stream2 stream3 stream4 stream verify1 \
|
||||
xchacha20"
|
||||
sodium_utils stream2 stream3 stream4 stream verify1 xchacha20"
|
||||
|
||||
PLATFORM=$(uname -s | tr A-Z a-z)
|
||||
|
||||
readonly OUT_DIR=$PWD/libsodium/zig-out/bin
|
||||
readonly REPORT=$PWD/report.txt
|
||||
readonly IWASM_CMD=$PWD/../../../product-mini/platforms/linux/build/iwasm
|
||||
readonly IWASM_CMD=$PWD/../../../product-mini/platforms/${PLATFORM}/build/iwasm
|
||||
readonly TIME=/usr/bin/time
|
||||
|
||||
BENCH_NAME_MAX_LEN=20
|
||||
|
||||
@ -40,7 +42,11 @@ function print_bench_name()
|
||||
# run benchmarks
|
||||
cd $OUT_DIR
|
||||
|
||||
echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT
|
||||
if [[ ${PLATFORM} == "linux" ]]; then
|
||||
echo -en "\t\t\t\t\t\tnative\tiwasm-aot\tiwasm-aot-segue\n" >> $REPORT
|
||||
else
|
||||
echo -en "\t\t\t\t\t\tnative\tiwasm-aot\n" >> $REPORT
|
||||
fi
|
||||
|
||||
for t in $libsodium_CASES
|
||||
do
|
||||
@ -48,11 +54,38 @@ do
|
||||
|
||||
echo "run $t with native..."
|
||||
echo -en "\t" >> $REPORT
|
||||
./${t} | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
|
||||
if [[ $t != "sodium_utils2" ]]; then
|
||||
./${t} | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT
|
||||
else
|
||||
# sodium_utils2 doesn't print the result,
|
||||
# use time command to get result instead
|
||||
$TIME -f "real-%e-time" ./${t} 2>&1 | grep "real-.*-time" |
|
||||
awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT
|
||||
fi
|
||||
|
||||
echo "run $t with iwasm aot..."
|
||||
echo -en "\t \t" >> $REPORT
|
||||
$IWASM_CMD ${t}.aot | awk -F '-' 'BEGIN{FIELDWIDTHS="10"}{ORS=""; print $1 / 1000000.0}' >> $REPORT
|
||||
if [[ $t != "sodium_utils2" ]]; then
|
||||
$IWASM_CMD ${t}.aot | awk '{printf "%-10.2f", $0/1000000.0}' >> $REPORT
|
||||
else
|
||||
# sodium_utils2 doesn't print the result,
|
||||
# use time command to get result instead
|
||||
$TIME -f "real-%e-time" $IWASM_CMD ${t}.aot 2>&1 | grep "real-.*-time" |
|
||||
awk -F '-' '{printf "%-10.2f", $2}' >> $REPORT
|
||||
fi
|
||||
|
||||
if [[ ${PLATFORM} == "linux" ]]; then
|
||||
echo "run $t with iwasm aot segue..."
|
||||
echo -en "\t \t" >> $REPORT
|
||||
if [[ $t != "sodium_utils2" ]]; then
|
||||
$IWASM_CMD ${t}_segue.aot | awk '{printf "%.2f", $0/1000000.0}' >> $REPORT
|
||||
else
|
||||
# sodium_utils2 doesn't print the result,
|
||||
# use time command to get result instead
|
||||
$TIME -f "real-%e-time" $IWASM_CMD ${t}_segue.aot 2>&1 | grep "real-.*-time" |
|
||||
awk -F '-' '{printf "%.2f", $2}' >> $REPORT
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -en "\n" >> $REPORT
|
||||
done
|
||||
Reference in New Issue
Block a user