Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
897fdb9
Adding barebones Int128 and UInt128 structs
tannergooding Apr 11, 2022
2fe1618
Special case Int128 and UInt128 alignment on x64 Unix and Arm64
tannergooding May 2, 2022
6559609
Implementing Int128 and UInt128
tannergooding May 3, 2022
2c820b5
Adding tests for Int128 and UInt128
tannergooding May 7, 2022
e7970fb
Updating Int128/UInt128 to respect the System V ABI ordering
tannergooding May 11, 2022
828440f
Merge remote-tracking branch 'dotnet/main' into generic-math-int128
tannergooding May 11, 2022
6904e73
Fixing an issue with UInt128->BigInteger setting the wrong sign
tannergooding May 12, 2022
bcbc375
Merge remote-tracking branch 'dotnet/main' into generic-math-int128
tannergooding May 12, 2022
09e8bfc
Don't use Unsafe.As in the Int128/UInt128 hex parsing logic
tannergooding May 12, 2022
5f9d22f
Adding Int128 P/Invoke tests and ensure R2R correctly sets the packing
tannergooding May 13, 2022
b6b85e6
Fixing some issues with the Int128 interop test for non-Windows
tannergooding May 13, 2022
9de4e76
Ensure that floating-point conversions exist for Int128 and UInt128
tannergooding May 13, 2022
a1dc14f
Fixing the casing of a couple fields
tannergooding May 16, 2022
7666952
Revert "Don't use Unsafe.As in the Int128/UInt128 hex parsing logic"
tannergooding May 16, 2022
f0a30cb
Adjusting the Int128/UInt128 generic math tests to have consistent or…
tannergooding May 16, 2022
cb5a82e
Responding to PR feedback
tannergooding May 18, 2022
384e572
Ensure that pNativeLayoutInfo alignment is initialized for Int128/UIn…
tannergooding May 18, 2022
ab85c7b
Don't use Unsafe.As in the Int128/UInt128 hex parsing logic
tannergooding May 12, 2022
163cfda
Merge remote-tracking branch 'dotnet/main' into generic-math-int128
tannergooding May 19, 2022
cd3c9e9
Skip the Interop/PInvoke/Int128 tests on Mono
tannergooding May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implementing Int128 and UInt128
  • Loading branch information
tannergooding committed May 11, 2022
commit 655960965d345e795327dbf273fc4403687e76be
12 changes: 12 additions & 0 deletions src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@
<data name="Arg_MustBeInt64" xml:space="preserve">
<value>Object must be of type Int64.</value>
</data>
<data name="Arg_MustBeInt128" xml:space="preserve">
<value>Object must be of type Int128.</value>
</data>
<data name="Arg_MustBeIntPtr" xml:space="preserve">
<value>Object must be of type IntPtr.</value>
</data>
Expand Down Expand Up @@ -567,6 +570,9 @@
<data name="Arg_MustBeUInt64" xml:space="preserve">
<value>Object must be of type UInt64.</value>
</data>
<data name="Arg_MustBeUInt128" xml:space="preserve">
<value>Object must be of type UInt128.</value>
</data>
<data name="Arg_MustBeUIntPtr" xml:space="preserve">
<value>Object must be of type UIntPtr.</value>
</data>
Expand Down Expand Up @@ -3022,6 +3028,9 @@
<data name="Overflow_Int64" xml:space="preserve">
<value>Value was either too large or too small for an Int64.</value>
</data>
<data name="Overflow_Int128" xml:space="preserve">
<value>Value was either too large or too small for an Int128.</value>
</data>
<data name="Overflow_MutexReacquireCount" xml:space="preserve">
<value>The current thread attempted to reacquire a mutex that has reached its maximum acquire count.</value>
</data>
Expand Down Expand Up @@ -3049,6 +3058,9 @@
<data name="Overflow_UInt64" xml:space="preserve">
<value>Value was either too large or too small for a UInt64.</value>
</data>
<data name="Overflow_UInt128" xml:space="preserve">
<value>Value was either too large or too small for a UInt128.</value>
</data>
<data name="PlatformNotSupported_ArgIterator" xml:space="preserve">
<value>ArgIterator is not supported on this platform.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ namespace System.Buffers.Text
{
internal static partial class FormattingHelpers
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountDigits(UInt128 value)
{
ulong upper = value.Upper;

if (upper < 5)
{
return CountDigits(value.Lower);
}

int digits = 19;

if (upper > 5)
{
digits++;
value /= new UInt128(0x5, 0x6BC7_5E2D_6310_0000); // value /= 1e20
digits += CountDigits(value.Lower);
}
else if (value.Lower >= 0x6BC75E2D63100000)
{
digits++;
}

return digits;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountDigits(ulong value)
{
Expand Down Expand Up @@ -100,6 +126,13 @@ public static int CountDigits(uint value)
return digits;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountHexDigits(UInt128 value)
{
// The number of hex digits is log16(value) + 1, or log2(value) / 4 + 1
return ((int)UInt128.Log2(value) >> 2) + 1;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int CountHexDigits(ulong value)
{
Expand Down
63 changes: 49 additions & 14 deletions src/libraries/System.Private.CoreLib/src/System/IComparable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace System
{
// The IComparable interface is implemented by classes that support an
Expand All @@ -13,12 +11,31 @@ namespace System
public interface IComparable
{
// Interface does not need to be marked with the serializable attribute
// Compares this object to another object, returning an integer that
// indicates the relationship. An implementation of this method must return
// a value less than zero if this is less than object, zero
// if this is equal to object, or a value greater than zero
// if this is greater than object.
//

/// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.</summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns>
/// <para>A value that indicates the relative order of the objects being compared. The return value has these meanings:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <description>Meaning</description>
/// </listheader>
/// <item>
/// <term>Less than zero</term>
/// <description>This instance precedes <paramref name="obj" /> in the sort order.</description>
/// </item>
/// <item>
/// <term>Zero</term>
/// <description>This instance occurs in the same position in the sort order as <paramref name="obj" />.</description>
/// </item>
/// <item>
/// <term>Greater than zero</term>
/// <description>This instance follows <paramref name="obj" /> in the sort order.</description>
/// </item>
/// </list>
/// </returns>
/// <exception cref="ArgumentException"><paramref name="obj" /> is not the same type as this instance.</exception>
int CompareTo(object? obj);
}

Expand All @@ -27,12 +44,30 @@ public interface IComparable
public interface IComparable<in T>
{
// Interface does not need to be marked with the serializable attribute
// Compares this object to another object, returning an integer that
// indicates the relationship. An implementation of this method must return
// a value less than zero if this is less than object, zero
// if this is equal to object, or a value greater than zero
// if this is greater than object.
//

/// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.</summary>
/// <param name="other">An object to compare with this instance.</param>
/// <returns>
/// <para>A value that indicates the relative order of the objects being compared. The return value has these meanings:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <description>Meaning</description>
/// </listheader>
/// <item>
/// <term>Less than zero</term>
/// <description>This instance precedes <paramref name="other" /> in the sort order.</description>
/// </item>
/// <item>
/// <term>Zero</term>
/// <description>This instance occurs in the same position in the sort order as <paramref name="other" />.</description>
/// </item>
/// <item>
/// <term>Greater than zero</term>
/// <description>This instance follows <paramref name="other" /> in the sort order.</description>
/// </item>
/// </list>
/// </returns>
int CompareTo(T? other);
}
}
5 changes: 3 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/IEquatable.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace System
{
public interface IEquatable<T> // invariant due to questionable semantics around equality and inheritance
{
/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns><c>true</c> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <c>false</c>.</returns>
bool Equals(T? other);
}
}
Loading