Skip to content

Commit 0ed2fa1

Browse files
committed
[mono][jit] Revert parts of '[mono] Remove the support for non r4fp, its not used by any supported platforms. (#82005)'
Some platforms don't support r4fp, so put back the general JIT support code. Force r4fp on platforms that support it. Fixes #84401.
1 parent e13f0dc commit 0ed2fa1

11 files changed

+41
-17
lines changed

src/mono/mono/mini/calls.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ ret_type_to_call_opcode (MonoCompile *cfg, MonoType *type, int calli, int virt)
111111
case MONO_TYPE_U8:
112112
return calli? OP_LCALL_REG: virt? OP_LCALL_MEMBASE: OP_LCALL;
113113
case MONO_TYPE_R4:
114-
return calli? OP_RCALL_REG: virt? OP_RCALL_MEMBASE: OP_RCALL;
114+
if (cfg->r4fp)
115+
return calli? OP_RCALL_REG: virt? OP_RCALL_MEMBASE: OP_RCALL;
116+
else
117+
return calli? OP_FCALL_REG: virt? OP_FCALL_MEMBASE: OP_FCALL;
115118
case MONO_TYPE_R8:
116119
return calli? OP_FCALL_REG: virt? OP_FCALL_MEMBASE: OP_FCALL;
117120
case MONO_TYPE_VALUETYPE:

