Here is some pseudocode for what I would like to do:

template SIMD(actions:untyped) =
  if AVX2_Available():
    import AVX2   # use the avx2 version of Add/Mul etc.
    import SSE    # use the sse version of Add/Mul etc.

  let c = SIMD_Add(a,b)

But I can't do that because imports have to be top level. I can do include instead of import, that will lead to massive code size if someone had multiple uses of the template in their code, as it will reproduce the same functions over and over.

Is there some way to accomplish this?

2017-11-12 20:12:05

Have you tried something like

when AVX2_Available():
Of course that can only work when your AVX2_Available() is known at compile time...

2017-11-12 20:23:38
yep, looking for a nice runtime solution. 2017-11-13 00:31:45
2017-11-14 16:45:43

I would be interested to know how you check that AVX2 is available at runtime, a try ... except block?

At compile-time you can use the approach done in QEX.

2017-11-15 12:03:11