Skip to content

simdMul ​

simdMul multiplies corresponding elements from two equal-length arrays and returns a new array inside Result<T[], SimdError>.

SignaturesimdMul<T>(left: T[], right: T[]): Result<T[], SimdError>
tyrus
import { simdMul, SimdError } from "tyrus:simd";

const left: f32[] = [2.0, 3.0, 4.0, 5.0, 6.0];
const right: f32[] = [3.0, 4.0, 5.0, 6.0, 7.0];
const result: Result<f32[], SimdError> = simdMul(left, right);

match (result) {
    Ok(values) => {
        print(values); // [6.0, 12.0, 20.0, 30.0, 42.0]
    }
    Err(error) => {
        printError(error.code, error.message);
    }
}

The supported element types are i8, i16, i32, i64, u8, u16, u32, u64, f32, and f64. Signed and unsigned integer multiplication wraps by default at the element width; for example, multiplying 255 by 2 as u8 produces 254. Integer literals must still fit their declared element type at compile time. Dynamic input length mismatch and result allocation failure return SimdError values. Different fixed input lengths are rejected with E0308 at compile time.

Errors ​

error

tyrus
import { simdMul, SimdError } from "tyrus:simd";

const left: i32[] = [1, 2];
const right: i32[] = [3, 4, 5];
const result: Result<i32[], SimdError> = simdMul(left, right);

match (result) {
    Ok(_) => {}
    Err(error) => { printError(error.code, error.message); }
}
text
ERR_SIMD_LENGTH_MISMATCH simdMul requires arrays of equal length

error

tyrus
import { simdMul } from "tyrus:simd";

const left: i32[] = [1, 2];
const right: i64[] = [3, 4];
const result = simdMul(left, right); 
text
error[E0308]: type mismatch for argument 2 of `simdMul`: expected `i32[]`, found `i64[]`
at /src/main.tyr:5:16
const result = simdMul(left, right);
               ^^^^^^^