src/mono/mono/mini/intrinsics.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ llvm_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
103103
MonoInst *ins = NULL;
104104
int opcode = 0;
105105
// Convert Math and MathF methods into LLVM intrinsics, e.g. MathF.Sin -> @llvm.sin.f32
106-
if (in_corlib && !strcmp (m_class_get_name (cmethod->klass), "MathF")) {
106+
if (in_corlib && !strcmp (m_class_get_name (cmethod->klass), "MathF") && cfg->r4fp) {
107107
// (float)
108108
if (fsig->param_count == 1 && fsig->params [0]->type == MONO_TYPE_R4) {
109109
if (!strcmp (cmethod->name, "Ceiling")) {
@@ -1524,7 +1524,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
15241524
#endif
15251525
break;
15261526
case MONO_TYPE_R4:
1527-
ins->type = GINT_TO_UINT8 (STACK_R4);
1527+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
15281528
break;
15291529
case MONO_TYPE_R8:
15301530
ins->type = STACK_R8;
@@ -1662,7 +1662,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
16621662
#endif
16631663
break;
16641664
case MONO_TYPE_R4:
1665-
ins->type = GINT_TO_UINT8 (STACK_R4);
1665+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
16661666
break;
16671667
case MONO_TYPE_R8:
16681668
ins->type = STACK_R8;

src/mono/mono/mini/method-to-ir.c

+16-13
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ mono_type_to_regmove (MonoCompile *cfg, MonoType *type)
337337
return OP_LMOVE;
338338
#endif
339339
case MONO_TYPE_R4:
340-
return OP_RMOVE;
340+
return cfg->r4fp ? OP_RMOVE : OP_FMOVE;
341341
case MONO_TYPE_R8:
342342
return OP_FMOVE;
343343
case MONO_TYPE_VALUETYPE:
@@ -483,8 +483,9 @@ add_widen_op (MonoCompile *cfg, MonoInst *ins, MonoInst **arg1_ref, MonoInst **a
483483
MonoInst *arg1 = *arg1_ref;
484484
MonoInst *arg2 = *arg2_ref;
485485

486-
if ((arg1->type == STACK_R4 && arg2->type == STACK_R8) ||
487-
(arg1->type == STACK_R8 && arg2->type == STACK_R4)) {
486+
if (cfg->r4fp &&
487+
((arg1->type == STACK_R4 && arg2->type == STACK_R8) ||
488+
(arg1->type == STACK_R8 && arg2->type == STACK_R4))) {
488489
MonoInst *conv;
489490

490491
/* Mixing r4/r8 is allowed by the spec */
@@ -826,7 +827,7 @@ mini_type_to_eval_stack_type (MonoCompile *cfg, MonoType *type, MonoInst *inst)
826827
inst->type = STACK_I8;
827828
return;
828829
case MONO_TYPE_R4:
829-
inst->type = GINT_TO_UINT8 (STACK_R4);
830+
inst->type = GINT_TO_UINT8 (cfg->r4_stack_type);
830831
break;
831832
case MONO_TYPE_R8:
832833
inst->type = STACK_R8;
@@ -1160,7 +1161,7 @@ type_from_op (MonoCompile *cfg, MonoInst *ins, MonoInst *src1, MonoInst *src2)
11601161
ins->opcode += ovf2ops_op_map [src1->type];
11611162
break;
11621163
case MONO_CEE_CONV_R4:
1163-
ins->type = GINT_TO_UINT8 (STACK_R4);
1164+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
11641165
ins->opcode += unops_op_map [src1->type];
11651166
break;
11661167
case MONO_CEE_CONV_R8:
@@ -1218,7 +1219,7 @@ type_from_op (MonoCompile *cfg, MonoInst *ins, MonoInst *src1, MonoInst *src2)
12181219
ins->type = STACK_I8;
12191220
break;
12201221
case OP_LOADR4_MEMBASE:
1221-
ins->type = GINT_TO_UINT8 (STACK_R4);
1222+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
12221223
break;
12231224
case OP_LOADR8_MEMBASE:
12241225
ins->type = STACK_R8;
@@ -1433,7 +1434,7 @@ mini_type_to_stack_type (MonoCompile *cfg, MonoType *t)
14331434
case MONO_TYPE_U8:
14341435
return STACK_I8;
14351436
case MONO_TYPE_R4:
1436-
return (MonoStackType)STACK_R4;
1437+
return (MonoStackType)cfg->r4_stack_type;
14371438
case MONO_TYPE_R8:
14381439
return STACK_R8;
14391440
case MONO_TYPE_VALUETYPE:
@@ -1916,7 +1917,7 @@ target_type_is_incompatible (MonoCompile *cfg, MonoType *target, MonoInst *arg)
19161917
return 1;
19171918
return 0;
19181919
case MONO_TYPE_R4:
1919-
if (arg->type != STACK_R4)
1920+
if (arg->type != cfg->r4_stack_type)
19201921
return 1;
19211922
return 0;
19221923
case MONO_TYPE_R8:
@@ -1979,6 +1980,8 @@ target_type_is_incompatible (MonoCompile *cfg, MonoType *target, MonoInst *arg)
19791980
static MonoInst*
19801981
convert_value (MonoCompile *cfg, MonoType *type, MonoInst *ins)
19811982
{
1983+
if (!cfg->r4fp)
1984+
return ins;
19821985
type = mini_get_underlying_type (type);
19831986
switch (type->type) {
19841987
case MONO_TYPE_R4:
@@ -2071,7 +2074,7 @@ check_call_signature (MonoCompile *cfg, MonoMethodSignature *sig, MonoInst **arg
20712074
return TRUE;
20722075
continue;
20732076
case MONO_TYPE_R4:
2074-
if (args [i]->type != STACK_R4)
2077+
if (args [i]->type != cfg->r4_stack_type)
20752078
return TRUE;
20762079
continue;
20772080
case MONO_TYPE_R8:
@@ -4636,7 +4639,7 @@ mini_emit_init_rvar (MonoCompile *cfg, int dreg, MonoType *rtype)
46364639
MONO_EMIT_NEW_ICONST (cfg, dreg, 0);
46374640
} else if (t == MONO_TYPE_I8 || t == MONO_TYPE_U8) {
46384641
MONO_EMIT_NEW_I8CONST (cfg, dreg, 0);
4639-
} else if (t == MONO_TYPE_R4) {
4642+
} else if (cfg->r4fp && t == MONO_TYPE_R4) {
46404643
MONO_INST_NEW (cfg, ins, OP_R4CONST);
46414644
ins->type = STACK_R4;
46424645
ins->inst_p0 = (void*)&r4_0;
@@ -4672,7 +4675,7 @@ emit_dummy_init_rvar (MonoCompile *cfg, int dreg, MonoType *rtype)
46724675
MONO_EMIT_NEW_DUMMY_INIT (cfg, dreg, OP_DUMMY_ICONST);
46734676
} else if (t == MONO_TYPE_I8 || t == MONO_TYPE_U8) {
46744677
MONO_EMIT_NEW_DUMMY_INIT (cfg, dreg, OP_DUMMY_I8CONST);
4675-
} else if (t == MONO_TYPE_R4) {
4678+
} else if (cfg->r4fp && t == MONO_TYPE_R4) {
46764679
MONO_EMIT_NEW_DUMMY_INIT (cfg, dreg, OP_DUMMY_R4CONST);
46774680
} else if (t == MONO_TYPE_R4 || t == MONO_TYPE_R8) {
46784681
MONO_EMIT_NEW_DUMMY_INIT (cfg, dreg, OP_DUMMY_R8CONST);
@@ -7278,10 +7281,10 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
72787281

72797282
dreg = alloc_freg (cfg);
72807283
EMIT_NEW_LOAD_MEMBASE (cfg, ins, OP_LOADR4_MEMBASE, dreg, cons->dreg, 0);
7281-
ins->type = GINT_TO_UINT8 (STACK_R4);
7284+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
72827285
} else {
72837286
MONO_INST_NEW (cfg, ins, OP_R4CONST);
7284-
ins->type = GINT_TO_UINT8 (STACK_R4);
7287+
ins->type = GINT_TO_UINT8 (cfg->r4_stack_type);
72857288
ins->dreg = alloc_dreg (cfg, STACK_R8);
72867289
ins->inst_p0 = f;
72877290
MONO_ADD_INS (cfg->cbb, ins);

src/mono/mono/mini/mini-amd64.h

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ typedef struct {
453453
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
454454
#define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1
455455
#define MONO_ARCH_HAVE_GENERAL_RGCTX_LAZY_FETCH_TRAMPOLINE 1
456+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
456457
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-i64:64-i128:128-n8:16:32:64-S128"
457458

458459
#define MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP

src/mono/mono/mini/mini-arm.h

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ typedef struct MonoCompileArch {
363363
#define MONO_ARCH_HAVE_OBJC_GET_SELECTOR 1
364364
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
365365
#define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1
366+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
366367
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-p:32:32-n32-S64"
367368

368369
#define MONO_ARCH_HAVE_INTERP_ENTRY_TRAMPOLINE 1

src/mono/mono/mini/mini-arm64.h

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ typedef struct {
177177
#define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1
178178
#define MONO_ARCH_HAVE_OPCODE_NEEDS_EMULATION 1
179179
#define MONO_ARCH_HAVE_DECOMPOSE_LONG_OPTS 1
180+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
180181
#define MONO_ARCH_HAVE_INTERP_PINVOKE_TRAMP 1
181182
#define MONO_ARCH_HAVE_INIT_MRGCTX 1
182183
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-i64:64-i128:128-n32:64-S128"

src/mono/mono/mini/mini-s390x.h

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct SeqPointInfo {
8383
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
8484
#define MONO_ARCH_HAVE_SETUP_RESUME_FROM_SIGNAL_HANDLER_CTX 1
8585
#define MONO_ARCH_HAVE_UNWIND_BACKTRACE 1
86+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
8687

8788
#define S390_STACK_ALIGNMENT 8
8889
#define S390_FIRST_ARG_REG s390_r2

src/mono/mono/mini/mini-wasm.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define MONO_ARCH_EMULATE_FCONV_TO_U4 1
3030
#define MONO_ARCH_NO_EMULATE_LONG_SHIFT_OPS 1
3131
#define MONO_ARCH_NO_EMULATE_LONG_MUL_OPTS 1
32+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
3233

3334
//mini-codegen stubs - this doesn't do anything
3435
#define MONO_ARCH_CALLEE_REGS (1 << 0)

src/mono/mono/mini/mini-x86.h

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ typedef struct {
229229
#define MONO_ARCH_HAVE_OP_TAILCALL_REG 1
230230
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
231231
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-p:32:32-n32-S128"
232+
#define MONO_ARCH_FLOAT32_SUPPORTED 1
232233
#define MONO_ARCH_NEED_SIMD_BANK 1
233234
#define MONO_ARCH_USE_SHARED_FP_SIMD_BANK 1
234235

src/mono/mono/mini/mini.c

+10
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,14 @@ mini_method_compile (MonoMethod *method, guint32 opts, JitFlags flags, int parts
31333133
try_llvm = mono_use_llvm || llvm;
31343134
#endif
31353135

3136+
#ifdef MONO_ARCH_FLOAT32_SUPPORTED
3137+
/* Force float32 mode on platforms where its supported */
3138+
opts |= MONO_OPT_FLOAT32;
3139+
#else
3140+
opts &= ~MONO_OPT_FLOAT32;
3141+
g_assert (!llvm);
3142+
#endif
3143+
31363144
restart_compile:
31373145
if (method_is_gshared) {
31383146
method_to_compile = method;
@@ -3209,6 +3217,8 @@ mini_method_compile (MonoMethod *method, guint32 opts, JitFlags flags, int parts
32093217

32103218
if (!is_simd_supported (cfg))
32113219
cfg->opt &= ~MONO_OPT_SIMD;
3220+
cfg->r4fp = (cfg->opt & MONO_OPT_FLOAT32) ? 1 : 0;
3221+
cfg->r4_stack_type = cfg->r4fp ? STACK_R4 : STACK_R8;
32123222

32133223
if (cfg->gen_seq_points)
32143224
cfg->seq_points = g_ptr_array_new ();

src/mono/mono/mini/mini.h

+2
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ typedef struct {
15011501
guint gshared : 1;
15021502
guint gsharedvt : 1;
15031503
guint gsharedvt_min : 1;
1504+
guint r4fp : 1;
15041505
guint llvm_only : 1;
15051506
guint interp : 1;
15061507
guint use_current_cpu : 1;
@@ -1512,6 +1513,7 @@ typedef struct {
15121513
guint deopt : 1;
15131514
guint prefer_instances : 1;
15141515
guint8 uses_simd_intrinsics;
1516+
int r4_stack_type;
15151517
gpointer debug_info;
15161518
guint32 lmf_offset;
15171519
guint16 *intvars;

0 commit comments

Comments
 (0)