Skip to content

Commit

Permalink
Optimize DashedHexFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison authored and phatboyg committed Jan 7, 2023
1 parent 8777158 commit 57b3467
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 558 deletions.
11 changes: 5 additions & 6 deletions src/NewId/NewIdFormatters/DashedHexFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ private static void EncodeVector256(Span<char> span, (byte[] bytes, bool, char _
var spanBytes = MemoryMarshal.Cast<char, byte>(charSpan);
IntrinsicsHelper.Vector256ToCharUtf16(a2, spanBytes);

spanBytes[32] = hexVec.GetElement(14);
spanBytes[34] = hexVec.GetElement(15);
var shuffleSpare = Avx2.Shuffle(hexVec, Vector256.Create((byte)14, 0xFF, 15, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 12, 0xFF, 13, 0xFF, 14, 0xFF, 15, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF));
var byte1415 = shuffleSpare.AsUInt32().GetElement(0);
MemoryMarshal.Write(spanBytes[32..], ref byte1415);

spanBytes[64] = hexVec.GetElement(28);
spanBytes[66] = hexVec.GetElement(29);
spanBytes[68] = hexVec.GetElement(30);
spanBytes[70] = hexVec.GetElement(31);
var byte2731 = shuffleSpare.AsUInt64().GetElement(2);
MemoryMarshal.Write(spanBytes[64..], ref byte2731);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
3 changes: 0 additions & 3 deletions tests/NewId.Tests/NewId.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
</ItemGroup>

<ItemGroup>
<Content Include="guids.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="texts.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Loading

0 comments on commit 57b3467

Please sign in to comment.