I am trying to write a function that compares a SIMD variable against a a sequence of other SIMD vectors that are determined by a function parameter and I want the function to do as much as possible at compile time. Ideally so that at runtime the function just has a structure like
If variable == reference1:
return True
If variable == reference2:
return True
...
return False
Currently I have it like this
fn _is_winner[size: Int, //, player: UInt8](board: SIMD[DType.uint8, size*size]) -> Bool:
var reference: SIMD[DType.uint8, board.size]
@parameter
for row in range(size):
reference = SIMD[DType.uint8, board.size](0)
@parameter
for col in range(size):
reference[row * size + col] = player
if (board & reference).reduce_bit_count() == size:
return True
...
return False
But I am not sure if this does everything I want at compile time and if there are other things I can do to do that?