case NI_X86Base_BitScanForward:
{
assert(!varTypeIsSmall(type) && !varTypeIsLong(type));
+ int32_t value = GetConstantInt32(arg0VN);
- int32_t value = GetConstantInt32(arg0VN);
- uint32_t result = BitOperations::BitScanForward(static_cast<uint32_t>(value));
+ if (value == 0)
+ {
+ // bsf is undefined for 0
+ break;
+ }
+ uint32_t result = BitOperations::BitScanForward(static_cast<uint32_t>(value));
return VNForIntCon(static_cast<int32_t>(result));
}
case NI_X86Base_X64_BitScanForward:
{
assert(varTypeIsLong(type));
+ int64_t value = GetConstantInt64(arg0VN);
- int64_t value = GetConstantInt64(arg0VN);
- uint32_t result = BitOperations::BitScanForward(static_cast<uint64_t>(value));
+ if (value == 0)
+ {
+ // bsf is undefined for 0
+ break;
+ }
+ uint32_t result = BitOperations::BitScanForward(static_cast<uint64_t>(value));
return VNForLongCon(static_cast<int64_t>(result));
}
case NI_X86Base_BitScanReverse:
{
assert(!varTypeIsSmall(type) && !varTypeIsLong(type));
+ int32_t value = GetConstantInt32(arg0VN);
- int32_t value = GetConstantInt32(arg0VN);
- uint32_t result = BitOperations::BitScanReverse(static_cast<uint32_t>(value));
+ if (value == 0)
+ {
+ // bsr is undefined for 0
+ break;
+ }
+ uint32_t result = BitOperations::BitScanReverse(static_cast<uint32_t>(value));
return VNForIntCon(static_cast<int32_t>(result));
}
case NI_X86Base_X64_BitScanReverse:
{
assert(varTypeIsLong(type));
+ int64_t value = GetConstantInt64(arg0VN);
- int64_t value = GetConstantInt64(arg0VN);
- uint32_t result = BitOperations::BitScanReverse(static_cast<uint64_t>(value));
+ if (value == 0)
+ {
+ // bsr is undefined for 0
+ break;
+ }
+ uint32_t result = BitOperations::BitScanReverse(static_cast<uint64_t>(value));
return VNForLongCon(static_cast<int64_t>(result));
}
#endif // TARGET_XARCH
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
+public static class FloatingPointHelper<TSelf>
+ where TSelf : IFloatingPoint<TSelf>
+{
+ public static int GetExponentShortestBitLength(TSelf value)
+ => value.GetExponentShortestBitLength();
+}
+
+class Runtime_81460
+{
+ static int Main()
+ {
+ return (Test() == 0) ? 100 : 0;
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static int Test() =>
+ FloatingPointHelper<double>.GetExponentShortestBitLength(1.0);
+}