Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -4331,6 +4331,10 @@ private static string MatchCharacterClass(RegexOptions options, string chExpr, s
// Next, handle sets where the high - low + 1 range is <= 64. In that case, we can emit
// a branchless lookup in a ulong that does not rely on loading any objects (e.g. the string-based
// lookup we use later). This nicely handles common sets like [0-9A-Fa-f], [0-9a-f], [A-Za-z], etc.
// Note that unlike RegexCompiler, the source generator doesn't know whether the code is going to be
// run in a 32-bit or 64-bit process: in a 64-bit process, this is an optimization, but in a 32-bit process,
// it's a deoptimization. In general we optimize for 64-bit perf, so this code remains; it complicates
// the code too much to try to include both this and a fallback for the check.
if (analysis.OnlyRanges && (analysis.UpperBoundExclusiveIfOnlyRanges - analysis.LowerBoundInclusiveIfOnlyRanges) <= 64)
{
additionalDeclarations.Add("ulong charMinusLow;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5203,7 +5203,9 @@ private void EmitMatchCharacterClass(string charClass)
// Next, handle sets where the high - low + 1 range is <= 64. In that case, we can emit
// a branchless lookup in a ulong that does not rely on loading any objects (e.g. the string-based
// lookup we use later). This nicely handles common sets like [0-9A-Fa-f], [0-9a-f], [A-Za-z], etc.
if (analysis.OnlyRanges && (analysis.UpperBoundExclusiveIfOnlyRanges - analysis.LowerBoundInclusiveIfOnlyRanges) <= 64)
// We skip this on 32-bit, as otherwise using 64-bit numbers in this manner is a deoptimization
// when compared to the subsequent fallbacks.
if (IntPtr.Size == 8 && analysis.OnlyRanges && (analysis.UpperBoundExclusiveIfOnlyRanges - analysis.LowerBoundInclusiveIfOnlyRanges) <= 64)
Copy link
Member

Choose a reason for hiding this comment

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

Environment.Is64BitProcess is a little more descriptive.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can address in a follow-up as necessary

{
// Create the 64-bit value with 1s at indices corresponding to every character in the set,
// where the bit is computed to be the char value minus the lower bound starting from
Expand Down