Thread overview
How use ldc pragmas?
Oct 01, 2021
james.p.leblanc
Oct 01, 2021
max haughton
Oct 01, 2021
james.p.leblanc
Oct 01, 2021
Imperatorn
Oct 01, 2021
james.p.leblanc
Oct 01, 2021
Imperatorn
Oct 02, 2021
james.p.leblanc
October 01, 2021

D-ers,

After experimenting with ldc's autovectorization of avx code, it appears there may
be counter-intuitiveness to the autovectorization (especially for complex numbers).
(My comment may be wrong, so any corrections are quite welcome).

Based on this, I wanted to investigate the use of ldc's pragma capabilities
(as found in ldc2/import/gccbuiltins_x86.di).

However, getting the ball rolling is a bit difficult, as I have not found a
simple example showing the whole process. What I have just now is:

// my example.d
import std.stdio;
import ldc.intrinsics;

void main()
{
   writeln("hello");

   float x;

   pragma(LDC_intrinsic, "llvm.sqrt.32")
   float sqrt(float);
}

I try to compile the above using:

ldc2 -mattr=+avx2 myexample.d -H ~/ldc2/import/ldc/gccbuiltins_x86.di

But receive the following:

ldcint.d(11): Error: unrecognized `pragma(LDC_intrinsic)`

I get the feeling that I am really "lost in the woods" here, probably
missing important aspects.

Are there any pointers this forum might have to help here?
(A very simple and complete example would be greatly appreciated!)

Thanks!
James

October 01, 2021

On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc wrote:

>

D-ers,

After experimenting with ldc's autovectorization of avx code, it appears there may
be counter-intuitiveness to the autovectorization (especially for complex numbers).
(My comment may be wrong, so any corrections are quite welcome).

[...]

Is it sqrt.32 or sqrt.f32? Try the latter, LLVM docs seem to agree.

October 01, 2021

On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc wrote:

>

D-ers,

After experimenting with ldc's autovectorization of avx code, it appears there may
be counter-intuitiveness to the autovectorization (especially for complex numbers).
(My comment may be wrong, so any corrections are quite welcome).

[...]

import std.stdio;
import ldc.intrinsics;

pragma(LDC_intrinsic, "llvm.sqrt.f32") float sqrt(float);

void main()
{
    writeln("hello");

    float x = 42.42;
    writeln(sqrt(x));
}
October 01, 2021

On Friday, 1 October 2021 at 19:58:30 UTC, max haughton wrote:

>

On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc

>

Is it sqrt.32 or sqrt.f32? Try the latter, LLVM docs seem to agree.

Hello Max,

Thanks for the correction... unfortunately, even after changing the "32",
to "f32", I receive the same error. So there is something of a bigger
nature that I am still doing wrong.

I should have noted earlier that I am just trying to mirror the docs found at:

https://wiki.dlang.org/LDC-specific_language_changes

// provide square root intrinsics
pragma(LDC_intrinsic, "llvm.sqrt.f32")
  float sqrt(float);
pragma(LDC_intrinsic, "llvm.sqrt.f64")
  double sqrt(double);
pragma(LDC_intrinsic, "llvm.sqrt.f80")
  real sqrt(real); // x86 only

Any additional hints for ldc instrinsics are greatly appreciated.
James

October 01, 2021

On Friday, 1 October 2021 at 20:14:01 UTC, james.p.leblanc wrote:

>

On Friday, 1 October 2021 at 19:58:30 UTC, max haughton wrote:

>

[...]

>

[...]

Hello Max,

Thanks for the correction... unfortunately, even after changing the "32",
to "f32", I receive the same error. So there is something of a bigger
nature that I am still doing wrong.

I should have noted earlier that I am just trying to mirror the docs found at:

https://wiki.dlang.org/LDC-specific_language_changes

// provide square root intrinsics
pragma(LDC_intrinsic, "llvm.sqrt.f32")
  float sqrt(float);
pragma(LDC_intrinsic, "llvm.sqrt.f64")
  double sqrt(double);
pragma(LDC_intrinsic, "llvm.sqrt.f80")
  real sqrt(real); // x86 only

Any additional hints for ldc instrinsics are greatly appreciated.
James

Take a look at my post ;)

October 01, 2021

On Friday, 1 October 2021 at 20:19:39 UTC, Imperatorn wrote:

>

Take a look at my post ;)

YES!

Thanks to both Imperatorn, and Max for their helpful and quick responses.
The problem is SOLVED!

I didn't realize that the pragma had to be placed outside of the main() ...
but it seems that I should have known this! (Tomorrow, I shall dive into
the deeper waters with avx2.)

Sometimes, getting a simple example to build from can be the hardest part, eh?

Thanks Again,
James

October 02, 2021

On Friday, 1 October 2021 at 19:23:06 UTC, james.p.leblanc wrote:

>

D-ers,

Update from myself to myself (and any others who might use the bash
command from my origin posting),

>

I try to compile the above using:

ldc2 -mattr=+avx2 myexample.d -H  ~/ldc2/import/ldc/gccbuiltins_x86.di

Remove the "-H ..." this should not be used (based on an earlier misunderstanding
of mine). Instead, simply use:

ldc2 -mattr=+avx2 myexample.d

Cheers,
jpl