Repository: dotnet/runtime
File: src/coreclr/jit/codegenriscv64.cpp (C++)

Code before:

    if ((desc.ExtendKind() != GenIntCastDesc::COPY) || (srcReg != dstReg))
    {
        switch (desc.ExtendKind())
        {
            case GenIntCastDesc::ZERO_EXTEND_SMALL_INT:
                if (desc.ExtendSrcSize() == 1)
                {
                    emit->emitIns_R_R_I(INS_andi, EA_PTRSIZE, dstReg, srcReg, 0xff);
                    break;
                }
                FALLTHROUGH;
            case GenIntCastDesc::SIGN_EXTEND_SMALL_INT:
            {
                bool isSignExtend = (desc.ExtendKind() == GenIntCastDesc::SIGN_EXTEND_SMALL_INT);
                if (compiler->compOpportunisticallyDependsOn(InstructionSet_Zbb))
                {
                    instruction extend = INS_none;
                    bool        isHalf = (desc.ExtendSrcSize() == 2);
                    if (isSignExtend)
                    {
                        extend = isHalf ? INS_sext_h : INS_sext_b;
                    }
                    else
                    {
                        assert(isHalf);
                        extend = INS_zext_h;
                    }
                    emit->emitIns_R_R(extend, EA_PTRSIZE, dstReg, srcReg);
                }
                else
                {
                    instruction shiftRight  = isSignExtend ? INS_srai : INS_srli;
                    unsigned    shiftAmount = 64 - desc.ExtendSrcSize() * 8;
                    emit->emitIns_R_R_I(INS_slli, EA_PTRSIZE, dstReg, srcReg, shiftAmount);
                    emit->emitIns_R_R_I(shiftRight, EA_PTRSIZE, dstReg, dstReg, shiftAmount);
                }
                break;
            }

            case GenIntCastDesc::ZERO_EXTEND_INT:
                if (compiler->compOpportunisticallyDependsOn(InstructionSet_Zba))
                {
                    emit->emitIns_R_R_R(INS_add_uw, EA_PTRSIZE, dstReg, srcReg, REG_R0);
                }
                else
                {
                    emit->emitIns_R_R_I(INS_slli, EA_PTRSIZE, dstReg, srcReg, 32);
                    emit->emitIns_R_R_I(INS_srli, EA_PTRSIZE, dstReg, dstReg, 32);
                }
                break;

Review comment (suggestion):
While you're here, `slliw, 0` is also a leftover after bring-up, you can use `sext.w`.
(in code above, GH comment can't reach there)

Code after:
                    emit->emitIns_R_R_I(shiftRight, EA_PTRSIZE, dstReg, dstReg, shiftAmount);
                }
                break;
            }

            case GenIntCastDesc::ZERO_EXTEND_INT:
                if (compiler->compOpportunisticallyDependsOn(InstructionSet_Zba))
                {
                    emit->emitIns_R_R_R(INS_add_uw, EA_PTRSIZE, dstReg, srcReg, REG_R0);
                }
                else
                {
                    emit->emitIns_R_R_I(INS_slli, EA_PTRSIZE, dstReg, srcReg, 32);
                    emit->emitIns_R_R_I(INS_srli, EA_PTRSIZE, dstReg, dstReg, 32);
                }
                break;
            case GenIntCastDesc::SIGN_EXTEND_INT:
                emit->emitIns_R_R(INS_sext_w, EA_4BYTE, dstReg, srcReg);
                break;

            default:
                assert(desc.ExtendKind() == GenIntCastDesc::COPY);
                if (srcType == TYP_INT)
                {
                    emit->emitIns_R_R(INS_sext_w, EA_4BYTE, dstReg, srcReg);
                }
                else
                {
                    emit->emitIns_R_R(INS_mov, EA_PTRSIZE, dstReg, srcReg);
                }
                break;
        }
    }

    genProduceReg(cast);
}

//------------------------------------------------------------------------
// genFloatToFloatCast: Generate code for a cast between float and double
//
// Arguments:
//    treeNode - The GT_CAST node
//
// Return Value:
//    None.
//
// Assumptions:
//    Cast is a non-overflow conversion.
//    The treeNode must have an assigned register.
//    The cast is between float and double.
//