www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Using AVX intrinsics with LDC

reply Jeff <jromang protonmail.com> writes:
Hello,
I'm a beginner in D (I come from C++/Python), but I'm having 
great fun learning the language reading Ali's book. I'm using LDC 
as compiler, and I would like to use intrinsics, but I have 
difficulties to find the Intel intrinsics equivalent. Here are 
the functions I'm looking for :

_mm_cvtsi64x_si128
_mm256_sll_epi64
_mm256_movemask_epi8

Is there a way to call them ? Is there an Intel intrinsics to LDC 
intrinsics guide somewhere ?
Thanks for your help !
May 15 2018
next sibling parent kinke <noone nowhere.com> writes:
On Tuesday, 15 May 2018 at 17:21:49 UTC, Jeff wrote:
 Hello,
 I'm a beginner in D (I come from C++/Python), but I'm having 
 great fun learning the language reading Ali's book. I'm using 
 LDC as compiler, and I would like to use intrinsics, but I have 
 difficulties to find the Intel intrinsics equivalent. Here are 
 the functions I'm looking for :

 _mm_cvtsi64x_si128
 _mm256_sll_epi64
 _mm256_movemask_epi8

 Is there a way to call them ? Is there an Intel intrinsics to 
 LDC intrinsics guide somewhere ?
 Thanks for your help !
Hi, you'll want to have a look at LDC's `import/ldc/gccbuiltins_x86.di` file (auto-generated from corresponding LLVM x86 intrinsics). Make sure to enable extended instruction sets via something like `-mattr=+avx2` (or simply `-mcpu=native`). _mm256_movemask_epi8 => __builtin_ia32_pmovmskb256 _mm256_sll_epi64 => __builtin_ia32_psllqi256 I didn't find the corresponding declaration for _mm_cvtsi64x_si128 (__builtin_ia32_vzeroupper strangely takes no args). You can always resort to LLVM assembly though (grep for `__asm` in import directory to see some examples in druntime/Phobos).
May 15 2018
prev sibling next sibling parent reply Kagamin <spam here.lot> writes:
On Tuesday, 15 May 2018 at 17:21:49 UTC, Jeff wrote:
 _mm_cvtsi64x_si128
If it zero extends 64-bit integer to 128-bit integer, it's done by movq instruction. I suppose simple assignment should do it.
May 16 2018
parent reply kinke <kinke libero.it> writes:
On Wednesday, 16 May 2018 at 10:36:01 UTC, Kagamin wrote:
 On Tuesday, 15 May 2018 at 17:21:49 UTC, Jeff wrote:
 _mm_cvtsi64x_si128
If it zero extends 64-bit integer to 128-bit integer, it's done by movq instruction. I suppose simple assignment should do it.
That's enough indeed: https://run.dlang.io/is/1wJ7mA [And vzeroupper is unrelated, and no args are correct.]
May 16 2018
parent reply Jeff <jromang protonmail.com> writes:
On Wednesday, 16 May 2018 at 13:11:46 UTC, kinke wrote:
 On Wednesday, 16 May 2018 at 10:36:01 UTC, Kagamin wrote:
 On Tuesday, 15 May 2018 at 17:21:49 UTC, Jeff wrote:
 _mm_cvtsi64x_si128
If it zero extends 64-bit integer to 128-bit integer, it's done by movq instruction. I suppose simple assignment should do it.
That's enough indeed: https://run.dlang.io/is/1wJ7mA [And vzeroupper is unrelated, and no args are correct.]
Thanks, it works perfectly ! Also I discover run.dlang.io, nice to quickly check the ASM output :)
May 16 2018
parent Johan Engelen <j j.nl> writes:
On Wednesday, 16 May 2018 at 19:34:32 UTC, Jeff wrote:
  Also I discover run.dlang.io, nice to quickly check the ASM 
 output :)
You might like https://d.godbolt.org better if you don't need to execute the code. -Johan
May 16 2018
prev sibling parent Guillaume Piolat <first.last gmail.com> writes:
On Tuesday, 15 May 2018 at 17:21:49 UTC, Jeff wrote:
 Hello,
 I'm a beginner in D (I come from C++/Python), but I'm having 
 great fun learning the language reading Ali's book. I'm using 
 LDC as compiler, and I would like to use intrinsics, but I have 
 difficulties to find the Intel intrinsics equivalent. Here are 
 the functions I'm looking for :

 _mm_cvtsi64x_si128
 _mm256_sll_epi64
 _mm256_movemask_epi8

 Is there a way to call them ? Is there an Intel intrinsics to 
 LDC intrinsics guide somewhere ?
 Thanks for your help !
I've started doing such a translation as a library here: http://code.dlang.org/packages/intel-intrinsics However, no AVX yet
May 23 2018