-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Mono] [Arm64] Add basic Vector3 SIMD intrinsics #97416
Conversation
Tagging subscribers to this area: @SamMonoRT, @fanyang-mono Issue DetailsBasic SIMD support for System.Numerics.Vector3. Should fix #91456
|
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Probably needs llvm support as well. |
a0aa8fe
to
1e30142
Compare
The llvm changes look ok as well, just the formatting needs to be cleaned up to conform to the mono coding convs. |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
src/mono/mono/mini/mini-llvm.c
Outdated
|
||
if (mono_class_value_size (klass, NULL) == 12) | ||
len--; |
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.
Why are we decrementing len
here?
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 encountered case that lhs
would be V3 represented as V4(three elements + zero). And the retval
would be V3.
The code tried to extract the fourth value of lhs
and insert it into retval
which caused an error, as retval
had only three elements.
The change made it only extract and insert the first three elms if V3 was encoutered
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 would add comment explaining this special case for easier comprehension.
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.
@jkurdek thank you for the explanation.
Just for my understanding, so it basically means that in such cases LLVMGetReturnType (ctx->lmethod_type)
and LLVMTypeOf (lhs)
are returning a different type (as we end up having different vector sizes) ?
If we have these kind of workarounds across the mini-llvm code, I think it is ok to manually adjust the len
however to be less cryptic, it might be better to have a comment explaining the special-casing (as @matouskozak suggested) and something like this instead:
// TODO: Here add explanation why handling Vector3 requires special treatment
int len = mono_class_value_size (klass, NULL) == 12 ? 3 : LLVMGetVectorSize (LLVMTypeOf (lhs));
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.
Yup, LLVMGetReturnType (ctx->lmethod_type)
is a vector of three elements, whereas LLVMTypeOf (lhs)
is a vector of four elements (three + zero)
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.
Since 3 element vectors don't exist in the hardware, it might be easier to use 4 elements ones in return types etc. and only handle 3 element ones in loads/stores etc.
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Test failures seem unrelated |
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.
The changes look good to me, as a follow up we could intrisify more Vector3/4 constructors.
@@ -2721,6 +2727,17 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f | |||
for (int i = 1; i < fsig->param_count; ++i) | |||
ins = emit_vector_insert_element (cfg, klass, ins, MONO_TYPE_R4, args [i + 1], i, FALSE); | |||
|
|||
if (len == 3) { |
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.
Does this also handle the Vector3 constructor: Vector3 (Vector2, float)
? As a follow up we could enable this block
runtime/src/mono/mono/mini/simd-intrinsics.c
Lines 2734 to 2762 in 93381bf
#if 0 | |
} else if (len == 3 && fsig->param_count == 2 && fsig->params [0]->type == MONO_TYPE_VALUETYPE && fsig->params [1]->type == etype->type) { | |
/* Vector3 (Vector2, float) */ | |
int dreg = load_simd_vreg (cfg, cmethod, args [0], NULL); | |
ins = emit_simd_ins (cfg, klass, OP_INSERT_R4, args [1]->dreg, args [2]->dreg); | |
ins->inst_c0 = 2; | |
ins->dreg = dreg; | |
return ins; | |
} else if (len == 4 && fsig->param_count == 2 && fsig->params [0]->type == MONO_TYPE_VALUETYPE && fsig->params [1]->type == etype->type) { | |
/* Vector4 (Vector3, float) */ | |
int dreg = load_simd_vreg (cfg, cmethod, args [0], NULL); | |
ins = emit_simd_ins (cfg, klass, OP_INSERT_R4, args [1]->dreg, args [2]->dreg); | |
ins->inst_c0 = 3; | |
ins->dreg = dreg; | |
return ins; | |
} else if (len == 4 && fsig->param_count == 3 && fsig->params [0]->type == MONO_TYPE_VALUETYPE && fsig->params [1]->type == etype->type && fsig->params [2]->type == etype->type) { | |
/* Vector4 (Vector2, float, float) */ | |
int dreg = load_simd_vreg (cfg, cmethod, args [0], NULL); | |
int sreg = args [1]->dreg; | |
ins = emit_simd_ins (cfg, klass, OP_INSERT_R4, sreg, args [2]->dreg); | |
ins->inst_c0 = 2; | |
ins = emit_simd_ins (cfg, klass, OP_INSERT_R4, ins->dreg, args [3]->dreg); | |
ins->inst_c0 = 3; | |
ins->dreg = dreg; | |
return ins; | |
} else { | |
g_assert_not_reached (); | |
} | |
#endif |
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.
It is not supported yet, I created a new issue for the rest of vector constructors as it seems they don't work out of the box.
src/mono/mono/mini/mini-llvm.c
Outdated
|
||
if (mono_class_value_size (klass, NULL) == 12) | ||
len--; |
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 would add comment explaining this special case for easier comprehension.
Co-authored-by: Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com>
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.
LGTM, Thank you!
Basic SIMD support for System.Numerics.Vector3. Should fix #91456