-
-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Wasm simd128 support #286
Conversation
making it the same as glm_mat4_inv_wasm, does not make any difference in tests
The static __inline__ void __attribute__((__always_inline__, __nodebug__))
_mm_storeu_ps(float *__p, glmm_128 __a)
{
struct __unaligned {
glmm_128 __v;
} __attribute__((__packed__, __may_alias__));
((struct __unaligned *)__p)->__v = __a;
}
static __inline__ void __DEFAULT_FN_ATTRS wasm_v128_store(void *__mem,
v128_t __a) {
// UB-free unaligned access copied from xmmintrin.h
struct __wasm_v128_store_struct {
__v128_u __v;
} __attribute__((__packed__, __may_alias__));
((struct __wasm_v128_store_struct *)__mem)->__v = __a;
} |
Another potential edge-case that may require handling is compiling w/ Emscripten, e.g., |
This could be guarded by some extra check in macros like this, a lot more similar things should be changed. diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h
index 17998f5..bf8d119 100644
--- a/include/cglm/simd/intrin.h
+++ b/include/cglm/simd/intrin.h
@@ -113,7 +113,7 @@
# endif
#endif
-#if defined(CGLM_SIMD_x86)
+#if defined(CGLM_SIMD_x86) && !defined(CGLM_SIMD_WASM)
# include "x86.h"
#endif
diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h
index d6ee080..e90a3c3 100644
--- a/include/cglm/vec4.h
+++ b/include/cglm/vec4.h
@@ -181,10 +181,10 @@ glm_vec4_ucopy(vec4 v, vec4 dest) {
CGLM_INLINE
void
glm_vec4_zero(vec4 v) {
-#if defined( __SSE__ ) || defined( __SSE2__ )
- glmm_store(v, _mm_setzero_ps());
-#elif defined(__wasm__) && defined(__wasm_simd128__)
+#if defined(__wasm__) && defined(__wasm_simd128__)
glmm_store(v, wasm_f32x4_const_splat(0.f));
+#elif defined( __SSE__ ) || defined( __SSE2__ )
+ glmm_store(v, _mm_setzero_ps());
#elif defined(CGLM_NEON_FP)
vst1q_f32(v, vdupq_n_f32(0.0f));
#else
|
After this, the required options for cmake are listed below: ``` -DCMAKE_C_FLAGS="-msimd128" -DCMAKE_TOOLCHAIN_FILE=/path/to/wasi-sdk-19.0/share/cmake/wasi-sdk.cmake -DWASI_SDK_PREFIX=/path/to/wasi-sdk-19.0 -DCGLM_USE_TEST=ON ``` If compiling to wasi with simd128 support, `-DCMAKE_C_FLAGS="-msimd128"` can be removed. If tests are not needed, `-DCGLM_USE_TEST=ON` can be removed.
@myfreeer great work! any new progress? |
Yes, github actions added for tests. |
@myfreeer awesome 🚀 |
@myfreeer any new progress ? It would be nice to merge this asap |
@recp |
@myfreeer yes this is good approach I think. This PR became huge update, another PR[s] would be awesome, I hope we won't forget it :)
🤷♂️ if it will take long time, I or you could do it later |
@myfreeer the PR is merged 🚀 many thanks. Feel free to create PRs for additional improvements |
Great! Also, it seems that the github actions ci needs to be manually enabled in this repo to make it work. |
I have just enabled the actions 👍 |
See #282 for previous discussion.
TODOs
Inline or rewrite sse2 wrappers borrowed from emscripten
Guard againist conditions when both
sse2
andsimd128
enabled by Emscripten (WIP: Wasm simd128 support #286 (comment))Change in compile scripts for cross-compiling or a build guide
autoconfdelayed since it could take too langmesondelayed since it could take too langCI-driven tests, cross compile all tests with or without simd128, using appveyor or Github Actions
Code style changes
Compiling
Currently the tests can be cross-compiled to wasi using clang and wasi-sdk with cmake arguments below:
Where
/path/to/wasi-sdk-19.0/
is the path to extracted wasi sdk.The cmake-wasm.yml shows an example for compiling and running tests on github actions.