Intrinsics
Martin Traverso
mtraverso at gmail.com
Fri Sep 14 18:17:09 UTC 2018
Hi,
I'm playing around with Graal, and as an experiment, I'm trying to see what
it would take to intrinsify some operations to do math on 128-bit values.
I have a method with the following signature:
boolean add128(long low1, long high1, long low2, long high2, long[]
result)
It computes the sum of two 128-bit integers encoded in two longs each and
stores the result in the 2-element array that's provided via the last
argument. It returns true if the sum overflows.
I'd like to emit the equivalent of the following assembly pseudocode:
result[0] = ADD low1 low2
result[1] = ADC high1 high2
return = (carry == 1)
>From what I gathered so far, I should add a new node (e.g., Add128Node) and
register a builder a graph builder plugin that swaps invocations to that
method with the new node.
But that's where I'm getting stuck. Two paths I've started exploring:
1. Lower the Add128Node into operations that perform the sums of the high
vs low parts (e.g., Add128LowNode, Add128HighNode), do the assignments to
the resulting array, etc. This would seem to require modeling operations
that produce multiple outputs (low + low produces one value + carry). Is
this even possible?
2. Make Add128Node LIRLowerable and generate the whole sequence of
low-level operations in one shot. I'm not sure how the assignments to the
output array and return value would fit here, though.
I'm sure I'm missing something obvious, so I appreciate any pointers or
suggestions. Are there similar examples I can draw inspiration from?
Thanks,
Martin
More information about the graal-dev
mailing list