From d89493a9617fe30c987b0d5903c98ddcd3319613 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 25 Oct 2023 14:12:02 -0700 Subject: [PATCH] Implement gsharedvt-in support. --- src/mono/mono/mini/mini-amd64-gsharedvt.c | 34 +++++++++++++--------- src/mono/mono/mini/mini-amd64-gsharedvt.h | 1 + src/mono/mono/mini/tramp-amd64-gsharedvt.c | 7 +++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/mono/mono/mini/mini-amd64-gsharedvt.c b/src/mono/mono/mini/mini-amd64-gsharedvt.c index 0aa2f1559006b3..d839cf858276f6 100644 --- a/src/mono/mono/mini/mini-amd64-gsharedvt.c +++ b/src/mono/mono/mini/mini-amd64-gsharedvt.c @@ -163,6 +163,7 @@ get_arg_slots (ArgInfo *ainfo, int **out_slots, gboolean is_source_argument) break; case ArgInDoubleSSEReg: case ArgInFloatSSEReg: + case ArgSIMDInSSEReg: nsrc = 1; src = g_malloc (nsrc * sizeof (int)); src [0] = map_freg (sreg); @@ -224,20 +225,21 @@ static void handle_marshal_when_dst_gsharedvt (ArgInfo *src_info, int *arg_marshal) { switch (src_info->storage) { - case ArgInIReg: - case ArgInDoubleSSEReg: - case ArgInFloatSSEReg: - case ArgValuetypeInReg: - case ArgOnStack: - *arg_marshal = GSHAREDVT_ARG_BYVAL_TO_BYREF; - break; - case ArgValuetypeAddrInIReg: - case ArgValuetypeAddrOnStack: - *arg_marshal = GSHAREDVT_ARG_NONE; - break; - default: - NOT_IMPLEMENTED; // See above - break; + case ArgInIReg: + case ArgInDoubleSSEReg: + case ArgInFloatSSEReg: + case ArgSIMDInSSEReg: + case ArgValuetypeInReg: + case ArgOnStack: + *arg_marshal = GSHAREDVT_ARG_BYVAL_TO_BYREF; + break; + case ArgValuetypeAddrInIReg: + case ArgValuetypeAddrOnStack: + *arg_marshal = GSHAREDVT_ARG_NONE; + break; + default: + NOT_IMPLEMENTED; // See above + break; } } @@ -331,6 +333,7 @@ mono_arch_get_gsharedvt_call_info (MonoMemoryManager *mem_manager, gpointer addr case ArgInIReg: case ArgInDoubleSSEReg: case ArgInFloatSSEReg: + case ArgSIMDInSSEReg: case ArgValuetypeInReg: case ArgOnStack: nsrc = get_arg_slots (src_info, &src, TRUE); @@ -500,6 +503,9 @@ mono_arch_get_gsharedvt_call_info (MonoMemoryManager *mem_manager, gpointer addr case ArgInFloatSSEReg: info->ret_marshal = GSHAREDVT_RET_R8; break; + case ArgSIMDInSSEReg: + info->ret_marshal = GSHAREDVT_RET_SIMD; + break; case ArgValuetypeAddrInIReg: break; default: diff --git a/src/mono/mono/mini/mini-amd64-gsharedvt.h b/src/mono/mono/mini/mini-amd64-gsharedvt.h index 539dff9ff51e16..fea5d385b7d968 100644 --- a/src/mono/mono/mini/mini-amd64-gsharedvt.h +++ b/src/mono/mono/mini/mini-amd64-gsharedvt.h @@ -37,6 +37,7 @@ typedef enum { GSHAREDVT_RET_I8, // 8 byte integer GSHAREDVT_RET_IREGS_1, // Load in first return register GSHAREDVT_RET_R8, // Double + GSHAREDVT_RET_SIMD, // SIMD GSHAREDVT_RET_NUM, } GSharedVtRetMarshal; diff --git a/src/mono/mono/mini/tramp-amd64-gsharedvt.c b/src/mono/mono/mini/tramp-amd64-gsharedvt.c index 43b575b9f3d7dd..57860c794829d5 100644 --- a/src/mono/mono/mini/tramp-amd64-gsharedvt.c +++ b/src/mono/mono/mini/tramp-amd64-gsharedvt.c @@ -224,7 +224,7 @@ mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot) /*callconv in regs */ caller_reg_area_offset = offset; - reg_area_size = ALIGN_TO ((n_arg_regs + n_arg_fregs) * 8, MONO_ARCH_FRAME_ALIGNMENT); + reg_area_size = ALIGN_TO ((n_arg_regs * 8) + (n_arg_fregs * 16), MONO_ARCH_FRAME_ALIGNMENT); offset += reg_area_size; framesize = offset; @@ -266,7 +266,7 @@ mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot) amd64_mov_membase_reg (code, AMD64_RSP, caller_reg_area_offset + i * 8, param_regs [i], sizeof (target_mgreg_t)); for (i = 0; i < n_arg_fregs; ++i) - amd64_sse_movsd_membase_reg (code, AMD64_RSP, caller_reg_area_offset + (i + n_arg_regs) * 8, i); + amd64_sse_movups_membase_reg (code, AMD64_RSP, caller_reg_area_offset + (n_arg_regs * 8) + (i * 16), i); /* TODO Allocate stack area used to pass arguments to the method */ @@ -411,6 +411,9 @@ mono_arch_get_gsharedvt_trampoline (MonoTrampInfo **info, gboolean aot) case GSHAREDVT_RET_R8: amd64_sse_movsd_reg_membase (code, AMD64_XMM0, AMD64_R11, 0); break; + case GSHAREDVT_RET_SIMD: + amd64_sse_movups_reg_membase (code, AMD64_XMM0, AMD64_R11, 0); + break; default: x86_breakpoint (code); /* can't handle specific case */ }