Graal compiler: AMD64 Intrinsics design

Gilles Duboscq gilles.m.duboscq at oracle.com
Thu Aug 16 10:33:13 UTC 2018


Hi Jean-Philippe,

Thanks for reaching out.

I think in general your steps are right.

A few things though about the particular use case:
- If i remember correctly, a lot of (all?) the BMI instructions use a VEX encoding. Currently our assembler makes some assumption about VEX-encoded instructions using some (x|y|z)mm registers.
  Some refactoring will be needed to clean that up and allow VEX-encoded instructions that only operate on general purpose registers.

- Which instructions do you want to implement an instrinsic for?
  It seems to me like most of them can either be matched in the back-end without having to add high-level nodes or intrinsics (see AMD64NodeMatchRules) or emitted when available:
  - In BMI1 we already use TZCNT and the rest can be matched,
  - In BMI2 (ROR|SAR|SHR|SHL|MUL)X can be emitted instead of the normal version when available.
  - BZHI can also probably be matched from something like `x & ~((1 << p) - 1)`?
  - PDEP & PEXT look like good candidates for intrinsics but which method are would they be intrinsics for?
  Maybe you are rather looking to create an intrinsic for an other high-level method?

Best regards,
 Gilles

On 15/08/18 20:57, Halimi, Jean-Philippe wrote:
> Hello everyone,
> 
> I'm getting started with the Graal source code and I'd like to add support for new BMI intrinsics, along with these already in place. I'm looking for help from people who developed the existing intrinsics infrastructure. Namely, I would like to double check that my initial understanding is correct.
> 
> Could you please let me know if the following steps are correct and sufficient?
> 
> 1. org.graalvm.compiler.asm.amd64/src/org/graalvm/compiler/asm/amd64/ --> will need to add any new type of instructions there if necessary
> 2. org.graalvm.compiler.replacements.amd64/src/org/graalvm/compiler/replacements/amd64/ --> will need to add new LIR types if necessary, typically in a new Node class that will represent the intrinsic. Design in pseudo code would be as follows:
> 
> public final class AMD64NewNode extends UnaryNode implements ArithmeticLirLowerable {
>    a. Constructor
>    b. tryFold(ValueNode value) method: will try convert the input value to the corresponding value if possible.
>    c. generate method: will generate the appropriate LIR containing the intrinsic in the builder.
> }
> 
> 3. Add an entry in org.graalvm.compiler.replacements.amd64/src/org/graalvm/compiler/replacements/amd64/AMD64GraphBuilderPlugins.java in order to support the intrinsic in the graph builder if hardware is supported
> 
> Thank you,
> 
> Jp
> 


More information about the graal-dev mailing list