-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intrinsic for AArch64 Arrays.fill(array, constant) #10207
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping up this work! I left some high-level comments for now. I'll do some testing and a more thorough review of the assembly code soon.
compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/aarch64/AArch64Assembler.java
Show resolved
Hide resolved
compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java
Outdated
Show resolved
Hide resolved
compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64LIRGenerator.java
Outdated
Show resolved
Hide resolved
compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/stubs/IntrinsicStubs.java
Outdated
Show resolved
Hide resolved
.../src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java
Outdated
Show resolved
Hide resolved
.../src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java
Outdated
Show resolved
Hide resolved
.../src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java
Outdated
Show resolved
Hide resolved
.../src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/StandardGraphBuilderPlugins.java
Outdated
Show resolved
Hide resolved
@gergo- - I believe I've addressed all your comments so far. Please, let me know if you have any other concerns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some requests for improved documentation, and the value to be filled should be a long
throughout. I also started some checks on this PR, note that the style checks had some complaints. Please make sure mx checkstyle
passes in the compiler
suite.
This will soon be ready for internal testing.
/** | ||
* Emits code which fills an array with a constant value. The assembly code in this intrinsic was | ||
* based in the HotSpot's version of the same intrinsic. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Constant value" is a bit misleading, since it doesn't have to be a compile-time constant. "Fixed value" maybe? Please also note that that only primitive values are supported, and that floating-point values are expected reinterpreted as integer bits.
* based in the HotSpot's version of the same intrinsic. | ||
*/ | ||
@Opcode("ARRAYS_FILL") | ||
public final class AArch64ArrayFillOp extends AArch64ComplexVectorOp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a @SyncPort
annotation referring to the exact piece of HotSpot code this is based on.
|
||
GraalError.guarantee(array.getPlatformKind() == AArch64Kind.QWORD, "pointer value expected"); | ||
GraalError.guarantee(length.getPlatformKind() == AArch64Kind.DWORD, "integer value expected in 'length'"); | ||
GraalError.guarantee(value.getPlatformKind() == AArch64Kind.DWORD, "integer value expected in 'value'."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guarantee cannot be correct anymore since you now support long
values too.
int operationWidthB = 8; | ||
int operationWidthH = 16; | ||
int operationWidthW = 32; | ||
int operationWidthDW = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our normal style is to have these magic operation size numbers as explicit constants in the code. The difference between 32
and 64
is just much easier to see than the difference between operationWidthW
and operationWidthDW
.
Also note that you're defining DW
as 64 bits, but that doesn't match our conventions: AArch64Kind.DWORD
is 32 bits. So please drop these symbolic constants.
|
||
/** | ||
* Fills in an array with a given constant value. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest something like:
Fills an array by setting all elements to {@link #valueToFillWith}. The value must be a primitive integer, and its bit size must match the array's {@link #elementKind}. Filling of floating-point arrays is supported by passing a floating-point value reinterpreted as integer bits.
|
||
protected JavaKind elementKind; | ||
|
||
@Input protected ValueNode arrayBase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest naming this just array
and adding a comment like /** Address of the array object on the Java heap. */
. The term "base" could be misleading, since we often use "base" for the address of the first array element, as opposed to the address of the whole object.
@Input protected ValueNode valueToFillWith; | ||
|
||
public ArrayFillNode(ValueNode arrayBase, ValueNode offsetToFirstElement, ValueNode arrayLength, ValueNode valueToFillWith, @ConstantNodeParameter JavaKind elementKind) { | ||
super(TYPE, StampFactory.forVoid(), null, LocationIdentity.any()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please unify with the other constructor:
super(TYPE, StampFactory.forVoid(), null, LocationIdentity.any()); | |
this(array, offsetToFirstElement, arrayLength, valueToFillWith, elementKind, null); |
Though I'm not even sure you need to pass the runtimeCheckedCPUFeatures
everywhere.
|
||
public ArrayFillNode(ValueNode arrayBase, ValueNode offsetToFirstElement, ValueNode arrayLength, ValueNode valueToFillWith, @ConstantNodeParameter JavaKind elementKind, | ||
@ConstantNodeParameter EnumSet<?> runtimeCheckedCPUFeatures) { | ||
super(TYPE, StampFactory.forVoid(), runtimeCheckedCPUFeatures, LocationIdentity.any()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use NamedLocationIdentity.arrayLocation(elementKind)
instead of any
.
this.offsetToFirstElement = offsetToFirstElement; | ||
this.arrayLength = arrayLength; | ||
this.valueToFillWith = valueToFillWith; | ||
this.elementKind = elementKind; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add guarantees for:
valueToFillWith.stamp(NodeView.DEFAULT) instanceof IntegerStamp
elementKind.isPrimitive()
PrimitiveStamp.getBits(valueToFillWith.stamp(NodeView.DEFAULT)) == elementKind.getBitCount()
@GenerateStub(name = "longArrayFill", parameters = {"Long"}) | ||
@GenerateStub(name = "floatArrayFill", parameters = {"Float"}) | ||
@GenerateStub(name = "doubleArrayFill", parameters = {"Double"}) | ||
public static native void fill(Pointer array, long offset, int length, int value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int value
cannot be correct if you support long
and double
fills.
Please, consider this patch to intrinsify
Arrays.fill(array, constant)
forbyte
,short
andint
on AArch64 backend. The assembly code is a port of the HotSpot assembly for the same intrinsic. Thank you @gergo- for reviewing the draft version of this PR!The below is a summary of some quick JMH tests that I ran on my dev machine.