From e3e66d49c5c0d87459923e5d84ab5ea62febc612 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 28 Apr 2025 16:36:04 -0500 Subject: [PATCH 1/3] Allow xcast --- src/mono/mono/mini/intrinsics.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/mono/mono/mini/intrinsics.c b/src/mono/mono/mini/intrinsics.c index 6b8e8642259826..74aac70a5e9a07 100644 --- a/src/mono/mono/mini/intrinsics.c +++ b/src/mono/mono/mini/intrinsics.c @@ -737,12 +737,8 @@ MONO_RESTORE_WARNING #endif } } else if (mini_class_is_simd (cfg, tfrom_klass) && mini_class_is_simd (cfg, tto_klass)) { -#if TARGET_SIZEOF_VOID_P == 8 opcode = OP_XCAST; tto_stack = STACK_VTYPE; -#else - return NULL; -#endif } if (opcode == OP_LDADDR) { From 95f00da9f59573acb04c81f2d4b1f19e7d62eeff Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 5 May 2025 14:39:23 -0500 Subject: [PATCH 2/3] Handle more cases --- src/mono/mono/mini/intrinsics.c | 46 +++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/mono/mono/mini/intrinsics.c b/src/mono/mono/mini/intrinsics.c index 74aac70a5e9a07..459875b30f2635 100644 --- a/src/mono/mono/mini/intrinsics.c +++ b/src/mono/mono/mini/intrinsics.c @@ -710,6 +710,17 @@ MONO_RESTORE_WARNING opcode = (tto_type == MONO_TYPE_I2) ? OP_ICONV_TO_I2 : OP_ICONV_TO_U2; tto_stack = STACK_I4; } else if (size == 4) { +#if TARGET_SIZEOF_VOID_P == 4 + if (tto_type == MONO_TYPE_I) + tto_type = MONO_TYPE_I4; + else if (tto_type == MONO_TYPE_U) + tto_type = MONO_TYPE_U4; + + if (tfrom_type == MONO_TYPE_I) + tfrom_type = MONO_TYPE_I4; + else if (tfrom_type == MONO_TYPE_U) + tfrom_type = MONO_TYPE_U4; +#endif if ((tfrom_type == MONO_TYPE_R4) && ((tto_type == MONO_TYPE_I4) || (tto_type == MONO_TYPE_U4))) { opcode = OP_MOVE_F_TO_I4; tto_stack = STACK_I4; @@ -722,23 +733,30 @@ MONO_RESTORE_WARNING } } else if (size == 8) { #if TARGET_SIZEOF_VOID_P == 8 - if ((tfrom_type == MONO_TYPE_R8) && ((tto_type == MONO_TYPE_I8) || (tto_type == MONO_TYPE_U8))) { - opcode = OP_MOVE_F_TO_I8; - tto_stack = STACK_I8; - } else if ((tto_type == MONO_TYPE_R8) && ((tfrom_type == MONO_TYPE_I8) || (tfrom_type == MONO_TYPE_U8))) { - opcode = OP_MOVE_I8_TO_F; - tto_stack = STACK_R8; - } else { - opcode = OP_MOVE; - tto_stack = STACK_I8; - } -#else - return NULL; + if (tto_type == MONO_TYPE_I) + tto_type = MONO_TYPE_I8; + else if (tto_type == MONO_TYPE_U) + tto_type = MONO_TYPE_U8; + + if (tfrom_type == MONO_TYPE_I) + tfrom_type = MONO_TYPE_I8; + else if (tfrom_type == MONO_TYPE_U) + tfrom_type = MONO_TYPE_U8; #endif + if ((tfrom_type == MONO_TYPE_R8) && ((tto_type == MONO_TYPE_I8) || (tto_type == MONO_TYPE_U8))) { + opcode = OP_MOVE_F_TO_I8; + tto_stack = STACK_I8; + } else if ((tto_type == MONO_TYPE_R8) && ((tfrom_type == MONO_TYPE_I8) || (tfrom_type == MONO_TYPE_U8))) { + opcode = OP_MOVE_I8_TO_F; + tto_stack = STACK_R8; + } else { + opcode = OP_MOVE; + tto_stack = STACK_I8; + } } } else if (mini_class_is_simd (cfg, tfrom_klass) && mini_class_is_simd (cfg, tto_klass)) { - opcode = OP_XCAST; - tto_stack = STACK_VTYPE; + opcode = OP_XCAST; + tto_stack = STACK_VTYPE; } if (opcode == OP_LDADDR) { From 0a4010f1d38149371e53cffd3757900de9316c3c Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Tue, 6 May 2025 10:22:23 -0500 Subject: [PATCH 3/3] restrict the chang to wasm --- src/mono/mono/mini/intrinsics.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mono/mono/mini/intrinsics.c b/src/mono/mono/mini/intrinsics.c index 459875b30f2635..8c4edcb988ba0d 100644 --- a/src/mono/mono/mini/intrinsics.c +++ b/src/mono/mono/mini/intrinsics.c @@ -755,8 +755,12 @@ MONO_RESTORE_WARNING } } } else if (mini_class_is_simd (cfg, tfrom_klass) && mini_class_is_simd (cfg, tto_klass)) { +#if TARGET_SIZEOF_VOID_P == 8 || defined(TARGET_WASM) opcode = OP_XCAST; tto_stack = STACK_VTYPE; +#else + return NULL; +#endif } if (opcode == OP_LDADDR) {