skia2/modules/canvaskit/wasm_tools/SIMD/build_simd_test.sh
Elliot Evans fe7e74b3a7 Add an experimental_simd build target to CanvasKit.
The `experimental_simd` build target builds
CanvasKit using the Emscripten `-msimd128` flag, to build CanvasKit
with SIMD instructions in the compiled WASM. This build of
CanvasKit works in Chrome Canary 86.0.4186.0
with chrome://flags#enable-webassembly-simd enabled.

Also add WebAssembly-specific intrinsics to SkVx.h to enable
support for almost all native SIMD operations in CanvasKit WebAssmebly.

Also add a Skia/modules/canvaskit/wasm_tools/SIMD folder which contains
build_simd_test.sh for testing whether WASM SIMD intrinsics operations
are actually being used by skvx, and for testing correctness of
WASM SIMD operations. Also contains simd_float_test.cpp and
simd_int_test.cpp which serve as documentation for which operations are
correctly turned into WASM SIMD operations by emscripten.

Bug: skia:10453
Change-Id: Icd312b4d189e8d8667d3ffe12a72bfa6febaab2f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299705
Reviewed-by: Mike Klein <mtklein@google.com>
2020-06-30 22:52:31 +00:00

32 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2020 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Requires that emscripten and wasm2wat are added to your PATH.
# Requires, and is verified to work with
# - wasm2wat 1.0.13 (1.0.17)
# - install from here: https://github.com/WebAssembly/wabt
# - emscripten 1.39.16
# - Chrome Canary 86.0.4186.0 with chrome://flags#enable-webassembly-simd enabled
#
# Example usage: ./build_simd_test.sh simd_float_test.cpp
# build the file specified as the first argument with SIMD enabled.
em++ $1 -I ../../../../ -msimd128 -Os -s WASM=1 -o output/simd_test.html
# convert the output WASM to a human readable text format (.wat)
wasm2wat --enable-simd output/simd_test.wasm > output/simd_test.wat
# The following lines output all SIMD operations produced in the output WASM.
# Useful for checking that SIMD instructions are actually being used.
# e.g. for the following C++ code:
# auto vec1 = skvx::Vec<2, double>({11.f, -22.f}) + skvx::Vec<2, double>({13.f, -1.f});
# it is expected that the f64x2.add operation is present in the output WASM.
echo "The following WASM SIMD operations were used in the compiled code:"
grep -f wasm_simd_types.txt output/simd_test.wat
# Serve the compiled WASM so output can be manually inspected for correctness.
echo "Go check out http://localhost:8000/output/simd_test.html"
python ../../serve.py