• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright 2020 Google LLC
3#
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This script takes a path to a .cpp file, compiles the file to wasm using emscripten, outputs
8# textual representations of all wasm SIMD operations present in the compiled .wasm, and starts
9# a static file server so that the running .wasm can be manually inspect in a browser.
10#
11# Example usage: ./build_simd_test.sh simd_float_capabilities.cpp
12
13# Requires that emscripten and wasm2wat are added to your PATH.
14# Requires, and is verified to work with
15# - The output of `wasm2wat --version` should be `1.0.13 (1.0.17)`
16#   - install from here: https://github.com/WebAssembly/wabt
17# - emscripten 1.39.16
18# - Chrome Canary 86.0.4186.0 with chrome://flags#enable-webassembly-simd enabled
19
20# build the file specified as the first argument with SIMD enabled.
21em++ $1 -I ../../../../ -msimd128 -Os -s WASM=1 -o output/simd_test.html
22# convert the output WASM to a human readable text format (.wat)
23wasm2wat --enable-simd output/simd_test.wasm > output/simd_test.wat
24
25# The following lines output all SIMD operations produced in the output WASM.
26# Useful for checking that SIMD instructions are actually being used.
27# e.g. for the following C++ code:
28#  auto vec1 = skvx::Vec<2, double>({11.f, -22.f}) + skvx::Vec<2, double>({13.f, -1.f});
29# it is expected that the f64x2.add operation is present in the output WASM.
30echo "The following WASM SIMD operations were used in the compiled code:"
31grep -f wasm_simd_types.txt output/simd_test.wat
32
33# Serve the compiled WASM so output can be manually inspected for correctness.
34echo "Go check out http://localhost:8000/output/simd_test.html in Chrome Canary 86.0.4186.0 \
35or later and enable the chrome://flags#enable-webassembly-simd flag!"
36python ../../serve.py
37