From a9d9b6deb361f8ca6dc2159ff069ad27ec1b82e2 Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Thu, 8 Sep 2022 10:55:38 +0000 Subject: [PATCH 1/8] [ppc64le] Fixed thunk address 8 byte alignment issue --- src/mono/mono/mini/mini-ppc.c | 17 ++++++++++++++--- src/mono/mono/mini/mini-ppc.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index d1b8fc9790783..bc97b497af93a 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -2732,6 +2732,9 @@ handle_thunk (MonoCompile *cfg, guchar *code, const guchar *target) if (!cfg->arch.thunks) { cfg->arch.thunks = cfg->thunks; cfg->arch.thunks_size = cfg->thunk_area; +#ifdef THUNK_ADDR_ALIGNMENT + cfg->arch.thunks = ALIGN_TO(cfg->arch.thunks, THUNK_ADDR_ALIGNMENT); +#endif } thunks = cfg->arch.thunks; thunks_size = cfg->arch.thunks_size; @@ -3907,11 +3910,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) if (cfg->compile_aot && ins->sreg1 == ppc_r12) { /* The trampolines clobber this */ ppc_mr (code, ppc_r29, ins->sreg1); - ppc_ldptr (code, ppc_r0, ins->inst_offset, ppc_r29); + ppc_ldptr (code, ppc_r12, ins->inst_offset, ppc_r29); } else { - ppc_ldptr (code, ppc_r0, ins->inst_offset, ins->sreg1); + ppc_ldptr (code, ppc_r12, ins->inst_offset, ins->sreg1); } - ppc_mtlr (code, ppc_r0); + ppc_mtlr (code, ppc_r12); ppc_blrl (code); /* FIXME: this should be handled somewhere else in the new jit */ code = emit_move_return_value (cfg, ins, code); @@ -5556,6 +5559,14 @@ mono_arch_emit_exceptions (MonoCompile *cfg) } set_code_cursor (cfg, code); + +#ifdef THUNK_ADDR_ALIGNMENT + /* We need to align thunks_offset to 8 byte boundary, hence allocating first 8 bytes + for padding purpose */ + if (cfg->thunk_area != 0) { + cfg->thunk_area += THUNK_ADDR_ALIGNMENT; + } +#endif } #endif diff --git a/src/mono/mono/mini/mini-ppc.h b/src/mono/mono/mini/mini-ppc.h index 0b962aac233d2..e872c4b99c538 100644 --- a/src/mono/mono/mini/mini-ppc.h +++ b/src/mono/mono/mini/mini-ppc.h @@ -35,6 +35,7 @@ #ifdef TARGET_POWERPC64 #if !defined(PPC_USES_FUNCTION_DESCRIPTOR) #define THUNK_SIZE 8 +#define THUNK_ADDR_ALIGNMENT 8 #define GET_MEMORY_SLOT_THUNK_ADDRESS(c) \ ((guint64)(((c)) [0] & 0x0000ffff) << 48) \ + ((guint64)(((c)) [1] & 0x0000ffff) << 32) \ From 3531291e6c796fbebb747a84a0342b480ae81a6f Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Wed, 19 Oct 2022 06:29:54 +0000 Subject: [PATCH 2/8] Fixed FSharp crash issue --- src/mono/mono/mini/mini-ppc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index a2d8c5a714e3b..db669f8b5da0f 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -3782,23 +3782,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_addis (code, ppc_r12, cfg->frame_reg, ppc_ha(cfg->stack_usage)); ppc_addi (code, ppc_r12, ppc_r12, cfg->stack_usage); } - if (!cfg->method->save_lmf) { - pos = 0; - for (i = 31; i >= 13; --i) { - if (cfg->used_int_regs & (1 << i)) { - pos += sizeof (target_mgreg_t); - ppc_ldptr (code, i, -pos, ppc_r12); - } - } - } else { - /* FIXME restore from MonoLMF: though this can't happen yet */ - } /* Copy arguments on the stack to our argument area */ if (call->stack_usage) { code = emit_memcpy (code, call->stack_usage, ppc_r12, PPC_STACK_PARAM_OFFSET, ppc_sp, PPC_STACK_PARAM_OFFSET); /* r12 was clobbered */ - g_assert (cfg->frame_reg == ppc_sp); if (ppc_is_imm16 (cfg->stack_usage)) { ppc_addi (code, ppc_r12, cfg->frame_reg, cfg->stack_usage); } else { @@ -3809,6 +3797,18 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } + if (!cfg->method->save_lmf) { + pos = 0; + for (i = 31; i >= 13; --i) { + if (cfg->used_int_regs & (1 << i)) { + pos += sizeof (target_mgreg_t); + ppc_ldptr (code, i, -pos, ppc_r12); + } + } + } else { + /* FIXME restore from MonoLMF: though this can't happen yet */ + } + ppc_mr (code, ppc_sp, ppc_r12); mono_add_patch_info (cfg, (guint8*) code - cfg->native_code, MONO_PATCH_INFO_METHOD_JUMP, call->method); cfg->thunk_area += THUNK_SIZE; From 96f7c4dfe62f03ebe82b8228dd2ee9dde93cc4e1 Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Fri, 21 Oct 2022 09:11:24 +0000 Subject: [PATCH 3/8] [ppc64le] Implementation of mono_arch_get_delegate_virtual_invoke_impl method for ppc64le architecture --- src/mono/mono/mini/mini-ppc.c | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index db669f8b5da0f..73a26c02b18aa 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -470,10 +470,54 @@ mono_arch_get_delegate_invoke_impl (MonoMethodSignature *sig, gboolean has_targe return start; } +/** + * + * @brief Architecture-specific delegation virtual trampoline processing + * + * @param[in] @sig - Method signature + * @param[in] @method - Method + * @param[in] @offset - Offset into vtable + * @param[in] @load_imt_reg - Whether to load the LMT register + * @returns Trampoline + * + * Return a pointer to a delegation virtual trampoline + */ + gpointer mono_arch_get_delegate_virtual_invoke_impl (MonoMethodSignature *sig, MonoMethod *method, int offset, gboolean load_imt_reg) { - return NULL; + guint8 *code, *start; + int size = 32; + + start = code = (guint8 *) mono_global_codeman_reserve (size); + + /* + * Replace the "this" argument with the target + */ + ppc_mr (code, ppc_r12, ppc_r3); + ppc_ldptr (code, ppc_r3, MONO_STRUCT_OFFSET(MonoDelegate, target), ppc_r12); + + /* + * Load the IMT register, if needed + */ + if (load_imt_reg) { + ppc_ldptr (code, MONO_ARCH_IMT_REG, MONO_STRUCT_OFFSET(MonoDelegate, method), ppc_r12); + } + + /* + * Load the vTable + */ + ppc_ldptr (code, ppc_r12, MONO_STRUCT_OFFSET(MonoObject, vtable), ppc_r3); + if (!ppc_is_imm16(offset)) + ppc_addis (code, ppc_r12, ppc_r12, ppc_ha(offset)); + ppc_ldptr (code, ppc_r12, offset, ppc_r12); + ppc_mtctr (code, ppc_r12); + ppc_bcctr (code, PPC_BR_ALWAYS, 0); + + mono_arch_flush_icache (start, code - start); + MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_DELEGATE_INVOKE, NULL)); + + return(start); } gpointer From 6a05d50d9a91f5244aae32ccf0e3ab83a587e3ff Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Wed, 9 Nov 2022 12:16:52 +0000 Subject: [PATCH 4/8] Fixed clang15 build issues and returning address of sc_sp instead of value --- src/mono/mono/mini/mini-ppc.c | 4 ++-- src/mono/mono/mini/tramp-ppc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index 73a26c02b18aa..ced67ccc78d27 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -2777,7 +2777,7 @@ handle_thunk (MonoCompile *cfg, guchar *code, const guchar *target) cfg->arch.thunks = cfg->thunks; cfg->arch.thunks_size = cfg->thunk_area; #ifdef THUNK_ADDR_ALIGNMENT - cfg->arch.thunks = ALIGN_TO(cfg->arch.thunks, THUNK_ADDR_ALIGNMENT); + cfg->arch.thunks = (guint8 *)ALIGN_TO(cfg->arch.thunks, THUNK_ADDR_ALIGNMENT); #endif } thunks = cfg->arch.thunks; @@ -5930,7 +5930,7 @@ host_mgreg_t* mono_arch_context_get_int_reg_address (MonoContext *ctx, int reg) { if (reg == ppc_r1) - return (host_mgreg_t)(gsize)MONO_CONTEXT_GET_SP (ctx); + return (host_mgreg_t *)(gsize)&ctx->sc_sp; return &ctx->regs [reg]; } diff --git a/src/mono/mono/mini/tramp-ppc.c b/src/mono/mono/mini/tramp-ppc.c index 59bcb275a4860..e0bc7f8eca42f 100644 --- a/src/mono/mono/mini/tramp-ppc.c +++ b/src/mono/mono/mini/tramp-ppc.c @@ -672,10 +672,10 @@ mono_arch_get_call_target (guint8 *code) } #if defined(TARGET_POWERPC64) && !defined(PPC_USES_FUNCTION_DESCRIPTOR) else if (((guint32*)(code - 32)) [0] >> 26 == 15) { - guint8 *thunk = GET_MEMORY_SLOT_THUNK_ADDRESS((guint32*)(code - 32)); + guint8 *thunk = (guint8 *)GET_MEMORY_SLOT_THUNK_ADDRESS((guint32*)(code - 32)); return thunk; } else if (((guint32*)(code - 4)) [0] >> 26 == 15) { - guint8 *thunk = GET_MEMORY_SLOT_THUNK_ADDRESS((guint32*)(code - 4)); + guint8 *thunk = (guint8 *)GET_MEMORY_SLOT_THUNK_ADDRESS((guint32*)(code - 4)); return thunk; } #endif From 1a1a0e25ba9fc8725e7df429b5d1624f859f0c48 Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Thu, 11 May 2023 12:19:04 +0000 Subject: [PATCH 5/8] Added float32 support and implemented related opcodes --- src/mono/mono/arch/ppc/ppc-codegen.h | 4 +++ src/mono/mono/mini/cpu-ppc64.mdesc | 36 ++++++++++++++++++-- src/mono/mono/mini/mini-ppc.c | 51 ++++++++++++++++++++++++++-- src/mono/mono/mini/mini-ppc.h | 1 + 4 files changed, 87 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/arch/ppc/ppc-codegen.h b/src/mono/mono/arch/ppc/ppc-codegen.h index 291337fd176a6..52e2b17ef12dc 100644 --- a/src/mono/mono/arch/ppc/ppc-codegen.h +++ b/src/mono/mono/arch/ppc/ppc-codegen.h @@ -793,6 +793,10 @@ my and Ximian's copyright to this code. ;) #define ppc_fcfid(c,D,B) ppc_fcfidx(c,D,B,0) #define ppc_fcfidd(c,D,B) ppc_fcfidx(c,D,B,1) +#define ppc_fcfidsx(c,D,B,Rc) ppc_emit32(c, (59 << 26) | ((D) << 21) | (0 << 16) | ((B) << 11) | (846 << 1) | (Rc)) +#define ppc_fcfids(c,D,B) ppc_fcfidsx(c,D,B,0) +#define ppc_fcfidsd(c,D,B) ppc_fcfidsx(c,D,B,1) + #define ppc_fctidx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | ((D) << 21) | (0 << 16) | ((B) << 11) | (814 << 1) | (Rc)) #define ppc_fctid(c,D,B) ppc_fctidx(c,D,B,0) #define ppc_fctidd(c,D,B) ppc_fctidx(c,D,B,1) diff --git a/src/mono/mono/mini/cpu-ppc64.mdesc b/src/mono/mono/mini/cpu-ppc64.mdesc index 77d99656d7215..3d892d944462f 100644 --- a/src/mono/mono/mini/cpu-ppc64.mdesc +++ b/src/mono/mono/mini/cpu-ppc64.mdesc @@ -229,6 +229,38 @@ ppc_subfze: dest:i src1:i len:4 bigmul: len:12 dest:i src1:i src2:i bigmul_un: len:12 dest:i src1:i src2:i +# R4 opcodes +r4_conv_to_i1: dest:i src1:f len:40 +r4_conv_to_u1: dest:i src1:f len:40 +r4_conv_to_i2: dest:i src1:f len:40 +r4_conv_to_u2: dest:i src1:f len:40 +r4_conv_to_i4: dest:i src1:f len:40 +r4_conv_to_u4: dest:i src1:f len:40 +r4_conv_to_i8: dest:i src1:f len:40 +r4_conv_to_u8: dest:i src1:f len:40 +r4_conv_to_r8: dest:f src1:f len:4 +r4_conv_to_r4: dest:f src1:f len:4 +r4_add: dest:f src1:f src2:f len:4 +r4_sub: dest:f src1:f src2:f len:4 +r4_mul: dest:f src1:f src2:f len:4 +r4_div: dest:f src1:f src2:f len:4 +r4_rem: dest:f src1:f src2:f len:16 +r4_neg: dest:f src1:f len:4 +r4_ceq: dest:i src1:f src2:f len:16 +r4_cgt: dest:i src1:f src2:f len:16 +r4_cgt_un: dest:i src1:f src2:f len:20 +r4_clt: dest:i src1:f src2:f len:16 +r4_clt_un: dest:i src1:f src2:f len:20 +r4_cneq: dest:i src1:f src2:f len:16 +r4_cge: dest:i src1:f src2:f len:16 +r4_cle: dest:i src1:f src2:f len:16 +rmove: dest:f src1:f len:4 +rcompare: src1:f src2:f len:12 +rcall_membase: dest:g src1:b len:16 clob:c +rcall_reg: dest:g src1:i len:16 clob:c +rcall: dest:g len:40 clob:c + + # Linear IR opcodes dummy_use: src1:i len:0 dummy_iconst: dest:i len:0 @@ -258,7 +290,7 @@ int_conv_to_i1: dest:i src1:i len:8 int_conv_to_i2: dest:i src1:i len:8 int_conv_to_i4: dest:i src1:i len:4 sext_i4: dest:i src1:i len:4 -int_conv_to_r4: dest:f src1:i len:20 +int_conv_to_r4: dest:f src1:i len:16 int_conv_to_r8: dest:f src1:i len:16 int_conv_to_u4: dest:i src1:i len:4 int_conv_to_u2: dest:i src1:i len:8 @@ -354,7 +386,7 @@ long_not: dest:i src1:i len:4 long_conv_to_i1: dest:i src1:i len:4 long_conv_to_i2: dest:i src1:i len:4 long_conv_to_i4: dest:i src1:i len:4 -long_conv_to_r4: dest:f src1:i len:16 +long_conv_to_r4: dest:f src1:i len:12 long_conv_to_r8: dest:f src1:i len:12 long_conv_to_u4: dest:i src1:i long_conv_to_u2: dest:i src1:i len:4 diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index ced67ccc78d27..cedd7c635c8a4 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -2690,6 +2690,7 @@ emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, { long offset = cfg->arch.fp_conv_var_offset; long sub_offset; + /* sreg is a float, dreg is an integer reg. ppc_f0 is used a scratch */ #ifdef TARGET_POWERPC64 if (size == 8) { @@ -3033,8 +3034,11 @@ emit_move_return_value (MonoCompile *cfg, MonoInst *ins, guint8 *code) { switch (ins->opcode) { case OP_FCALL: + case OP_RCALL: case OP_FCALL_REG: + case OP_RCALL_REG: case OP_FCALL_MEMBASE: + case OP_RCALL_MEMBASE: if (ins->dreg != ppc_f1) ppc_fmr (code, ins->dreg, ppc_f1); break; @@ -3763,6 +3767,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_mr (code, ppc_r4, saved); break; } + case OP_RMOVE: case OP_FMOVE: if (ins->dreg != ins->sreg1) ppc_fmr (code, ins->dreg, ins->sreg1); @@ -3894,6 +3899,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_stptr (code, ppc_r0, 0, ins->sreg1); break; } + case OP_RCALL: case OP_FCALL: case OP_LCALL: case OP_VCALL: @@ -3916,6 +3922,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) /* FIXME: this should be handled somewhere else in the new jit */ code = emit_move_return_value (cfg, ins, code); break; + case OP_RCALL_REG: case OP_FCALL_REG: case OP_LCALL_REG: case OP_VCALL_REG: @@ -3945,6 +3952,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) /* FIXME: this should be handled somewhere else in the new jit */ code = emit_move_return_value (cfg, ins, code); break; + case OP_RCALL_MEMBASE: case OP_FCALL_MEMBASE: case OP_LCALL_MEMBASE: case OP_VCALL_MEMBASE: @@ -4266,21 +4274,27 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case CEE_CONV_R4: /* FIXME: change precision */ case CEE_CONV_R8: g_assert_not_reached (); + case OP_RCONV_TO_I1: case OP_FCONV_TO_I1: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, TRUE); break; + case OP_RCONV_TO_U1: case OP_FCONV_TO_U1: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 1, FALSE); break; + case OP_RCONV_TO_I2: case OP_FCONV_TO_I2: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, TRUE); break; + case OP_RCONV_TO_U2: case OP_FCONV_TO_U2: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 2, FALSE); break; + case OP_RCONV_TO_I4: case OP_FCONV_TO_I4: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, TRUE); break; + case OP_RCONV_TO_U4: case OP_FCONV_TO_U4: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 4, FALSE); break; @@ -4339,21 +4353,35 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_SQRT: ppc_fsqrtd (code, ins->dreg, ins->sreg1); break; + case OP_RADD: + ppc_fadds (code, ins->dreg, ins->sreg1, ins->sreg2); + break; case OP_FADD: ppc_fadd (code, ins->dreg, ins->sreg1, ins->sreg2); break; + case OP_RSUB: + ppc_fsubs (code, ins->dreg, ins->sreg1, ins->sreg2); + break; case OP_FSUB: ppc_fsub (code, ins->dreg, ins->sreg1, ins->sreg2); break; + case OP_RMUL: + ppc_fmuls (code, ins->dreg, ins->sreg1, ins->sreg2); + break; case OP_FMUL: ppc_fmul (code, ins->dreg, ins->sreg1, ins->sreg2); break; + case OP_RDIV: + ppc_fdivs (code, ins->dreg, ins->sreg1, ins->sreg2); + break; case OP_FDIV: ppc_fdiv (code, ins->dreg, ins->sreg1, ins->sreg2); break; + case OP_RNEG: case OP_FNEG: ppc_fneg (code, ins->dreg, ins->sreg1); break; + case OP_RREM: case OP_FREM: /* emulated */ g_assert_not_reached (); @@ -4391,9 +4419,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_cmpl (code, 0, 1, ins->sreg1, ins->sreg2); ppc_iselgt (code, ins->dreg, ins->sreg1, ins->sreg2); break; + case OP_RCOMPARE: case OP_FCOMPARE: ppc_fcmpu (code, 0, ins->sreg1, ins->sreg2); break; + case OP_RCEQ: + case OP_RCNEQ: case OP_FCEQ: case OP_FCNEQ: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); @@ -4401,6 +4432,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_bc (code, ins->opcode == OP_FCEQ ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_EQ, 2); ppc_li (code, ins->dreg, 0); break; + case OP_RCLT: + case OP_RCGE: case OP_FCLT: case OP_FCGE: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); @@ -4408,6 +4441,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_bc (code, ins->opcode == OP_FCLT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_LT, 2); ppc_li (code, ins->dreg, 0); break; + case OP_RCLT_UN: case OP_FCLT_UN: ppc_fcmpu (code, 0, ins->sreg1, ins->sreg2); ppc_li (code, ins->dreg, 1); @@ -4415,6 +4449,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_bc (code, PPC_BR_TRUE, PPC_BR_LT, 2); ppc_li (code, ins->dreg, 0); break; + case OP_RCGT: + case OP_RCLE: case OP_FCGT: case OP_FCLE: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); @@ -4422,6 +4458,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_bc (code, ins->opcode == OP_FCGT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_GT, 2); ppc_li (code, ins->dreg, 0); break; + case OP_RCGT_UN: case OP_FCGT_UN: ppc_fcmpu (code, 0, ins->sreg1, ins->sreg2); ppc_li (code, ins->dreg, 1); @@ -4492,6 +4529,10 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_ZEXT_I4: ppc_clrldi (code, ins->dreg, ins->sreg1, 32); break; + case OP_RCONV_TO_R4: + case OP_RCONV_TO_R8: + ppc_mr (code, ins->dreg, ins->sreg1); + break; case OP_ICONV_TO_R4: case OP_ICONV_TO_R8: case OP_LCONV_TO_R4: @@ -4509,9 +4550,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_str (code, tmp, -8, ppc_r1); ppc_lfd (code, ins->dreg, -8, ppc_r1); } - ppc_fcfid (code, ins->dreg, ins->dreg); - if (ins->opcode == OP_ICONV_TO_R4 || ins->opcode == OP_LCONV_TO_R4) - ppc_frsp (code, ins->dreg, ins->dreg); + if (ins->opcode == OP_ICONV_TO_R4 || ins->opcode == OP_LCONV_TO_R4) { + ppc_fcfids (code, ins->dreg, ins->dreg); + } else { + ppc_fcfid (code, ins->dreg, ins->dreg); + } break; } case OP_LSHR: @@ -4544,9 +4587,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_LBLE_UN: EMIT_COND_BRANCH (ins, ins->opcode - OP_LBEQ); break; + case OP_RCONV_TO_I8: case OP_FCONV_TO_I8: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 8, TRUE); break; + case OP_RCONV_TO_U8: case OP_FCONV_TO_U8: code = emit_float_to_int (cfg, code, ins->dreg, ins->sreg1, 8, FALSE); break; diff --git a/src/mono/mono/mini/mini-ppc.h b/src/mono/mono/mini/mini-ppc.h index e872c4b99c538..5fd50f4b9830a 100644 --- a/src/mono/mono/mini/mini-ppc.h +++ b/src/mono/mono/mini/mini-ppc.h @@ -261,6 +261,7 @@ typedef struct MonoCompileArch { #define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1 #define MONO_ARCH_GSHARED_SUPPORTED 1 +#define MONO_ARCH_FLOAT32_SUPPORTED 1 #define MONO_ARCH_NEED_DIV_CHECK 1 #define MONO_ARCH_AOT_SUPPORTED 1 From 6b2758d850eb751bab272e6d29f23cf07d3369d1 Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Thu, 11 May 2023 13:43:01 +0000 Subject: [PATCH 6/8] Correction in OP_RCONV_TO_R cases --- src/mono/mono/mini/cpu-ppc64.mdesc | 1 - src/mono/mono/mini/mini-ppc.c | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mono/mono/mini/cpu-ppc64.mdesc b/src/mono/mono/mini/cpu-ppc64.mdesc index 3d892d944462f..8729c30d5c062 100644 --- a/src/mono/mono/mini/cpu-ppc64.mdesc +++ b/src/mono/mono/mini/cpu-ppc64.mdesc @@ -260,7 +260,6 @@ rcall_membase: dest:g src1:b len:16 clob:c rcall_reg: dest:g src1:i len:16 clob:c rcall: dest:g len:40 clob:c - # Linear IR opcodes dummy_use: src1:i len:0 dummy_iconst: dest:i len:0 diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index cedd7c635c8a4..4f522a1690850 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -2690,7 +2690,6 @@ emit_float_to_int (MonoCompile *cfg, guchar *code, int dreg, int sreg, int size, { long offset = cfg->arch.fp_conv_var_offset; long sub_offset; - /* sreg is a float, dreg is an integer reg. ppc_f0 is used a scratch */ #ifdef TARGET_POWERPC64 if (size == 8) { @@ -4531,7 +4530,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) break; case OP_RCONV_TO_R4: case OP_RCONV_TO_R8: - ppc_mr (code, ins->dreg, ins->sreg1); + ppc_fmr (code, ins->dreg, ins->sreg1); break; case OP_ICONV_TO_R4: case OP_ICONV_TO_R8: From fe1b890ce8b3756850ede66f79a57a8cab0ee5ae Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Wed, 24 May 2023 11:05:33 +0000 Subject: [PATCH 7/8] Corrected code for few opcodes --- src/mono/mono/mini/mini-ppc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index 4f522a1690850..3b9bdf2bcb985 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -4428,7 +4428,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_FCNEQ: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); ppc_li (code, ins->dreg, 1); - ppc_bc (code, ins->opcode == OP_FCEQ ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_EQ, 2); + ppc_bc (code, ins->opcode == OP_FCEQ || ins->opcode == OP_RCEQ ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_EQ, 2); ppc_li (code, ins->dreg, 0); break; case OP_RCLT: @@ -4437,7 +4437,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_FCGE: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); ppc_li (code, ins->dreg, 1); - ppc_bc (code, ins->opcode == OP_FCLT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_LT, 2); + ppc_bc (code, ins->opcode == OP_FCLT || ins->opcode == OP_RCLT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_LT, 2); ppc_li (code, ins->dreg, 0); break; case OP_RCLT_UN: @@ -4454,7 +4454,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_FCLE: ppc_fcmpo (code, 0, ins->sreg1, ins->sreg2); ppc_li (code, ins->dreg, 1); - ppc_bc (code, ins->opcode == OP_FCGT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_GT, 2); + ppc_bc (code, ins->opcode == OP_FCGT || ins->opcode == OP_RCGT ? PPC_BR_TRUE : PPC_BR_FALSE, PPC_BR_GT, 2); ppc_li (code, ins->dreg, 0); break; case OP_RCGT_UN: From a1fec64b93d3cd1767ff5b75004d4d86408ef5ba Mon Sep 17 00:00:00 2001 From: Alhad Deshpande Date: Fri, 11 Aug 2023 06:12:30 +0000 Subject: [PATCH 8/8] [ppc64le] performance improvements while branching --- src/mono/mono/mini/mini-ppc.c | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index 3b9bdf2bcb985..b3514123b7e94 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -297,7 +297,7 @@ gboolean mono_ppc_is_direct_call_sequence (guint32 *code) { #ifdef TARGET_POWERPC64 - g_assert(*code == 0x4e800021 || *code == 0x4e800020 || *code == 0x4e800420); + g_assert(*code == 0x4e800021 || *code == 0x4e800020 || *code == 0x4e800421 || *code == 0x4e800420); /* the thunk-less direct call sequence: lis/ori/sldi/oris/ori/mtlr/blrl */ if (ppc_opcode (code [-1]) == 31) { /* mtlr */ @@ -2939,7 +2939,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i return; } - if (prim == 15 || ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) { + if (prim == 15 || ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) { #ifdef TARGET_POWERPC64 #if !defined(PPC_USES_FUNCTION_DESCRIPTOR) handle_thunk (cfg, code, target); @@ -2948,7 +2948,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i guint32 *branch_ins; /* the trampoline code will try to patch the blrl, blr, bcctr */ - if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) { + if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) { branch_ins = seq; if (ppc_is_load_op (seq [-3]) || ppc_opcode (seq [-3]) == 31) /* ld || lwz || mr */ code -= 32; @@ -2996,7 +2996,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i #else guint32 *seq; /* the trampoline code will try to patch the blrl, blr, bcctr */ - if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800420) { + if (ins == 0x4e800021 || ins == 0x4e800020 || ins == 0x4e800421 || ins == 0x4e800420) { code -= 12; } /* this is the lis/ori/mtlr/blrl sequence */ @@ -3004,7 +3004,7 @@ ppc_patch_full (MonoCompile *cfg, guchar *code, const guchar *target, gboolean i g_assert ((seq [0] >> 26) == 15); g_assert ((seq [1] >> 26) == 24); g_assert ((seq [2] >> 26) == 31); - g_assert (seq [3] == 0x4e800021 || seq [3] == 0x4e800020 || seq [3] == 0x4e800420); + g_assert (seq [3] == 0x4e800021 || seq [3] == 0x4e800020 || seq [3] == 0x4e800421 || seq [3] == 0x4e800420); /* FIXME: make this thread safe */ ppc_lis (code, PPC_CALL_REG, (guint32)(target) >> 16); ppc_ori (code, PPC_CALL_REG, PPC_CALL_REG, (guint32)(target) & 0xffff); @@ -3426,8 +3426,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); } @@ -3913,8 +3913,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); } @@ -3945,9 +3945,9 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } } #endif - ppc_mtlr (code, ins->sreg1); + ppc_mtctr (code, ins->sreg1); #endif - ppc_blrl (code); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); /* FIXME: this should be handled somewhere else in the new jit */ code = emit_move_return_value (cfg, ins, code); break; @@ -3965,8 +3965,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) } else { ppc_ldptr (code, ppc_r12, ins->inst_offset, ins->sreg1); } - ppc_mtlr (code, ppc_r12); - ppc_blrl (code); + ppc_mtctr (code, ppc_r12); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); /* FIXME: this should be handled somewhere else in the new jit */ code = emit_move_return_value (cfg, ins, code); break; @@ -4022,8 +4022,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); } @@ -4040,8 +4040,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); } @@ -4725,8 +4725,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); } @@ -5348,8 +5348,8 @@ mono_arch_emit_prolog (MonoCompile *cfg) ppc_ldr (code, PPC_CALL_REG, 0, PPC_CALL_REG); cfg->thunk_area += THUNK_SIZE; #endif - ppc_mtlr (code, PPC_CALL_REG); - ppc_blrl (code); + ppc_mtctr (code, PPC_CALL_REG); + ppc_bcctrl (code, PPC_BR_ALWAYS, 0); } else { ppc_bl (code, 0); }