build.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/bin/bash
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. source /opt/emsdk/emsdk_env.sh
  5. PLATFORM=$(uname -s | tr A-Z a-z)
  6. OUT_DIR=$PWD/out
  7. WAMRC_CMD=$PWD/../../../wamr-compiler/build/wamrc
  8. mkdir -p jetstream
  9. mkdir -p tsf-src
  10. mkdir -p ${OUT_DIR}
  11. if [[ $1 != "--no-simd" ]];then
  12. NATIVE_SIMD_FLAGS="-msse2 -msse3 -msse4"
  13. WASM_SIMD_FLAGS="-msimd128 -msse2 -msse3 -msse4"
  14. else
  15. NATIVE_SIMD_FLAGS=""
  16. WASM_SIMD_FLAGS=""
  17. fi
  18. cd jetstream
  19. echo "Download source files .."
  20. wget -N https://browserbench.org/JetStream/wasm/gcc-loops.cpp
  21. wget -N https://browserbench.org/JetStream/wasm/quicksort.c
  22. wget -N https://browserbench.org/JetStream/wasm/HashSet.cpp
  23. wget -N https://browserbench.org/JetStream/simple/float-mm.c
  24. if [[ $? != 0 ]]; then
  25. exit
  26. fi
  27. echo "Patch source files .."
  28. patch -p1 -N < ../jetstream.patch
  29. echo "Build gcc-loops with g++ .."
  30. g++ -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/gcc-loops_native gcc-loops.cpp
  31. echo "Build gcc-loops with em++ .."
  32. em++ -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \
  33. -s INITIAL_MEMORY=1048576 \
  34. -s TOTAL_STACK=32768 \
  35. -s "EXPORTED_FUNCTIONS=['_main']" \
  36. -s ERROR_ON_UNDEFINED_SYMBOLS=0 \
  37. -o ${OUT_DIR}/gcc-loops.wasm gcc-loops.cpp
  38. echo "Compile gcc-loops.wasm to gcc-loops.aot"
  39. ${WAMRC_CMD} -o ${OUT_DIR}/gcc-loops.aot ${OUT_DIR}/gcc-loops.wasm
  40. if [[ ${PLATFORM} == "linux" ]]; then
  41. echo "Compile gcc-loops.wasm to gcc-loops_segue.aot"
  42. ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/gcc-loops_segue.aot ${OUT_DIR}/gcc-loops.wasm
  43. fi
  44. echo "Build quicksort with gcc .."
  45. gcc -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/quicksort_native quicksort.c
  46. echo "Build quicksort with emcc .."
  47. emcc -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \
  48. -s INITIAL_MEMORY=1048576 \
  49. -s TOTAL_STACK=32768 \
  50. -s "EXPORTED_FUNCTIONS=['_main']" \
  51. -o ${OUT_DIR}/quicksort.wasm quicksort.c
  52. echo "Compile quicksort.wasm to quicksort.aot"
  53. ${WAMRC_CMD} -o ${OUT_DIR}/quicksort.aot ${OUT_DIR}/quicksort.wasm
  54. if [[ ${PLATFORM} == "linux" ]]; then
  55. echo "Compile quicksort.wasm to quicksort_segue.aot"
  56. ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/quicksort_segue.aot ${OUT_DIR}/quicksort.wasm
  57. fi
  58. echo "Build HashSet with g++ .."
  59. g++ -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/HashSet_native HashSet.cpp \
  60. -lstdc++
  61. echo "Build HashSet with em++ .."
  62. em++ -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \
  63. -s INITIAL_MEMORY=1048576 \
  64. -s TOTAL_STACK=32768 \
  65. -s "EXPORTED_FUNCTIONS=['_main']" \
  66. -o ${OUT_DIR}/HashSet.wasm HashSet.cpp
  67. echo "Compile HashSet.wasm to HashSet.aot"
  68. ${WAMRC_CMD} -o ${OUT_DIR}/HashSet.aot ${OUT_DIR}/HashSet.wasm
  69. if [[ ${PLATFORM} == "linux" ]]; then
  70. echo "Compile HashSet.wasm to HashSet_segue.aot"
  71. ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/HashSet_segue.aot ${OUT_DIR}/HashSet.wasm
  72. fi
  73. echo "Build float-mm with gcc .."
  74. gcc -O3 ${NATIVE_SIMD_FLAGS} -o ${OUT_DIR}/float-mm_native float-mm.c
  75. echo "Build float-mm with emcc .."
  76. emcc -O3 -s STANDALONE_WASM=1 ${WASM_SIMD_FLAGS} \
  77. -s INITIAL_MEMORY=1048576 \
  78. -s TOTAL_STACK=32768 \
  79. -s "EXPORTED_FUNCTIONS=['_main']" \
  80. -o ${OUT_DIR}/float-mm.wasm float-mm.c
  81. echo "Compile float-mm.wasm to float-mm.aot"
  82. ${WAMRC_CMD} -o ${OUT_DIR}/float-mm.aot ${OUT_DIR}/float-mm.wasm
  83. if [[ ${PLATFORM} == "linux" ]]; then
  84. echo "Compile float-mm.wasm to float-mm_segue.aot"
  85. ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/float-mm_segue.aot ${OUT_DIR}/float-mm.wasm
  86. fi
  87. cd ../tsf-src
  88. tsf_srcs="tsf_asprintf.c tsf_buffer.c tsf_error.c tsf_reflect.c tsf_st.c \
  89. tsf_type.c tsf_io.c tsf_native.c tsf_generator.c tsf_st_typetable.c \
  90. tsf_parser.c tsf_buf_writer.c tsf_buf_reader.c tsf_primitive.c \
  91. tsf_type_table.c tsf_copier.c tsf_destructor.c tsf_gpc_code_gen.c \
  92. gpc_code_gen_util.c gpc_threaded.c gpc_intable.c gpc_instruction.c \
  93. gpc_program.c gpc_proto.c gpc_stack_height.c tsf_serial_in_man.c \
  94. tsf_serial_out_man.c tsf_type_in_map.c tsf_type_out_map.c \
  95. tsf_stream_file_input.c tsf_stream_file_output.c tsf_sort.c \
  96. tsf_version.c tsf_named_type.c tsf_io_utils.c tsf_zip_attr.c \
  97. tsf_zip_reader.c tsf_zip_writer.c tsf_zip_abstract.c tsf_limits.c \
  98. tsf_ra_type_man.c tsf_adaptive_reader.c tsf_sha1.c tsf_sha1_writer.c \
  99. tsf_fsdb.c tsf_fsdb_protocol.c tsf_define_helpers.c tsf_ir.c \
  100. tsf_ir_different.c tsf_ir_speed.c"
  101. tsf_files="${tsf_srcs} config.h gpc_worklist.h \
  102. tsf_config_stub.h tsf.h tsf_internal.h tsf_region.h tsf_types.h \
  103. gpc.h tsf_atomics.h tsf_define_helpers.h tsf_indent.h tsf_inttypes.h \
  104. tsf_serial_protocol.h tsf_util.h gpc_int_common.h tsf_build_defines.h \
  105. tsf_format.h tsf_internal_config.h tsf_ir_different.h tsf_sha1.h \
  106. tsf_zip_abstract.h gpc_internal.h tsf_config.h tsf_fsdb_protocol.h \
  107. tsf_internal_config_stub.h tsf_ir.h tsf_st.h \
  108. gpc_instruction_dispatch.gen gpc_instruction_stack_effects.gen \
  109. gpc_instruction_to_string.gen gpc_instruction_size.gen \
  110. gpc_instruction_static_size.gen gpc_interpreter.gen"
  111. echo "Download tsf source files .."
  112. for t in ${tsf_files}
  113. do
  114. wget -N "https://browserbench.org/JetStream/wasm/TSF/${t}"
  115. if [[ $? != 0 ]]; then
  116. exit
  117. fi
  118. done
  119. patch -p1 -N < ../tsf.patch
  120. echo "Build tsf with gcc .."
  121. gcc \
  122. -o ${OUT_DIR}/tsf_native -O3 ${NATIVE_SIMD_FLAGS} \
  123. -I. -DTSF_BUILD_SYSTEM=1 \
  124. ${tsf_srcs} -lm
  125. echo "Build tsf standalone with wasi-sdk .."
  126. /opt/wasi-sdk/bin/clang -O3 ${WASM_SIMD_FLAGS} -z stack-size=1048576 \
  127. -Wl,--initial-memory=52428800 \
  128. -Wl,--export=main \
  129. -Wl,--export=__heap_base,--export=__data_end \
  130. -I. -DTSF_BUILD_SYSTEM=1 \
  131. -Wl,--allow-undefined \
  132. -o ${OUT_DIR}/tsf.wasm \
  133. ${tsf_srcs}
  134. echo "Compile tsf.wasm to tsf.aot"
  135. ${WAMRC_CMD} -o ${OUT_DIR}/tsf.aot ${OUT_DIR}/tsf.wasm
  136. if [[ ${PLATFORM} == "linux" ]]; then
  137. echo "Compile tsf.wasm to tsf_segue.aot"
  138. ${WAMRC_CMD} --enable-segue -o ${OUT_DIR}/tsf_segue.aot ${OUT_DIR}/tsf.wasm
  139. fi