Skip to content
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

simd version of the build libs #402

Open
kalwalt opened this issue Nov 7, 2024 · 0 comments
Open

simd version of the build libs #402

kalwalt opened this issue Nov 7, 2024 · 0 comments
Assignees
Labels
C/C++ enhancement New feature or request simd128

Comments

@kalwalt
Copy link
Member

kalwalt commented Nov 7, 2024

I would convert some part of the code to WASM simd, i would start with the

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);
        }
    }
}
@kalwalt kalwalt added enhancement New feature or request C/C++ simd128 labels Nov 7, 2024
@kalwalt kalwalt self-assigned this Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ enhancement New feature or request simd128
Projects
None yet
Development

No branches or pull requests

1 participant