Skip to content

Commit 2c9964f

Browse files
committed
Implement some of the convert methods, disable the rest.
1 parent 4b970d5 commit 2c9964f

File tree

4 files changed

+74
-35
lines changed

4 files changed

+74
-35
lines changed

src/mono/mono/mini/cpu-amd64.mdesc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ ones_complement: dest:x src1:x len:16 clob:1
606606
negate: dest:x src1:x len:24 clob:1
607607
xlower: dest:x src1:x len:16
608608
xupper: dest:x src1:x len:16
609+
convert_fp_to_si: dest:x src1:x len:16
610+
convert_si_to_fp: dest:x src1:x len:16
609611

610612
addps: dest:x src1:x src2:x len:4 clob:1
611613
divps: dest:x src1:x src2:x len:4 clob:1

src/mono/mono/mini/mini-amd64.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7414,6 +7414,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
74147414
amd64_movhlps_reg_reg (code, SIMD_TEMP_REG, ins->sreg1);
74157415
amd64_sse_movaps_reg_reg (code, ins->dreg, SIMD_TEMP_REG);
74167416
break;
7417+
case OP_CVT_FP_SI:
7418+
amd64_sse_cvttps2dq_reg_reg (code, ins->dreg, ins->sreg1);
7419+
break;
7420+
case OP_CVT_SI_FP:
7421+
amd64_sse_cvtdq2ps_reg_reg (code, ins->dreg, ins->sreg1);
7422+
break;
74177423
case OP_STOREX_MEMBASE_REG:
74187424
case OP_STOREX_MEMBASE:
74197425
amd64_sse_movups_membase_reg (code, ins->dreg, ins->inst_offset, ins->sreg1);

src/mono/mono/mini/mini-ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ MINI_OP(OP_CVT_SI_FP_SCALAR, "convert_si_to_fp_scalar", XREG, XREG, NONE)
18461846
/* inst_c1 is one of the MONO_TYPE_ constants */
18471847
MINI_OP(OP_NEGATION, "negate", XREG, XREG, NONE)
18481848
MINI_OP(OP_NEGATION_SCALAR, "negate_scalar", XREG, XREG, NONE)
1849+
/* Select bits from src2/src3 using src1 */
18491850
MINI_OP3(OP_BSL, "bitwise_select", XREG, XREG, XREG, XREG)
18501851
#endif // TARGET_ARM64 || TARGET_AMD64 || TARGET_WASM
18511852

src/mono/mono/mini/simd-intrinsics.c

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,30 +1403,6 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
14031403
#ifdef TARGET_WIN32
14041404
return NULL;
14051405
#endif
1406-
switch (id) {
1407-
case SN_ConditionalSelect:
1408-
case SN_ConvertToDouble:
1409-
case SN_ConvertToInt32:
1410-
case SN_ConvertToInt64:
1411-
case SN_ConvertToSingle:
1412-
case SN_ConvertToUInt32:
1413-
case SN_ConvertToUInt64:
1414-
case SN_ExtractMostSignificantBits:
1415-
case SN_Narrow:
1416-
case SN_Shuffle:
1417-
case SN_ToScalar:
1418-
case SN_ToVector128:
1419-
case SN_ToVector128Unsafe:
1420-
case SN_WidenLower:
1421-
case SN_WidenUpper:
1422-
return NULL;
1423-
case SN_GetLower:
1424-
case SN_GetUpper:
1425-
/* These return a Vector64 */
1426-
return NULL;
1427-
default:
1428-
break;
1429-
}
14301406
}
14311407
#endif
14321408

