Skip to content

Light up Ascii.Equality.Equals and Ascii.Equality.EqualsIgnoreCase with Vector512 code path - #88650

Merged
tannergooding merged 14 commits into
dotnet:mainfrom
khushal1996:kcm-ascii-equals
Jul 18, 2023
Merged

Light up Ascii.Equality.Equals and Ascii.Equality.EqualsIgnoreCase with Vector512 code path#88650
tannergooding merged 14 commits into
dotnet:mainfrom
khushal1996:kcm-ascii-equals

Conversation

@khushal1996

@khushal1996khushal1996 commented Jul 11, 2023

Copy link
Copy Markdown
Member

This PR is about adding Vector512 support to the existing ASCII.Equality.Equals and ASCIIEquality..EqualsIgnoreCase library APIs. The implementation remains very much similar to Vector256.

We have changed the implementation of public static Vector512<ushort> Load512 to make sure we either retain the existing performance or see a performance gain. Please look the comments in the code for detailed explanation.

PERF


MethodToolchainSizeMeanErrorStdDevMedianMinMaxRatioRatioSD
Equals_BytesBase_impl66.633 ns0.0262 ns0.0245 ns6.636 ns6.595 ns6.674 ns1.000.01
Equals_BytesDiff_impl66.658 ns0.0351 ns0.0328 ns6.658 ns6.604 ns6.708 ns1.000.01
Equals_CharsBase_impl65.341 ns0.0375 ns0.0351 ns5.338 ns5.272 ns5.403 ns1.000.01
Equals_CharsDiff_impl65.379 ns0.0308 ns0.0288 ns5.379 ns5.327 ns5.421 ns1.000.01
Equals_Bytes_CharsBase_impl65.944 ns0.0635 ns0.0530 ns5.960 ns5.861 ns6.061 ns0.990.02
Equals_Bytes_CharsDiff_impl66.016 ns0.0836 ns0.0782 ns5.996 ns5.859 ns6.161 ns1.000.02
EqualsIgnoreCase_ExactlyTheSame_BytesBase_impl66.451 ns0.0460 ns0.0430 ns6.444 ns6.394 ns6.530 ns0.990.01
EqualsIgnoreCase_ExactlyTheSame_BytesDiff_impl66.154 ns0.0247 ns0.0219 ns6.165 ns6.101 ns6.171 ns0.950.01
EqualsIgnoreCase_ExactlyTheSame_CharsBase_impl66.584 ns0.0801 ns0.0749 ns6.586 ns6.484 ns6.716 ns1.010.01
EqualsIgnoreCase_ExactlyTheSame_CharsDiff_impl65.428 ns0.0189 ns0.0177 ns5.436 ns5.401 ns5.452 ns0.830.01
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsBase_impl66.443 ns0.0551 ns0.0516 ns6.455 ns6.346 ns6.519 ns1.000.01
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsDiff_impl66.113 ns0.0356 ns0.0315 ns6.118 ns6.062 ns6.177 ns0.950.01
EqualsIgnoreCase_DifferentCase_BytesBase_impl66.513 ns0.0393 ns0.0367 ns6.510 ns6.460 ns6.577 ns0.980.01
EqualsIgnoreCase_DifferentCase_BytesDiff_impl67.089 ns0.0481 ns0.0450 ns7.079 ns7.033 ns7.174 ns1.070.01
EqualsIgnoreCase_DifferentCase_CharsBase_impl66.752 ns0.0468 ns0.0415 ns6.750 ns6.659 ns6.813 ns1.000.01
EqualsIgnoreCase_DifferentCase_CharsDiff_impl67.174 ns0.0413 ns0.0387 ns7.177 ns7.110 ns7.246 ns1.060.01
EqualsIgnoreCase_DifferentCase_Bytes_CharsBase_impl66.465 ns0.0518 ns0.0484 ns6.461 ns6.410 ns6.563 ns0.930.01
EqualsIgnoreCase_DifferentCase_Bytes_CharsDiff_impl67.111 ns0.0239 ns0.0212 ns7.111 ns7.063 ns7.151 ns1.030.01
Equals_BytesBase_impl322.546 ns0.0305 ns0.0255 ns2.545 ns2.507 ns2.603 ns1.010.02
Equals_BytesDiff_impl322.522 ns0.0257 ns0.0241 ns2.515 ns2.490 ns2.562 ns1.000.01
Equals_CharsBase_impl322.820 ns0.0118 ns0.0111 ns2.815 ns2.810 ns2.840 ns1.000.01
Equals_CharsDiff_impl322.833 ns0.0030 ns0.0024 ns2.834 ns2.828 ns2.836 ns1.000.00
Equals_Bytes_CharsBase_impl322.607 ns0.0089 ns0.0075 ns2.608 ns2.590 ns2.622 ns1.000.00
Equals_Bytes_CharsDiff_impl322.603 ns0.0102 ns0.0085 ns2.605 ns2.585 ns2.616 ns1.000.00
EqualsIgnoreCase_ExactlyTheSame_BytesBase_impl322.954 ns0.0045 ns0.0035 ns2.954 ns2.950 ns2.963 ns0.850.00
EqualsIgnoreCase_ExactlyTheSame_BytesDiff_impl323.059 ns0.0086 ns0.0076 ns3.061 ns3.037 ns3.069 ns0.880.01
EqualsIgnoreCase_ExactlyTheSame_CharsBase_impl324.079 ns0.0258 ns0.0215 ns4.082 ns4.042 ns4.118 ns0.760.01
EqualsIgnoreCase_ExactlyTheSame_CharsDiff_impl323.562 ns0.0175 ns0.0155 ns3.561 ns3.538 ns3.596 ns0.670.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsBase_impl324.299 ns0.0193 ns0.0181 ns4.301 ns4.266 ns4.333 ns0.760.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsDiff_impl323.662 ns0.0486 ns0.0455 ns3.667 ns3.559 ns3.717 ns0.650.01
EqualsIgnoreCase_DifferentCase_BytesBase_impl323.844 ns0.0236 ns0.0221 ns3.844 ns3.809 ns3.882 ns0.650.00
EqualsIgnoreCase_DifferentCase_BytesDiff_impl324.240 ns0.0414 ns0.0387 ns4.226 ns4.197 ns4.315 ns0.720.01
EqualsIgnoreCase_DifferentCase_CharsBase_impl326.577 ns0.0263 ns0.0233 ns6.579 ns6.537 ns6.623 ns0.600.00
EqualsIgnoreCase_DifferentCase_CharsDiff_impl324.536 ns0.0203 ns0.0190 ns4.542 ns4.509 ns4.563 ns0.420.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsBase_impl327.672 ns0.0320 ns0.0284 ns7.681 ns7.624 ns7.710 ns0.710.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsDiff_impl325.625 ns0.0228 ns0.0190 ns5.631 ns5.580 ns5.655 ns0.520.00
Equals_BytesBase_impl1283.177 ns0.0010 ns0.0008 ns3.177 ns3.176 ns3.179 ns1.000.00
Equals_BytesDiff_impl1283.178 ns0.0013 ns0.0012 ns3.178 ns3.176 ns3.180 ns1.000.00
Equals_CharsBase_impl1285.643 ns0.0237 ns0.0210 ns5.647 ns5.578 ns5.666 ns0.990.00
Equals_CharsDiff_impl1285.317 ns0.0048 ns0.0040 ns5.317 ns5.308 ns5.324 ns0.940.00
Equals_Bytes_CharsBase_impl1284.633 ns0.0292 ns0.0259 ns4.631 ns4.595 ns4.688 ns1.000.01
Equals_Bytes_CharsDiff_impl1284.625 ns0.0234 ns0.0196 ns4.627 ns4.588 ns4.650 ns1.000.01
EqualsIgnoreCase_ExactlyTheSame_BytesBase_impl1286.018 ns0.0185 ns0.0164 ns6.011 ns6.001 ns6.047 ns0.630.00
EqualsIgnoreCase_ExactlyTheSame_BytesDiff_impl1284.519 ns0.0334 ns0.0312 ns4.534 ns4.463 ns4.550 ns0.470.00
EqualsIgnoreCase_ExactlyTheSame_CharsBase_impl12811.243 ns0.0057 ns0.0053 ns11.244 ns11.234 ns11.251 ns0.580.00
EqualsIgnoreCase_ExactlyTheSame_CharsDiff_impl1288.042 ns0.0035 ns0.0029 ns8.041 ns8.037 ns8.046 ns0.420.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsBase_impl12814.060 ns0.0333 ns0.0295 ns14.053 ns14.019 ns14.131 ns0.680.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsDiff_impl1288.859 ns0.0030 ns0.0027 ns8.858 ns8.855 ns8.864 ns0.430.00
EqualsIgnoreCase_DifferentCase_BytesBase_impl12811.694 ns0.0036 ns0.0030 ns11.695 ns11.690 ns11.701 ns0.600.00
EqualsIgnoreCase_DifferentCase_BytesDiff_impl1287.287 ns0.0126 ns0.0105 ns7.287 ns7.267 ns7.303 ns0.380.00
EqualsIgnoreCase_DifferentCase_CharsBase_impl12820.930 ns0.0275 ns0.0230 ns20.923 ns20.903 ns20.989 ns0.550.00
EqualsIgnoreCase_DifferentCase_CharsDiff_impl12814.724 ns0.0124 ns0.0116 ns14.725 ns14.690 ns14.738 ns0.380.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsBase_impl12824.800 ns0.0270 ns0.0252 ns24.802 ns24.760 ns24.840 ns0.610.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsDiff_impl12814.666 ns0.0077 ns0.0072 ns14.664 ns14.656 ns14.682 ns0.360.00
Equals_BytesBase_impl5128.693 ns0.0057 ns0.0044 ns8.693 ns8.687 ns8.699 ns1.000.00
Equals_BytesDiff_impl51210.694 ns0.0031 ns0.0029 ns10.693 ns10.690 ns10.700 ns1.230.00
Equals_CharsBase_impl51217.528 ns0.0065 ns0.0058 ns17.526 ns17.520 ns17.542 ns0.990.00
Equals_CharsDiff_impl51216.729 ns0.0044 ns0.0041 ns16.727 ns16.722 ns16.737 ns0.950.00
Equals_Bytes_CharsBase_impl51214.422 ns0.0048 ns0.0045 ns14.423 ns14.416 ns14.429 ns1.010.00
Equals_Bytes_CharsDiff_impl51214.005 ns0.0065 ns0.0061 ns14.003 ns13.993 ns14.018 ns0.980.00
EqualsIgnoreCase_ExactlyTheSame_BytesBase_impl51219.734 ns0.0095 ns0.0089 ns19.733 ns19.721 ns19.750 ns0.440.00
EqualsIgnoreCase_ExactlyTheSame_BytesDiff_impl51213.132 ns0.0036 ns0.0033 ns13.132 ns13.127 ns13.138 ns0.290.00
EqualsIgnoreCase_ExactlyTheSame_CharsBase_impl51251.981 ns0.0377 ns0.0352 ns51.985 ns51.908 ns52.039 ns0.620.00
EqualsIgnoreCase_ExactlyTheSame_CharsDiff_impl51227.112 ns0.0064 ns0.0060 ns27.110 ns27.104 ns27.123 ns0.320.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsBase_impl51257.214 ns0.0301 ns0.0282 ns57.213 ns57.170 ns57.273 ns0.610.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsDiff_impl51231.673 ns0.0095 ns0.0074 ns31.673 ns31.661 ns31.682 ns0.340.00
EqualsIgnoreCase_DifferentCase_BytesBase_impl51243.033 ns0.0091 ns0.0080 ns43.034 ns43.020 ns43.047 ns0.500.00
EqualsIgnoreCase_DifferentCase_BytesDiff_impl51227.040 ns0.1025 ns0.0856 ns27.064 ns26.756 ns27.070 ns0.320.00
EqualsIgnoreCase_DifferentCase_CharsBase_impl51289.066 ns0.0922 ns0.0770 ns89.070 ns88.975 ns89.238 ns0.560.00
EqualsIgnoreCase_DifferentCase_CharsDiff_impl51252.448 ns0.0152 ns0.0135 ns52.448 ns52.429 ns52.477 ns0.330.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsBase_impl512102.465 ns0.0737 ns0.0653 ns102.459 ns102.327 ns102.600 ns0.600.00
EqualsIgnoreCase_DifferentCase_Bytes_CharsDiff_impl51256.994 ns0.1687 ns0.1409 ns56.940 ns56.871 ns57.312 ns0.340.00
Equals_BytesBase_impl102415.430 ns0.0044 ns0.0041 ns15.430 ns15.421 ns15.435 ns0.980.00
Equals_BytesDiff_impl102416.261 ns0.0044 ns0.0034 ns16.262 ns16.254 ns16.265 ns1.030.00
Equals_CharsBase_impl102438.232 ns0.7836 ns0.8710 ns38.331 ns36.608 ns39.653 ns0.950.02
Equals_CharsDiff_impl102439.503 ns0.0855 ns0.0799 ns39.520 ns39.219 ns39.548 ns0.980.00
Equals_Bytes_CharsBase_impl102427.625 ns0.0398 ns0.0353 ns27.630 ns27.507 ns27.652 ns1.000.00
Equals_Bytes_CharsDiff_impl102427.242 ns0.0138 ns0.0129 ns27.243 ns27.213 ns27.259 ns0.990.00
EqualsIgnoreCase_ExactlyTheSame_BytesBase_impl102449.150 ns0.1114 ns0.1042 ns49.189 ns48.969 ns49.267 ns0.630.00
EqualsIgnoreCase_ExactlyTheSame_BytesDiff_impl102424.301 ns0.0097 ns0.0091 ns24.299 ns24.288 ns24.319 ns0.310.00
EqualsIgnoreCase_ExactlyTheSame_CharsBase_impl102494.396 ns0.0399 ns0.0374 ns94.397 ns94.327 ns94.459 ns0.600.00
EqualsIgnoreCase_ExactlyTheSame_CharsDiff_impl102460.306 ns0.0189 ns0.0167 ns60.304 ns60.274 ns60.342 ns0.380.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsBase_impl1024102.150 ns0.2300 ns0.1920 ns102.080 ns101.973 ns102.638 ns0.610.00
EqualsIgnoreCase_ExactlyTheSame_Bytes_CharsDiff_impl102472.305 ns0.0378 ns0.0335 ns72.303 ns72.239 ns72.378 ns0.440.00
EqualsIgnoreCase_DifferentCase_BytesBase_impl102492.898 ns0.1827 ns0.1525 ns92.848 ns92.676 ns93.261 ns0.580.00
EqualsIgnoreCase_DifferentCase_BytesDiff_impl102448.550 ns0.0189 ns0.0177 ns48.544 ns48.531 ns48.585 ns0.300.00

