Skip to content

Conversation

@khwilliamson
Copy link
Contributor

Various functions that traffic in UTF-8 take a flags parameter. This series of commits creates, then uses, definitions for the log2 of those flag bits. So there is now a definition for what goes in bit position 5, and its flag is defined as 1 << 5. Compilers are better able to see the pattern in 0, 1, 2, ... than in 1<<0, 1<<1, 1<<2. These definitions will also be useful in later pull requests.

  • This set of changes does not require a perldelta entry.

The GOT defines are now the principal ones, and the ALLOW ones are
changed to be in terms of the GOT.  This seems right to me, as the GOT
ones are the ones anyone might actually care about.  (The ALLOW ones are
for weird cases.)  More importantly this makes the next commit make more
sense.
This commit creates new #defines for the bit positions for the flags
that get passed to various functions that deal with UTF-8 input, and
then redefines the flag bits as the positions shifted to the proper
place.

There should be no change in the code generated by this.
The previous commit #defined the bit position of various flag bits.
This commit changes to use those as cases in a switch(), rather than the
shifted values.  This results in better generated code as the cases
now reduce to:             case 0:     case 1:     case 2:    ...
as opposed to previously:  case 1<<0:  case 1<<1:  case 1<<2: ...

clang and gcc were unable to see the pattern previously but now are.
Copy link
Contributor

@tonycoz tonycoz left a comment

Choose a reason for hiding this comment

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

It's an optimisation and it seems sane, but how often is that code hit?

@khwilliamson
Copy link
Contributor Author

It should not be hit much; it does save a bit of memory, and I think I want those bit positions for other reasons.

@khwilliamson khwilliamson merged commit 0f17f26 into Perl:blead Sep 23, 2025
34 checks passed
@khwilliamson khwilliamson deleted the utf8_use_bit_pos branch September 23, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants