-
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
Description
I would convert some part of the code to WASM simd, i would start with the
jsartoolkitNFT/emscripten/ARToolKitNFT_js.cpp
Lines 23 to 30 in c5486f0
void matrixLerp(ARdouble src[3][4], ARdouble dst[3][4], | |
float interpolationFactor) { | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 4; j++) { | |
dst[i][j] = dst[i][j] + (src[i][j] - dst[i][j]) / interpolationFactor; | |
} | |
} | |
} |
this could be converted to this:
#include <wasm_simd128.h>
void matrixLerp(ARdouble src[3][4], ARdouble dst[3][4], float interpolationFactor) {
v128_t factor = wasm_f64x2_splat(interpolationFactor);
v128_t one_minus_factor = wasm_f64x2_splat(1.0 - interpolationFactor);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j += 2) {
v128_t src_vec = wasm_v128_load(&src[i][j]);
v128_t dst_vec = wasm_v128_load(&dst[i][j]);
v128_t result = wasm_f64x2_add(
wasm_f64x2_mul(src_vec, one_minus_factor),
wasm_f64x2_mul(dst_vec, factor)
);
wasm_v128_store(&dst[i][j], result);
}
}
}