Skip to content
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

Minimally light up Quaternion and Plane for Mono SIMD #81541

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,11 @@ ovr_tag_from_mono_vector_class (MonoClass *klass) {
case 16: ret |= INTRIN_vector128; break;
}

if (!strcmp ("Vector4", m_class_get_name (klass)) || !strcmp ("Vector2", m_class_get_name (klass)))
const char *class_name = m_class_get_name (klass);
if (!strcmp ("Vector2", class_name) || !strcmp ("Vector4", class_name) || !strcmp ("Quaternion", class_name) || !strcmp ("Plane", class_name)) {
// FIXME: Support Vector3
return ret | INTRIN_float32;
}

MonoType *etype = mono_class_get_context (klass)->class_inst->type_argv [0];
switch (etype->type) {
Expand Down Expand Up @@ -650,7 +653,7 @@ simd_class_to_llvm_type (EmitContext *ctx, MonoClass *klass)
return LLVMVectorType (LLVMFloatType (), 4);
} else if (!strcmp (klass_name, "Vector3")) {
return LLVMVectorType (LLVMFloatType (), 4);
} else if (!strcmp (klass_name, "Vector4")) {
} else if (!strcmp (klass_name, "Vector4") || !strcmp (klass_name, "Quaternion") || !strcmp (klass_name, "Plane")) {
return LLVMVectorType (LLVMFloatType (), 4);
} else if (!strcmp (klass_name, "Vector`1") || !strcmp (klass_name, "Vector64`1") || !strcmp (klass_name, "Vector128`1") || !strcmp (klass_name, "Vector256`1") || !strcmp (klass_name, "Vector512`1")) {
MonoType *etype = mono_class_get_generic_class (klass)->context.class_inst->type_argv [0];
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -4347,8 +4347,8 @@ init_class (MonoClass *klass)
* The JIT can't handle SIMD types with != 16 size yet.
*/
if (!strcmp (m_class_get_name_space (klass), "System.Numerics")) {
//if (!strcmp (name, "Vector2") || !strcmp (name, "Vector3") || !strcmp (name, "Vector4"))
if (!strcmp (name, "Vector4"))
// FIXME: Support Vector2/Vector3
if (!strcmp (name, "Vector4") || !strcmp (name, "Quaternion") || !strcmp (name, "Plane"))
mono_class_set_is_simd_type (klass, TRUE);
}
#endif
Expand Down
46 changes: 29 additions & 17 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ emit_simd_ins_for_binary_op (MonoCompile *cfg, MonoClass *klass, MonoMethodSigna
instc0 = OP_FADD;
break;
case SN_Divide:
case SN_op_Division:
if (strcmp ("Vector4", m_class_get_name (klass)) && strcmp ("Vector2", m_class_get_name (klass))) {
case SN_op_Division: {
const char *class_name = m_class_get_name (klass);
if (strcmp ("Vector2", class_name) && strcmp ("Vector4", class_name) && strcmp ("Quaternion", class_name) && strcmp ("Plane", class_name)) {
if ((fsig->params [0]->type == MONO_TYPE_GENERICINST) && (fsig->params [1]->type != MONO_TYPE_GENERICINST)) {
MonoInst* ins = emit_simd_ins (cfg, klass, OP_CREATE_SCALAR_UNSAFE, args [1]->dreg, -1);
ins->inst_c1 = arg_type;
Expand All @@ -318,15 +319,17 @@ emit_simd_ins_for_binary_op (MonoCompile *cfg, MonoClass *klass, MonoMethodSigna
}
instc0 = OP_FDIV;
break;
}
case SN_Max:
instc0 = OP_FMAX;
break;
case SN_Min:
instc0 = OP_FMIN;
break;
case SN_Multiply:
case SN_op_Multiply:
if (strcmp ("Vector4", m_class_get_name (klass)) && strcmp ("Vector2", m_class_get_name (klass))) {
case SN_op_Multiply: {
const char *class_name = m_class_get_name (klass);
if (strcmp ("Vector2", class_name) && strcmp ("Vector4", class_name) && strcmp ("Quaternion", class_name) && strcmp ("Plane", class_name)) {
if (fsig->params [1]->type != MONO_TYPE_GENERICINST) {
MonoInst* ins = emit_simd_ins (cfg, klass, OP_CREATE_SCALAR_UNSAFE, args [1]->dreg, -1);
ins->inst_c1 = arg_type;
Expand All @@ -348,6 +351,7 @@ emit_simd_ins_for_binary_op (MonoCompile *cfg, MonoClass *klass, MonoMethodSigna
}
instc0 = OP_FMUL;
break;
}
case SN_Subtract:
case SN_op_Subtraction:
instc0 = OP_FSUB;
Expand Down Expand Up @@ -551,11 +555,15 @@ emit_sum_vector (MonoCompile *cfg, MonoType *vector_type, MonoTypeEnum element_t
MonoClass *vector_class = mono_class_from_mono_type_internal (vector_type);
int vector_size = mono_class_value_size (vector_class, NULL);
int element_size;
if (!strcmp ("Vector4", m_class_get_name (vector_class)))
element_size = vector_size / 4;
else if (!strcmp ("Vector2", m_class_get_name (vector_class)))

// FIXME: Support Vector3

const char *class_name = m_class_get_name (vector_class);
if (!strcmp ("Vector2", class_name)) {
element_size = vector_size / 2;
else {
} else if (!strcmp ("Vector4", class_name) || !strcmp ("Quaternion", class_name) || !strcmp ("Plane", class_name)) {
element_size = vector_size / 4;
} else {
MonoClass *element_class = mono_class_from_mono_type_internal (get_vector_t_elem_type (vector_type));
element_size = mono_class_value_size (element_class, NULL);
}
Expand Down Expand Up @@ -1438,7 +1446,7 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
int esize = mono_class_value_size (mono_class_from_mono_type_internal (etype), NULL);
elems = size / esize;
} else {
// This exists to handle the static extension methods for Vector2/3/4 and Quaterion
// This exists to handle the static extension methods for Vector2/3/4, Quaternion, and Plane
// which live on System.Numerics.Vector

arg0_type = MONO_TYPE_R4;
Expand Down Expand Up @@ -1703,7 +1711,7 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
int esize = mono_class_value_size (mono_class_from_mono_type_internal (etype), NULL);
elems = size / esize;
} else {
// This exists to handle the static extension methods for Vector2/3/4 and Quaterion
// This exists to handle the static extension methods for Vector2/3/4, Quaternion, and Plane
// which live on System.Numerics.Vector

arg0_type = MONO_TYPE_R4;
Expand Down Expand Up @@ -1866,12 +1874,13 @@ emit_vector64_vector128_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
return NULL;
}

// System.Numerics.Vector2/Vector3/Vector4
// System.Numerics.Vector2/Vector3/Vector4, Quaternion, and Plane
static guint16 vector2_methods[] = {
SN_ctor,
SN_Abs,
SN_Add,
SN_Clamp,
SN_Conjugate,
SN_CopyTo,
SN_Distance,
SN_DistanceSquared,
Expand All @@ -1887,6 +1896,7 @@ static guint16 vector2_methods[] = {
SN_Normalize,
SN_SquareRoot,
SN_Subtract,
SN_get_Identity,
SN_get_Item,
SN_get_One,
SN_get_UnitW,
Expand Down Expand Up @@ -1999,6 +2009,7 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f
}
case SN_get_Zero:
return emit_xzero (cfg, klass);
case SN_get_Identity:
case SN_get_UnitX:
case SN_get_UnitY:
case SN_get_UnitZ:
Expand Down Expand Up @@ -2128,6 +2139,7 @@ emit_vector_2_3_4 (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *f

return min;
}
case SN_Conjugate:
case SN_Distance:
case SN_DistanceSquared:
case SN_Length:
Expand Down Expand Up @@ -4551,8 +4563,8 @@ arch_emit_simd_intrinsics (const char *class_ns, const char *class_name, MonoCom
}

if (!strcmp (class_ns, "System.Numerics")) {
//if (!strcmp ("Vector2", class_name) || !strcmp ("Vector4", class_name) || !strcmp ("Vector3", class_name))
if (!strcmp ("Vector4", class_name))
// FIXME: Support Vector2/Vector3
if (!strcmp (class_name, "Vector4") || !strcmp (class_name, "Quaternion") || !strcmp (class_name, "Plane"))
return emit_vector_2_3_4 (cfg, cmethod, fsig, args);
}

Expand All @@ -4575,8 +4587,8 @@ arch_emit_simd_intrinsics (const char *class_ns, const char *class_name, MonoCom
}

if (!strcmp (class_ns, "System.Numerics")) {
//if (!strcmp ("Vector2", class_name) || !strcmp ("Vector4", class_name) || !strcmp ("Vector3", class_name))
if (!strcmp ("Vector4", class_name))
// FIXME: Support Vector2/Vector3
if (!strcmp (class_name, "Vector4") || !strcmp (class_name, "Quaternion") || !strcmp (class_name, "Plane"))
return emit_vector_2_3_4 (cfg, cmethod, fsig, args);
}

Expand Down Expand Up @@ -4615,8 +4627,8 @@ arch_emit_simd_intrinsics (const char *class_ns, const char *class_name, MonoCom
}

if (!strcmp (class_ns, "System.Numerics")) {
//if (!strcmp ("Vector2", class_name) || !strcmp ("Vector4", class_name) || !strcmp ("Vector3", class_name))
if (!strcmp ("Vector4", class_name))
// FIXME: Support Vector2/Vector3
if (!strcmp (class_name, "Vector4") || !strcmp (class_name, "Quaternion") || !strcmp (class_name, "Plane"))
return emit_vector_2_3_4 (cfg, cmethod, fsig, args);
}

Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/simd-methods.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
METHOD2(".ctor", ctor)
METHOD(Clamp)
METHOD(Conjugate)
METHOD(CopyTo)
METHOD(Distance)
METHOD(DistanceSquared)
Expand Down Expand Up @@ -30,6 +31,7 @@ METHOD(get_Count)
METHOD(get_IsHardwareAccelerated)
METHOD(get_IsSupported)
METHOD(get_AllBitsSet)
METHOD(get_Identity)
METHOD(get_Item)
METHOD(get_One)
METHOD(get_UnitW)
Expand Down