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

Including FastFloat in parsing process #62301

Merged
merged 29 commits into from
Feb 8, 2022
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0b22f35
Including FastFloat in parsing process
CarlVerret Dec 2, 2021
9e04dd0
Merge branch 'dotnet:main' into 48646-FastFloat-integration
CarlVerret Dec 4, 2021
ba592e0
PR step 1 - adjusting code in regards to received comments.
CarlVerret Dec 4, 2021
c1bf2df
DigitsToUInt64 : Parsing batches of 8 digits with SWAR
CarlVerret Dec 4, 2021
93a4caa
Update src/libraries/System.Private.CoreLib/src/System/Number.NumberT…
CarlVerret Dec 4, 2021
458476e
Update src/libraries/System.Private.CoreLib/src/System/Number.NumberT…
CarlVerret Dec 4, 2021
a47557d
MaxMantissaFastPath fix
CarlVerret Dec 7, 2021
a288f30
Merge branch '48646-FastFloat-integration' of https://github.com/Carl…
CarlVerret Dec 7, 2021
1b5fd51
merge problem...
CarlVerret Dec 7, 2021
5ff2eef
Revert "merge problem..."
CarlVerret Dec 7, 2021
e71647e
removing an extra comparison for fast path.
CarlVerret Dec 7, 2021
7766fff
Merge branch 'dotnet:main' into 48646-FastFloat-integration
CarlVerret Dec 10, 2021
b76988b
According to PR review, all requested changes are in this commit.
CarlVerret Dec 12, 2021
aad8d4b
According to new serie of comments on this PR.
CarlVerret Dec 12, 2021
e1fd88e
Fixing formatting.
CarlVerret Dec 12, 2021
286aaaa
fixing sentence ending in comments
CarlVerret Dec 12, 2021
36cbbd4
Update THIRD-PARTY-NOTICES.TXT
CarlVerret Dec 13, 2021
9abe649
Merge branch 'dotnet:main' into 48646-FastFloat-integration
CarlVerret Dec 18, 2021
afc3413
Update src/libraries/System.Private.CoreLib/src/System/Number.NumberT…
CarlVerret Jan 22, 2022
94cae92
Identation of power of 5 table
CarlVerret Jan 22, 2022
364a7f8
some adjustements according to reviewer's requests.
CarlVerret Jan 23, 2022
2d8a9e5
Unnecessary assignment of a value to 'exponent'
CarlVerret Jan 23, 2022
6327a5b
removing excedent path for total digits < 7
CarlVerret Jan 31, 2022
36b9f5b
removing path for totaldigits <7
CarlVerret Jan 31, 2022
41fa641
getting rid of unused power of 10 table
CarlVerret Jan 31, 2022
8140f02
Renaming FastFloat specific values
CarlVerret Jan 31, 2022
795804d
renaming some variables and adjusting comments.
CarlVerret Jan 31, 2022
c86080b
Handle endianness swapping for BigEndian systems.
CarlVerret Feb 3, 2022
5d0efb9
Merge branch 'dotnet:main' into 48646-FastFloat-integration
CarlVerret Feb 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Numerics;
using Internal.Runtime.CompilerServices;

namespace System
{
Expand Down Expand Up @@ -107,9 +108,7 @@ public FloatingPointInfo(ushort denormalMantissaBits, ushort exponentBits, int m
MaxExponentFastPath = maxExponentFastPath;
}
}

