Skip to content

Commit 01108e8

Browse files
authored
[RISC-V] Integer min/max intrinsics (#114687)
* Intrinsify integer min/max * Implement integer min/max * Cleanup assert * Fix windows build * Add tests * Different VNFunc for unsigned * Min/Max is commutative * Different intrinsic name for unsigned
1 parent e901a03 commit 01108e8

File tree

13 files changed

+928
-429
lines changed

13 files changed

+928
-429
lines changed

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4718,6 +4718,18 @@ void CodeGen::genIntrinsic(GenTreeIntrinsic* treeNode)
47184718
case NI_System_Math_MaxNumber:
47194719
instr = is4 ? INS_fmax_s : INS_fmax_d;
47204720
break;
4721+
case NI_System_Math_Min:
4722+
instr = INS_min;
4723+
break;
4724+
case NI_System_Math_MinUnsigned:
4725+
instr = INS_minu;
4726+
break;
4727+
case NI_System_Math_Max:
4728+
instr = INS_max;
4729+
break;
4730+
case NI_System_Math_MaxUnsigned:
4731+
instr = INS_maxu;
4732+
break;
47214733
case NI_PRIMITIVE_LeadingZeroCount:
47224734
instr = is4 ? INS_clzw : INS_clz;
47234735
break;

src/coreclr/jit/emitriscv64.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ void emitter::emitIns_R_R_R(
826826
if ((INS_add <= ins && ins <= INS_and) || (INS_mul <= ins && ins <= INS_remuw) ||
827827
(INS_addw <= ins && ins <= INS_sraw) || (INS_fadd_s <= ins && ins <= INS_fmax_s) ||
828828
(INS_fadd_d <= ins && ins <= INS_fmax_d) || (INS_feq_s <= ins && ins <= INS_fle_s) ||
829-
(INS_feq_d <= ins && ins <= INS_fle_d) || (INS_lr_w <= ins && ins <= INS_amomaxu_d))
829+
(INS_feq_d <= ins && ins <= INS_fle_d) || (INS_lr_w <= ins && ins <= INS_amomaxu_d) ||
830+
(INS_min <= ins && ins <= INS_maxu))
830831
{
831832
#ifdef DEBUG
832833
switch (ins)
@@ -913,6 +914,11 @@ void emitter::emitIns_R_R_R(
913914
case INS_amominu_d:
914915
case INS_amomaxu_w:
915916
case INS_amomaxu_d:
917+
918+
case INS_min:
919+
case INS_minu:
920+
case INS_max:
921+
case INS_maxu:
916922
break;
917923
default:
918924
NYI_RISCV64("illegal ins within emitIns_R_R_R!");
@@ -4070,6 +4076,15 @@ void emitter::emitDispInsName(
40704076
return emitDispIllegalInstruction(code);
40714077
}
40724078
return;
4079+
case 0b0000101:
4080+
{
4081+
if ((opcode3 >> 2) != 1) // clmul[h] unsupported
4082+
return emitDispIllegalInstruction(code);
4083+
4084+
static const char names[][5] = {"min ", "minu", "max ", "maxu"};
4085+
printf("%s %s, %s, %s\n", names[opcode3 & 0b11], rd, rs1, rs2);
4086+
return;
4087+
}
40734088
default:
40744089
return emitDispIllegalInstruction(code);
40754090
}

src/coreclr/jit/gentree.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,10 +5404,12 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
54045404
case NI_System_Math_MaxMagnitude:
54055405
case NI_System_Math_MaxMagnitudeNumber:
54065406
case NI_System_Math_MaxNumber:
5407+
case NI_System_Math_MaxUnsigned:
54075408
case NI_System_Math_Min:
54085409
case NI_System_Math_MinMagnitude:
54095410
case NI_System_Math_MinMagnitudeNumber:
54105411
case NI_System_Math_MinNumber:
5412+
case NI_System_Math_MinUnsigned:
54115413
case NI_System_Math_Pow:
54125414
case NI_System_Math_Round:
54135415
case NI_System_Math_Sin:
@@ -5759,10 +5761,12 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
57595761
case NI_System_Math_MaxMagnitude:
57605762
case NI_System_Math_MaxMagnitudeNumber:
57615763
case NI_System_Math_MaxNumber:
5764+
case NI_System_Math_MaxUnsigned:
57625765
case NI_System_Math_Min:
57635766
case NI_System_Math_MinMagnitude:
57645767
case NI_System_Math_MinMagnitudeNumber:
57655768
case NI_System_Math_MinNumber:
5769+
case NI_System_Math_MinUnsigned:
57665770
{
57675771
level++;
57685772
break;
@@ -12758,6 +12762,9 @@ void Compiler::gtDispTree(GenTree* tree,
1275812762
case NI_System_Math_MaxNumber:
1275912763
printf(" maxNumber");
1276012764
break;
12765+
case NI_System_Math_MaxUnsigned:
12766+
printf(" maxUnsigned");
12767+
break;
1276112768
case NI_System_Math_Min:
1276212769
printf(" min");
1276312770
break;
@@ -12770,6 +12777,9 @@ void Compiler::gtDispTree(GenTree* tree,
1277012777
case NI_System_Math_MinNumber:
1277112778
printf(" minNumber");
1277212779
break;
12780+
case NI_System_Math_MinUnsigned:
12781+
printf(" minUnsigned");
12782+
break;
1277312783
case NI_System_Math_Pow:
1277412784
printf(" pow");
1277512785
break;

0 commit comments

Comments
 (0)