From 1c75a5a5d992be99aed6364d2cfa5760ce1f64b6 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 3 Aug 2025 13:22:12 +0100 Subject: [PATCH 1/3] Remove some unnecessary `#if TARGET_64BIT` --- .../Runtime/CompilerServices/FunctionPointerOps.cs | 6 +----- .../System.Private.CoreLib/src/System/Single.cs | 9 ++------- .../System.Private.CoreLib/src/System/UIntPtr.cs | 7 +------ 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs index c0bceb7963c8ad..5e3b11fae1b2ef 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/FunctionPointerOps.cs @@ -112,11 +112,7 @@ public static unsafe IntPtr GetGenericMethodFunctionPointer(IntPtr canonFunction public static unsafe bool IsGenericMethodPointer(IntPtr functionPointer) { // Check the low bit to find out what kind of function pointer we have here. -#if TARGET_64BIT - if ((functionPointer.ToInt64() & FatFunctionPointerOffset) == FatFunctionPointerOffset) -#else - if ((functionPointer.ToInt32() & FatFunctionPointerOffset) == FatFunctionPointerOffset) -#endif + if ((functionPointer & FatFunctionPointerOffset) == FatFunctionPointerOffset) { return true; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index a724877c632b81..969955d18751f2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -1469,13 +1469,8 @@ private static bool TryConvertTo(float value, [MaybeNullWhen(false)] out else if (typeof(TOther) == typeof(nuint)) { #if MONO -#if TARGET_64BIT - nuint actualResult = (value >= ulong.MaxValue) ? unchecked((nuint)ulong.MaxValue) : - (value <= ulong.MinValue) ? unchecked((nuint)ulong.MinValue) : (nuint)value; -#else - nuint actualResult = (value >= uint.MaxValue) ? uint.MaxValue : - (value <= uint.MinValue) ? uint.MinValue : (nuint)value; -#endif + nuint actualResult = (value >= uint.MaxValue) ? nuint.MaxValue : + (value <= uint.MinValue) ? nuint.MinValue : (nuint)value; #else nuint actualResult = (nuint)value; #endif diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index d940ababf1c149..450160040fb4f7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -486,13 +486,8 @@ bool IBinaryInteger.TryWriteLittleEndian(Span destination, out int /// static nuint IBinaryNumber.AllBitsSet { -#if TARGET_64BIT - [NonVersionable] - get => unchecked((nuint)0xFFFF_FFFF_FFFF_FFFF); -#else [NonVersionable] - get => (nuint)0xFFFF_FFFF; -#endif + get => unchecked((nuint)nuint_t.MaxValue); } /// From b3b41749da55a6f1a9cdef26d2674508769f974d Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 5 Aug 2025 01:35:54 +0100 Subject: [PATCH 2/3] fix typo --- src/libraries/System.Private.CoreLib/src/System/Single.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 969955d18751f2..5b95aa41dcc757 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -1469,8 +1469,8 @@ private static bool TryConvertTo(float value, [MaybeNullWhen(false)] out else if (typeof(TOther) == typeof(nuint)) { #if MONO - nuint actualResult = (value >= uint.MaxValue) ? nuint.MaxValue : - (value <= uint.MinValue) ? nuint.MinValue : (nuint)value; + nuint actualResult = (value >= nuint.MaxValue) ? nuint.MaxValue : + (value <= nuint.MinValue) ? nuint.MinValue : (nuint)value; #else nuint actualResult = (nuint)value; #endif From 249a2f2a2e266ffab2ce9b46cb1476b25377c05b Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Fri, 29 Aug 2025 20:07:57 +0100 Subject: [PATCH 3/3] change `Double` --- .../System.Private.CoreLib/src/System/Double.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 30630a6eb54783..105ded07251522 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -1450,13 +1450,8 @@ private static bool TryConvertTo(double value, [MaybeNullWhen(false)] ou else if (typeof(TOther) == typeof(nuint)) { #if MONO -#if TARGET_64BIT - nuint actualResult = (value >= ulong.MaxValue) ? unchecked((nuint)ulong.MaxValue) : - (value <= ulong.MinValue) ? unchecked((nuint)ulong.MinValue) : (nuint)value; -#else - nuint actualResult = (value >= uint.MaxValue) ? uint.MaxValue : - (value <= uint.MinValue) ? uint.MinValue : (nuint)value; -#endif + nuint actualResult = (value >= nuint.MaxValue) ? nuint.MaxValue : + (value <= nuint.MinValue) ? nuint.MinValue : (nuint)value; #else nuint actualResult = (nuint)value; #endif