Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This ports DoubleToNum and supporting code to be a managed implementation. #19999

Merged
merged 11 commits into from Sep 20, 2018
Prev

Moving GetExponent/Mantissa and make BigInteger used fixed-sized buffer

  • Loading branch information...
tannergooding committed Sep 19, 2018
commit b5e398609aae0ff046ccf51434e9bd5516632912
@@ -44,22 +44,6 @@ namespace System
// We use this explicit definition to avoid the confusion between 0.0 and -0.0.
internal const double NegativeZero = -0.0;

[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetExponent(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (int)((bits >> 52) & 0x7FF);
}

[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static long GetMantissa(double d)
{
var bits = BitConverter.DoubleToInt64Bits(d);
return (bits & 0xFFFFFFFFFFFFF);
}

/// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary>
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -721,9 +721,11 @@ public void ShiftLeft(uint shift)
}
}

[StructLayout(LayoutKind.Sequential, Size = (MaxBlockCount * sizeof(uint)))]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct BlocksBuffer

This comment has been minimized.

Copy link
@jkotas

jkotas Sep 17, 2018

Member

fixed uint _buffer[MaxBlockCount] ?

This comment has been minimized.

Copy link
@tannergooding

tannergooding Sep 17, 2018

Author Member

Won't that cause a perf hit due to UnsafeValueTypeAttribute?

This comment has been minimized.

Copy link
@jkotas

jkotas Sep 17, 2018

Member

You can measure it.

You are using unsafe stackallocated buffers, so you do want to pay for the GS cookie checks. I assume that the C/C++ code paid for them too.

This comment has been minimized.

Copy link
@tannergooding

tannergooding Sep 17, 2018

Author Member

We should move to a C# 7.3 compiler version (we are still on 2.8.0-beta4 right now) so that we can index a fixed-buffer without pinning: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#indexing-fixed-fields-does-not-require-pinning

This comment has been minimized.

Copy link
@tannergooding

This comment has been minimized.

Copy link
@tannergooding

tannergooding Sep 17, 2018

Author Member

This is blocked more generally on: #19878 (comment).

{
private fixed uint _blocks[MaxBlockCount];

public ref uint this[int index]
{
get
@@ -2310,8 +2310,9 @@ private static unsafe void DoubleToNumber(double value, int precision, ref Numbe

private static long ExtractFractionAndBiasedExponent(double value, out int exponent)
{
long fraction = double.GetMantissa(value);
exponent = double.GetExponent(value);
var bits = BitConverter.DoubleToInt64Bits(value);
long fraction = (bits & 0xFFFFFFFFFFFFF);
exponent = (int)((bits >> 52) & 0x7FF);

if (exponent != 0)
{
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.