Skip to content

simd version of the build libs #402

@kalwalt

Description

@kalwalt

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);
        }
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions