@@ -4880,6 +4880,96 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
48804880 break;
48814881 }
48824882
4883+ case NI_System_BitConverter_DoubleToInt64Bits:
4884+ {
4885+ GenTree* op1 = impStackTop().val;
4886+ assert(varTypeIsFloating(op1));
4887+
4888+ if (op1->IsCnsFltOrDbl())
4889+ {
4890+ impPopStack();
4891+
4892+ double f64Cns = op1->AsDblCon()->gtDconVal;
4893+ retNode = gtNewLconNode(*reinterpret_cast<int64_t*>(&f64Cns));
4894+ }
4895+ #if TARGET_64BIT
4896+ else
4897+ {
4898+ // TODO-Cleanup: We should support this on 32-bit but it requires decomposition work
4899+ impPopStack();
4900+
4901+ if (op1->TypeGet() != TYP_DOUBLE)
4902+ {
4903+ op1 = gtNewCastNode(TYP_DOUBLE, op1, false, TYP_DOUBLE);
4904+ }
4905+ retNode = gtNewBitCastNode(TYP_LONG, op1);
4906+ }
4907+ #endif
4908+ break;
4909+ }
4910+
4911+ case NI_System_BitConverter_Int32BitsToSingle:
4912+ {
4913+ GenTree* op1 = impPopStack().val;
4914+ assert(varTypeIsInt(op1));
4915+
4916+ if (op1->IsIntegralConst())
4917+ {
4918+ int32_t i32Cns = (int32_t)op1->AsIntConCommon()->IconValue();
4919+ retNode = gtNewDconNode(*reinterpret_cast<float*>(&i32Cns), TYP_FLOAT);
4920+ }
4921+ else
4922+ {
4923+ retNode = gtNewBitCastNode(TYP_FLOAT, op1);
4924+ }
4925+ break;
4926+ }
4927+
4928+ case NI_System_BitConverter_Int64BitsToDouble:
4929+ {
4930+ GenTree* op1 = impStackTop().val;
4931+ assert(varTypeIsLong(op1));
4932+
4933+ if (op1->IsIntegralConst())
4934+ {
4935+ impPopStack();
4936+
4937+ int64_t i64Cns = op1->AsIntConCommon()->LngValue();
4938+ retNode = gtNewDconNode(*reinterpret_cast<double*>(&i64Cns));
4939+ }
4940+ #if TARGET_64BIT
4941+ else
4942+ {
4943+ // TODO-Cleanup: We should support this on 32-bit but it requires decomposition work
4944+ impPopStack();
4945+
4946+ retNode = gtNewBitCastNode(TYP_DOUBLE, op1);
4947+ }
4948+ #endif
4949+ break;
4950+ }
4951+
4952+ case NI_System_BitConverter_SingleToInt32Bits:
4953+ {
4954+ GenTree* op1 = impPopStack().val;
4955+ assert(varTypeIsFloating(op1));
4956+
4957+ if (op1->IsCnsFltOrDbl())
4958+ {
4959+ float f32Cns = (float)op1->AsDblCon()->gtDconVal;
4960+ retNode = gtNewIconNode(*reinterpret_cast<int32_t*>(&f32Cns));
4961+ }
4962+ else
4963+ {
4964+ if (op1->TypeGet() != TYP_FLOAT)
4965+ {
4966+ op1 = gtNewCastNode(TYP_FLOAT, op1, false, TYP_FLOAT);
4967+ }
4968+ retNode = gtNewBitCastNode(TYP_INT, op1);
4969+ }
4970+ break;
4971+ }
4972+
48834973 default:
48844974 break;
48854975 }
@@ -5518,6 +5608,53 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
55185608 result = NI_System_Activator_DefaultConstructorOf;
55195609 }
55205610 }
5611+ else if (strcmp(className, "BitConverter") == 0)
5612+ {
5613+ if (methodName[0] == 'D')
5614+ {
5615+ if (strcmp(methodName, "DoubleToInt64Bits") == 0)
5616+ {
5617+ result = NI_System_BitConverter_DoubleToInt64Bits;
5618+ }
5619+ else if (strcmp(methodName, "DoubleToUInt64Bits") == 0)
5620+ {
5621+ result = NI_System_BitConverter_DoubleToInt64Bits;
5622+ }
5623+ }
5624+ else if (methodName[0] == 'I')
5625+ {
5626+ if (strcmp(methodName, "Int32BitsToSingle") == 0)
5627+ {
5628+ result = NI_System_BitConverter_Int32BitsToSingle;
5629+ }
5630+ else if (strcmp(methodName, "Int64BitsToDouble") == 0)
5631+ {
5632+ result = NI_System_BitConverter_Int64BitsToDouble;
5633+ }
5634+ }
5635+ else if (methodName[0] == 'S')
5636+ {
5637+ if (strcmp(methodName, "SingleToInt32Bits") == 0)
5638+ {
5639+ result = NI_System_BitConverter_SingleToInt32Bits;
5640+ }
5641+ else if (strcmp(methodName, "SingleToUInt32Bits") == 0)
5642+ {
5643+ result = NI_System_BitConverter_SingleToInt32Bits;
5644+ }
5645+ }
5646+ else if (methodName[0] == 'U')
5647+ {
5648+ if (strcmp(methodName, "UInt32BitsToSingle") == 0)
5649+ {
5650+ result = NI_System_BitConverter_Int32BitsToSingle;
5651+ }
5652+ else if (strcmp(methodName, "UInt64BitsToDouble") == 0)
5653+ {
5654+ result = NI_System_BitConverter_Int64BitsToDouble;
5655+ }
5656+ }
5657+ }
55215658 else if (strcmp(className, "Math") == 0 || strcmp(className, "MathF") == 0)
55225659 {
55235660 if (strcmp(methodName, "Abs") == 0)
0 commit comments