@@ -1541,9 +1517,22 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
15411517
#endif
15421518
}
15431519
case SN_ConditionalSelect: {
1544-
#if defined(TARGET_ARM64) || defined(TARGET_AMD64) || defined(TARGET_WASM)
15451520
if (!is_element_type_primitive (fsig->params [0]))
15461521
return NULL;
1522+
1523+
#if defined(TARGET_ARM64) || defined(TARGET_AMD64) || defined(TARGET_WASM)
1524+
1525+
#if defined(TARGET_AMD64)
1526+
if (!COMPILE_LLVM (cfg)) {
1527+
MonoInst *val1 = emit_simd_ins (cfg, klass, OP_XBINOP_FORCEINT, args [0]->dreg, args [1]->dreg);
1528+
val1->inst_c0 = XBINOP_FORCEINT_AND;
1529+
MonoInst *val2 = emit_simd_ins (cfg, klass, OP_VECTOR_ANDN, args [0]->dreg, args [2]->dreg);
1530+
MonoInst *ins = emit_simd_ins (cfg, klass, OP_XBINOP_FORCEINT, val1->dreg, val2->dreg);
1531+
ins->inst_c0 = XBINOP_FORCEINT_OR;
1532+
return ins;
1533+
}
1534+
#endif
1535+
15471536
return emit_simd_ins_for_sig (cfg, klass, OP_BSL, -1, arg0_type, fsig, args);
15481537
#else
15491538
return NULL;
@@ -1567,6 +1556,13 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
15671556
op = arg0_type == MONO_TYPE_I8 ? OP_CVT_SI_FP_SCALAR : OP_CVT_UI_FP_SCALAR;
15681557
else
15691558
op = arg0_type == MONO_TYPE_I8 ? OP_CVT_SI_FP : OP_CVT_UI_FP;
1559+
1560+
#ifdef TARGET_AMD64
1561+
// Fall back to the c# code
1562+
if (!COMPILE_LLVM (cfg))
1563+
return NULL;
1564+
#endif
1565+
15701566
return emit_simd_ins_for_sig (cfg, klass, op, -1, arg0_type, fsig, args);
15711567
#else
15721568
return NULL;
@@ -1585,6 +1581,13 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
15851581
}
15861582
#endif
15871583
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
1584+
1585+
#if defined(TARGET_AMD64)
1586+
if (!COMPILE_LLVM (cfg) && id == SN_ConvertToUInt32)
1587+
// FIXME:
1588+
return NULL;
1589+
#endif
1590+
15881591
int op = id == SN_ConvertToInt32 ? OP_CVT_FP_SI : OP_CVT_FP_UI;
15891592
return emit_simd_ins_for_sig (cfg, klass, op, -1, arg0_type, fsig, args);
15901593
#else
@@ -1611,6 +1614,13 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
16111614
op = size == 8 ? OP_CVT_FP_SI_SCALAR : OP_CVT_FP_SI;
16121615
else
16131616
op = size == 8 ? OP_CVT_FP_UI_SCALAR : OP_CVT_FP_UI;
1617+
1618+
#if defined(TARGET_AMD64)
1619+
if (!COMPILE_LLVM (cfg))
1620+
// FIXME:
1621+
return NULL;
1622+
#endif
1623+
16141624
return emit_simd_ins_for_sig (cfg, klass, op, -1, arg0_type, fsig, args);
16151625
#else
16161626
return NULL;
@@ -1628,6 +1638,13 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
16281638
#endif
16291639
#if defined(TARGET_ARM64) || defined(TARGET_AMD64)
16301640
int op = arg0_type == MONO_TYPE_I4 ? OP_CVT_SI_FP : OP_CVT_UI_FP;
1641+
1642+
#if defined(TARGET_AMD64)
1643+
if (!COMPILE_LLVM (cfg) && op == OP_CVT_UI_FP)
1644+
// FIXME:
1645+
return NULL;
1646+
#endif
1647+
16311648
return emit_simd_ins_for_sig (cfg, klass, op, -1, arg0_type, fsig, args);
16321649
#else
16331650
return NULL;
@@ -1906,6 +1923,13 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
19061923
if (!is_element_type_primitive (fsig->params [0]))
19071924
return NULL;
19081925
int op = id == SN_GetLower ? OP_XLOWER : OP_XUPPER;
1926+
1927+
#ifdef TARGET_AMD64
1928+
if (!COMPILE_LLVM (cfg))
1929+
/* These return a Vector64 */
1930+
return NULL;
1931+
#endif
1932+
19091933
return emit_simd_ins_for_sig (cfg, klass, op, 0, arg0_type, fsig, args);
19101934
}
19111935
case SN_GreaterThan:
@@ -2109,6 +2133,9 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
21092133
if (vector_size == 128 && (arg0_type == MONO_TYPE_I1 || arg0_type == MONO_TYPE_U1))
21102134
return emit_simd_ins_for_sig (cfg, klass, OP_XOP_OVR_X_X_X, INTRINS_AARCH64_ADV_SIMD_TBL1, 0, fsig, args);
21112135
return NULL;
2136+
#elif defined(TARGET_AMD64)
2137+
// FIXME:
2138+
return NULL;
21122139
#else
21132140
return NULL;
21142141
#endif
@@ -2255,16 +2282,19 @@ emit_sri_vector (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSignature *fsi
22552282
}
22562283
#endif
22572284
#if defined(TARGET_ARM64) || defined(TARGET_WASM)
2258-
int op = id == SN_WidenLower ? OP_XLOWER : OP_XUPPER;
2259-
MonoInst *lower_or_upper_half = emit_simd_ins_for_sig (cfg, klass, op, 0, arg0_type, fsig, args);
2260-
if (type_enum_is_float (arg0_type)) {
2261-
return emit_simd_ins (cfg, klass, OP_SIMD_FCVTL, lower_or_upper_half->dreg, -1);
2262-
} else {
2263-
int zero = alloc_ireg (cfg);
2264-
MONO_EMIT_NEW_ICONST (cfg, zero, 0);
2265-
op = type_enum_is_unsigned (arg0_type) ? OP_SIMD_USHLL : OP_SIMD_SSHLL;
2266-
return emit_simd_ins (cfg, klass, op, lower_or_upper_half->dreg, zero);
2267-
}
2285+
int op = id == SN_WidenLower ? OP_XLOWER : OP_XUPPER;
2286+
MonoInst *lower_or_upper_half = emit_simd_ins_for_sig (cfg, klass, op, 0, arg0_type, fsig, args);
2287+
if (type_enum_is_float (arg0_type)) {
2288+
return emit_simd_ins (cfg, klass, OP_SIMD_FCVTL, lower_or_upper_half->dreg, -1);
2289+
} else {
2290+
int zero = alloc_ireg (cfg);
2291+
MONO_EMIT_NEW_ICONST (cfg, zero, 0);
2292+
op = type_enum_is_unsigned (arg0_type) ? OP_SIMD_USHLL : OP_SIMD_SSHLL;
2293+
return emit_simd_ins (cfg, klass, op, lower_or_upper_half->dreg, zero);
2294+
}
2295+
#elif defined(TARGET_AMD64)
2296+
// FIXME:
2297+
return NULL;
22682298
#else
22692299
return NULL;
22702300
#endif

0 commit comments

Comments
 (0)