Thread overview
XMM Intrinsics
May 08, 2020
Marcio Martins
May 08, 2020
Simen Kjærås
May 08, 2020
kinke
May 08, 2020
Simen Kjærås
May 09, 2020
Mike Parker
May 08, 2020
Guillaume Piolat
May 08, 2020
Marcio Martins
May 08, 2020
kinke
May 08, 2020
Marcio Martins
May 09, 2020
Olivier Pisano
May 08, 2020
Hi,

I am building a CRC32C implementation using SSE for D, because I couldn't find any readily available :[

However, I am unable to find any documentation regarding which SSE instructions are available and how I could use them in D. I can see core.simd can't seem to make any use of it.

How would I go about calling _mm_* functions in D in a way that is portable between D compilers?

I am currently using LDC so if someone could point me a direction I can get this going even if only on LDC it would already be a great help.

Cheers!
May 08, 2020
On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote:
> Hi,
>
> I am building a CRC32C implementation using SSE for D, because I couldn't find any readily available :[
>
> However, I am unable to find any documentation regarding which SSE instructions are available and how I could use them in D. I can see core.simd can't seem to make any use of it.
>
> How would I go about calling _mm_* functions in D in a way that is portable between D compilers?

You would use core.simd:

https://dlang.org/library/core/simd.html


Sadly, the supported instructions are not documented on that page, and you'll need to look at the source to get at them:

https://github.com/dlang/druntime/blob/master/src/core/simd.d#L85-L384

(I'll file a bug on this)


There's a bit more info on D SIMD instructions here:

https://dlang.org/spec/simd.html

--
  Siomen
May 08, 2020
On Friday, 8 May 2020 at 12:49:00 UTC, Simen Kjærås wrote:
>> How would I go about calling _mm_* functions in D in a way that is portable between D compilers?
>
> You would use core.simd:

Nope one wouldn't, because that horrible interface isn't supported by LDC, and I guess GDC neither.

The intel-intrinsics dub package aims to provide a compiler-independent layer: https://code.dlang.org/packages/intel-intrinsics
May 08, 2020
On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote:
> How would I go about calling _mm_* functions in D in a way that is portable between D compilers?

Hello,

I've made this library for that exact purpose: https://github.com/AuburnSounds/intel-intrinsics


Supports every intrinsic listed under MMX/SSE/SSE2/SSE3 in https://software.intel.com/sites/landingpage/IntrinsicsGuide/
May 08, 2020
On Friday, 8 May 2020 at 13:11:02 UTC, Guillaume Piolat wrote:
> On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote:
>> How would I go about calling _mm_* functions in D in a way that is portable between D compilers?
>
> Hello,
>
> I've made this library for that exact purpose: https://github.com/AuburnSounds/intel-intrinsics
>
>
> Supports every intrinsic listed under MMX/SSE/SSE2/SSE3 in https://software.intel.com/sites/landingpage/IntrinsicsGuide/

I saw the intel-intrinsics package, but unfortunately it stops at SEE3 and I need SSE4.2 for this.

How is this library working? Will LDC/LLVM detect the name and replace it with the right instructions? If so, could I just provide an empty _mm_crc32_u8 and it'd pick it up correctly?


Thanks guys!
May 08, 2020
On Friday, 8 May 2020 at 13:30:42 UTC, Marcio Martins wrote:
> I saw the intel-intrinsics package, but unfortunately it stops at SEE3 and I need SSE4.2 for this.
>
> How is this library working?

It's open source. :)

> Will LDC/LLVM detect the name and replace it with the right instructions? If so, could I just provide an empty _mm_crc32_u8 and it'd pick it up correctly?

Nope. But take a look at ldc.gccbuiltins_x86, it offers these 4 builtins:

int __builtin_ia32_crc32hi(int, short);
int __builtin_ia32_crc32si(int, int);
int __builtin_ia32_crc32qi(int, byte);
long __builtin_ia32_crc32di(long, long);

Make sure to compile with `-mattr=+sse4.2` to enable these instructions.
May 08, 2020
On Friday, 8 May 2020 at 13:56:18 UTC, kinke wrote:
> On Friday, 8 May 2020 at 13:30:42 UTC, Marcio Martins wrote:
>> I saw the intel-intrinsics package, but unfortunately it stops at SEE3 and I need SSE4.2 for this.
>>
>> How is this library working?
>
> It's open source. :)

I know, but I don't have time to implement it and make it pretty, I am prototyping  with very little time.

>> Will LDC/LLVM detect the name and replace it with the right instructions? If so, could I just provide an empty _mm_crc32_u8 and it'd pick it up correctly?
>
> Nope. But take a look at ldc.gccbuiltins_x86, it offers these 4 builtins:
>
> int __builtin_ia32_crc32hi(int, short);
> int __builtin_ia32_crc32si(int, int);
> int __builtin_ia32_crc32qi(int, byte);
> long __builtin_ia32_crc32di(long, long);
>
> Make sure to compile with `-mattr=+sse4.2` to enable these instructions.

YES! Thank you, this is exactly what I was looking for.
I suppose I will have to implement a scalar version for DMD later... I don't even know why I bother with DMD...


May 08, 2020
On Friday, 8 May 2020 at 13:09:49 UTC, kinke wrote:
> On Friday, 8 May 2020 at 12:49:00 UTC, Simen Kjærås wrote:
>>> How would I go about calling _mm_* functions in D in a way that is portable between D compilers?
>>
>> You would use core.simd:
>
> Nope one wouldn't, because that horrible interface isn't supported by LDC, and I guess GDC neither.
>
> The intel-intrinsics dub package aims to provide a compiler-independent layer: https://code.dlang.org/packages/intel-intrinsics

TIL, thanks! :)

--
  Simen
May 09, 2020
On Friday, 8 May 2020 at 20:14:05 UTC, Simen Kjærås wrote:

>>
>> The intel-intrinsics dub package aims to provide a compiler-independent layer: https://code.dlang.org/packages/intel-intrinsics
>
> TIL, thanks! :)
>
> --
>   Simen

DConf 2019: Not intrinsically about intrinsics -- Guillaume Piolat

https://youtu.be/cmswsx1_BUQ
May 09, 2020
On Friday, 8 May 2020 at 12:38:51 UTC, Marcio Martins wrote:
> Hi,
>
> I am building a CRC32C implementation using SSE for D, because I couldn't find any readily available :[

Here is mine:

https://github.com/opisano/crc32c/blob/master/crc32c.d