ModularM
Modular3y ago
2 replies
Henk-Jan Lebbink

How to cast SIMD when the size is known at compile time

In the following minimal code snippet v cannot be assigned to
v2
. The error message is: cannot implicitly convert 'SIMD[si32, size]' value to 'SIMD[si32, 32]' in 'let' initializer. But size is known to be equal to 32.

Question: how to convince the compiler that I'm a good citizen: trust me, this is ok, everyting will be fine...

fn x(v: SIMD[DType.int32, 32]):
    pass

fn howto[size: Int](v: SIMD[DType.int32, size]) -> SIMD[DType.int32, size]:
    @parameter
    if size == 32:
        let v2: SIMD[DType.int32, 32] = v  # compile error here
        x(v2)
Was this page helpful?