1 // Copyright 2020 Google LLC
2 //
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "include/private/SkVx.h"
7 #include <emscripten.h>
8 #include <stdio.h>
9
10 // How to read this file:
11 // - Lines with "//GOOD" are compatible with WASM SIMD and are automatically compiled
12 // into WASM SIMD operations by emscripten.
13 // - Lines with "//N/A" are not operations that are compatible with this type of data.
14 // - Lines with "GOOD (FIXED)" are compatible with WASM SIMD but are NOT automatically
15 // compiled into WASM SIMD operations by emscripten. Special WASM SIMD intrinsics have been
16 // specified in skia/include/private/SkVx.h to tell emscripten how to compile them to WASM SIMD
17 // operations.
18 // - Lines with "//not available in wasm" do not have compatible WASM SIMD operations. Emscripten
19 // compiles these operations into non-SIMD WASM.
20 // - Lines with "//???" may be more complex and it is not clear if they have compatible WASM SIMD
21 // operations. More work could be needed on these operations.
22
23 // How to use this file for testing WASM SIMDification of operations:
24 // 1. Reference https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md
25 // and https://github.com/llvm/llvm-project/blob/master/clang/lib/Headers/wasm_simd128.h
26 // to check if a WASM SIMD operation exists which correspond to any given line of code.
27 // 2. Uncomment that line of code.
28 // 3. Run `./build_simd_test.sh simd_float_capabilities.cpp` to build and output WASM SIMD operations
29 // present in the compiled WASM.
30 // 4. Read the output in the console to see if the WASM SIMD operations you expected were present in
31 // the resulting compiled WASM.
32
main()33 int main() {
34 auto vec1 = skvx::Vec<4, float>({11.f, -22.f, 33.f, -44.f});
35 auto vec2 = skvx::Vec<4, float>({-.5f, 100.5f, 100.5f, -.5f});
36
37 //auto vec3 = skvx::join(vec1, vec2); //not available in wasm
38 // note: may be possible using "widening"
39
40 //vec1 = vec1 + vec2; //GOOD
41 //vec1 = vec1 - vec2; //GOOD
42 //vec1 = vec1 * vec2; //GOOD
43 //vec1 = vec1 / vec2; //GOOD
44
45 //vec1 = vec1 ^ vec2; //N/A
46 //vec1 = vec1 & vec2; //N/A
47 //vec1 = vec1 | vec2; //N/A
48
49 //vec1 = !vec1; //N/A
50 //vec1 = -vec1; //GOOD
51 //vec1 = ~vec1; //N/A
52
53 //vec1 = vec1 << 2; //N/A
54 //vec1 = vec1 >> 2; //N/A
55
56 //auto vec3 = vec1 == vec2; //GOOD
57 //auto vec3 = vec1 != vec2; //GOOD
58 //auto vec3 = vec1 <= vec2; //GOOD
59 //auto vec3 = vec1 >= vec2; //GOOD
60 //auto vec3 = vec1 < vec2; //GOOD
61 //auto vec3 = vec1 > vec2; //GOOD
62
63 //auto vec3 = skvx::any(vec1); //N/A
64 //auto vec3 = skvx::all(vec1); //N/A
65
66 //vec1 = skvx::max(vec1, vec2); //GOOD (FIXED)
67 //vec1 = skvx::min(vec1, vec2); //GOOD (FIXED)
68
69 //vec1 = skvx::pow(vec1, vec2); //not available in wasm
70 //vec1 = skvx::atan(vec1); //not available in wasm
71 //vec1 = ceil(vec1); //not available in wasm, note: maybe could use "comparisons"
72 //vec1 = skvx::floor(vec1); //not available in wasm
73 //vec1 = skvx::trunc(vec1); //not available in wasm
74 // note: maybe possible using trunc_sat_f32x4_s and convert_i32x4_s?
75 //vec1 = skvx::round(vec1); //not available in wasm
76 // note: maybe possible using trunc_sat_f32x4_s and convert_i32x4_s?
77 //vec1 = skvx::sqrt(vec1); //GOOD (FIXED)
78 //vec1 = skvx::abs(vec1); //GOOD (FIXED)
79 //vec1 = skvx::sin(vec1); //not available in wasm
80 //vec1 = skvx::cos(vec1); //not available in wasm
81 //vec1 = skvx::tan(vec1); //not available in wasm
82
83 //auto vec3 = skvx::lrint(vec1); //???
84 // note: may be possible using f32x4.convert_i32x4_s, would need to test correctness.
85
86 //vec1 = skvx::rcp(vec1); //GOOD (FIXED) previous: N/A-BAD, doesn't use SIMD div
87 //vec1 = skvx::rsqrt(vec1); //GOOD (FIXED) previous: BAD, doesn't use SIMD sqrt or div
88
89 //vec1 = skvx::if_then_else(vec1, vec1, vec2); //N/A
90
91 //vec1 = skvx::shuffle<2,1,0,3>(vec1); //GOOD
92
93 //vec1 = skvx::fma(vec1, vec2, vec1); //not available in wasm (no fused multiply-add is available)
94 //vec1 = skvx::fract(vec1); //???
95
96 //printf("result: { %f, %f, %f, %f }\n", vec1[0], vec1[1], vec1[2], vec1[3]);
97
98 return 0;
99 }
100