private static readonly float[] s_Pow10SingleTable = new float[]
{
private static ReadOnlySpan<float> s_Pow10SingleTable => new float[]{
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
1e0f, // 10^0
1e1f, // 10^1
1e2f, // 10^2
Expand All @@ -123,8 +122,7 @@ public FloatingPointInfo(ushort denormalMantissaBits, ushort exponentBits, int m
1e10f, // 10^10
};

private static readonly double[] s_Pow10DoubleTable = new double[]
{
private static ReadOnlySpan<double> s_Pow10DoubleTable => new double[] {
1e0, // 10^0
1e1, // 10^1
1e2, // 10^2
Expand All @@ -150,7 +148,7 @@ public FloatingPointInfo(ushort denormalMantissaBits, ushort exponentBits, int m
1e22, // 10^22
};

private static readonly ulong[] s_Pow5128Table = {
private static ReadOnlySpan<ulong> s_Pow5128Table => new ulong[] {
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
0xeef453d6923bd65a, 0x113faa2906a13b3f,
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
0x9558b4661b6565f8, 0x4ac7ca59a424c507,
0xbaaee17fa23ebf76, 0x5d79bcf00d2df649,
Expand Down Expand Up @@ -1006,11 +1004,19 @@ private static uint DigitsToUInt32(byte* p, int count)
Debug.Assert((1 <= count) && (count <= 9));

byte* end = (p + count);
uint res = (uint)(p[0] - '0');
uint res = 0;

for (p++; p < end; p++)
// parse batches of 8 digits with SWAR
while (end - p >= 8)
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
{
res = (res * 100000000) + ParseEightDigitsUnrolled(p);
p += 8;
}

while (p != end)
{
res = (10 * res) + p[0] - '0';
++p;
}

return res;
Expand All @@ -1022,16 +1028,37 @@ private static ulong DigitsToUInt64(byte* p, int count)
Debug.Assert((1 <= count) && (count <= 19));

byte* end = (p + count);
ulong res = (ulong)(p[0] - '0');
ulong res = 0;

for (p++; p < end; p++)
// parse batches of 8 digits with SWAR
while (end - p >= 8)
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
{
res = (res * 100000000) + ParseEightDigitsUnrolled(p);
p += 8;
}

while (p!=end)
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
{
res = (10 * res) + p[0] - '0';
++p;
}

return res;
}


internal static uint ParseEightDigitsUnrolled(byte* chars)
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
{
ulong val = Unsafe.ReadUnaligned<ulong>(chars);
const ulong mask = 0x000000FF000000FF;
const ulong mul1 = 0x000F424000000064; // 100 + (1000000ULL << 32)
const ulong mul2 = 0x0000271000000001; // 1 + (10000ULL << 32)
val -= 0x3030303030303030;
val = (val * 10) + (val >> 8); // val = (val * 2561) >> 8;
val = (((val & mask) * mul1) + (((val >> 16) & mask) * mul2)) >> 32;
return (uint)val;
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved
}

private static ulong NumberToDoubleFloatingPointBits(ref NumberBuffer number, in FloatingPointInfo info)
{
Debug.Assert(info.DenormalMantissaBits == 52);
Expand Down Expand Up @@ -1065,7 +1092,7 @@ private static ulong NumberToDoubleFloatingPointBits(ref NumberBuffer number, in
ulong mantissa = DigitsToUInt64(src, (int)(totalDigits));

int exponent = (int)(number.Scale - integerDigitsPresent - fractionalDigitsPresent);
uint fastExponent = (uint)(Math.Abs(exponent));
int fastExponent = (Math.Abs(exponent));
CarlVerret marked this conversation as resolved.
Show resolved Hide resolved

// When the number of significant digits is less than or equal to MaxMantissaFastPath and the
// scale is less than or equal to MaxExponentFastPath, we can take some shortcuts and just rely
Expand Down Expand Up @@ -1137,7 +1164,7 @@ private static ushort NumberToHalfFloatingPointBits(ref NumberBuffer number, in
uint fractionalDigitsPresent = totalDigits - integerDigitsPresent;

int exponent = (int)(number.Scale - integerDigitsPresent - fractionalDigitsPresent);
uint fastExponent = (uint)(Math.Abs(exponent));
int fastExponent = (Math.Abs(exponent));

// Above 19 digits, we rely on slow path
if (totalDigits <= 19)
Expand Down Expand Up @@ -1237,7 +1264,7 @@ private static uint NumberToSingleFloatingPointBits(ref NumberBuffer number, in
uint fractionalDigitsPresent = totalDigits - integerDigitsPresent;

int exponent = (int)(number.Scale - integerDigitsPresent - fractionalDigitsPresent);
uint fastExponent = (uint)(Math.Abs(exponent));
int fastExponent = (Math.Abs(exponent));


// Above 19 digits, we rely on slow path
Expand Down