go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

build-native-bench-libs.sh (2017B)


      1 #!/bin/sh
      2 #
      3 # Build two native shared objects from the vendored c-lib source, for the
      4 # benchmark harness in ./bench:
      5 #
      6 #   libwebp_simd.so    normal build — SSE2/SSE4.1 kernels, runtime dispatch
      7 #   libwebp_scalar.so  SIMD disabled, matching how tools/transpile.sh and the
      8 #                      wasm builds are configured
      9 #
     10 # The scalar one exists so the benchmark can separate the cost of a sandbox or
     11 # a transpiler from the cost of simply not having SIMD.
     12 
     13 set -eux
     14 
     15 HERE=$(cd "$(dirname "$0")" && pwd)
     16 SRC=$HERE/../c-lib
     17 OUT=${OUT:-$HERE/../bench/lib}
     18 mkdir -p "$OUT"
     19 
     20 # dsp.h only honours WEBP_HAVE_SSE2 when HAVE_CONFIG_H is set, so an empty
     21 # config.h is how the scalar build turns SIMD off. On x86-64 __SSE2__ is
     22 # always defined and -mno-sse2 is not a legal option, so this is the only way.
     23 INC=$(mktemp -d)
     24 mkdir -p "$INC/src/webp"
     25 # HAVE_BUILTIN_BSWAP* matter: endian_inl_utils.h only probes for the builtins
     26 # when HAVE_CONFIG_H is absent, so without these libwebp falls back to x86
     27 # inline asm, which ccgo turns into a runtime assertion that fires on the
     28 # first lossy decode. A real autotools configure detects these too.
     29 cat > "$INC/src/webp/config.h" <<'CONFIG'
     30 #define HAVE_BUILTIN_BSWAP16 1
     31 #define HAVE_BUILTIN_BSWAP32 1
     32 #define HAVE_BUILTIN_BSWAP64 1
     33 CONFIG
     34 trap 'rm -rf "$INC" "$OBJ"' EXIT
     35 
     36 build() {
     37     name=$1
     38     shift
     39     OBJ=$(mktemp -d)
     40     cd "$SRC"
     41     # sharpyuv is a separate top-level library since libwebp 1.3.
     42     for f in src/dec/*.c src/enc/*.c src/utils/*.c src/dsp/*.c sharpyuv/*.c; do
     43         extra=""
     44         # Vector kernels need their instruction set enabled on their own TU.
     45         case "$f:$name" in
     46             *_sse41.c:simd) extra="-msse4.1" ;;
     47             *_avx2.c:simd) extra="-mavx2" ;;
     48         esac
     49         gcc -O3 -fPIC -DNDEBUG -I"$SRC" "$@" $extra -c "$f" \
     50             -o "$OBJ/$(echo "$f" | tr / _).o"
     51     done
     52     gcc -shared -o "$OUT/libwebp_$name.so" "$OBJ"/*.o -lm
     53     rm -rf "$OBJ"
     54 }
     55 
     56 build simd
     57 build scalar -DHAVE_CONFIG_H -I"$INC"
     58 
     59 ls -la "$OUT"