@ghostghost added community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 11, 2023
@khushal1996khushal1996 changed the title Adding Vector512 support in Ascii.Equality.Equals and Ascii.Equality.EqualsIgnoreCaseLight up Ascii.Equality.Equals and Ascii.Equality.EqualsIgnoreCase with Vector512 code pathJul 11, 2023
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-text-encoding
See info in area-owners.md if you want to be subscribed.

Issue Details

NO NEED FOR REVIEW AT THIS TIME

This PR is about adding Vector512 support to the existing ASCII.Equality.Equals and ASCIIEquality..EqualsIgnoreCase library APIs. The implementation remains very much similar to Vector256.

Perf


Author:khushal1996
Assignees:-
Labels:

area-System.Text.Encoding, community-contribution, needs-area-label

Milestone:-

@lewinglewing removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 13, 2023
@tannergoodingtannergooding added the avx512 Related to the AVX-512 architecture label Jul 14, 2023
Comment threadsrc/libraries/System.Private.CoreLib/src/System/Text/Ascii.Equality.cs Outdated

@tannergoodingtannergooding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Basically a copy/paste of the V256 path and changed to use V512

@MihaZupanMihaZupan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I was also relying on it matching the Vector256 variant.

Comment on lines +85 to +92
while (!Unsafe.IsAddressGreaterThan(ref currentRightSearchSpace, ref oneVectorAwayFromRightEnd));

// If any elements remain, process the last vector in the search space.
if (length % (uint)Vector512<TLeft>.Count != 0)
{
ref TLeft oneVectorAwayFromLeftEnd = ref Unsafe.Add(ref left, length - (uint)Vector512<TLeft>.Count);
return TLoader.EqualAndAscii512(ref oneVectorAwayFromLeftEnd, ref oneVectorAwayFromRightEnd);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not specific to this PR since it's just following the existing pattern)

Since we're already doing the ref arithmetic here, we might be able to save a few instructions by changing such loops to

while(Unsafe.IsAddressLessThan(refcurrentRightSearchSpace,refoneVectorAwayFromRightEnd)){ ...}refTLeftoneVectorAwayFromLeftEnd=refUnsafe.Add(refleft,length-(uint)Vector512<TLeft>.Count);returnTLoader.EqualAndAscii512(refoneVectorAwayFromLeftEnd,refoneVectorAwayFromRightEnd);

@tannergooding
tannergooding merged commit bced584 into dotnet:mainJul 18, 2023
@ghostghost locked as resolved and limited conversation to collaborators Aug 18, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Encodingavx512Related to the AVX-512 architecturecommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@khushal1996@tannergooding@MihaZupan@lewing