LLVM asm with constraints, and 2 operands
Basile B.
b2.temp at gmx.com
Sun Jul 18 16:32:46 UTC 2021
On Sunday, 18 July 2021 at 11:42:24 UTC, Guillaume Piolat wrote:
> Is anyone versed in LLVM inline asm?
>
> I know how to generate SIMD unary op with:
>
> return __asm!int4("pmovsxwd $1,$0","=x,x",a);
>
> but I struggle to generate 2-operands SIMD ops like:
>
> return __asm!int4("paddd $1,$0","=x,x",a, b);
>
> If you know how to do it => https://d.godbolt.org/z/ccM38bfMT
> it would probably help build speed of SIMD heavy code, also -O0
> performance
> Also generating the right instruction is good but it must
> resist optimization too, so proper LLVM constraints is needed.
> It would be really helpful if someone has understood the
> cryptic rules of LLVM assembly constraints.
Yeah I can confirm it's aweful. Took me hours to understand how
to use it a bit (my PL has [an
interface](https://styx-lang.gitlab.io/styx/primary_expressions.html#asmexpression) for LLVM asm)
You need to add a "x" to the constraint string
return __asm!int4("paddd $1,$0","=x,x,x",a, b);
- **=x** says "returns in whatever is has to"
- **x** (1) is the constraint for input `a`, which is passed as
operand **$0**
- **x** (2) is the constraint for input `b`, which is passed as
operand **$1**
So the thing to get is that the output constraint does not
consume anything else, it is standalone.
More information about the Digitalmars-d-learn
mailing list