github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/scripts/build-x86.sh (about) 1 #!/bin/bash 2 3 # Define the directories 4 SRC_DIR="native" 5 TMP_DIR="output" 6 OUT_DIR="internal/native" 7 TOOL_DIR="tools/asm2asm" 8 TMPL_DIR="internal/native" 9 CC=clang 10 if [ "$1" != "" ]; then 11 CC=$1 12 fi 13 echo $CC 14 15 CPU_ARCS=("sse" "avx" "avx2") 16 CLAGS=( 17 "-msse -mno-sse4 -mno-avx -mno-avx2 -mpclmul" 18 "-mno-sse4 -mavx -mpclmul -mno-avx2 -DUSE_AVX=1 -DUSE_AVX2=0" 19 "-mno-sse4 -mavx -mpclmul -mavx2 -DUSE_AVX=1 -DUSE_AVX2=1" 20 ) 21 22 i=0 23 for arc in "${CPU_ARCS[@]}"; do 24 echo "arch: $arc" 25 # Create the output directory if it doesn't exist 26 out_dir="$OUT_DIR/$arc" 27 tmp_dir="$TMP_DIR/$arc" 28 mkdir -p $out_dir 29 mkdir -p $tmp_dir 30 31 # all tmplates 32 for tmpl in "$TMPL_DIR"/*.tmpl; do 33 tmpl_name=$(basename "$tmpl" .tmpl) 34 sed -e 's/{{PACKAGE}}/'${arc}'/g' $tmpl > "$out_dir/${tmpl_name}.go" 35 done 36 37 # all .c files in the source directory 38 for src_file in "$SRC_DIR"/*.c; do 39 base_name=$(basename "$src_file" .c) 40 asm_file="$tmp_dir/${base_name}.s" 41 42 # Compile the source file into an assembly file 43 echo "$CC ${CLAGS[$i]} -m -target x86_64-apple-macos11 -mno-red-zone -mstack-alignment=0 -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -S -o $asm_file $src_file" 44 $CC ${CLAGS[$i]} -target x86_64-apple-macos11 -mno-red-zone -fno-asynchronous-unwind-tables -fno-builtin -fno-exceptions -fno-rtti -fno-stack-protector -nostdlib -O3 -Wall -Werror -S -o $asm_file $src_file 45 46 # Execute asm2asm tool 47 echo "python3 $TOOL_DIR/asm2asm.py -r $out_dir/${base_name}.go $asm_file" 48 python3 $TOOL_DIR/asm2asm.py -r $out_dir/${base_name}.go $asm_file 49 50 done 51 52 ((i++)) 53 54 done