Compile time facilities
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
Currently I have it like this
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?
5 Replies
@parameter does loop unrolling, so you've accidently made this function very expensive, and then Mojo is saving you from yourself. This is what you actually want:
Now, if you had intended to compare each row, it would be like this:
So what i have above should be functionally equivalent to the start of this for size = 3: and player=1
I just dont know how to best generate these at compile time.
(and here is the full current code):
As far as I can tell what you have now works reasonably well due to constant folding references.
Ok, so there are no other compile time facilities that would allow me to do even more here?
You could potentially do a bit better, but the compiler seems to mostly be figuring it out.
You're rapidly approaching the point where knowing the exact CPU you execute on will be more useful than more things at compile time.