Skip to content

Commit

Permalink
Merge pull request #1 from db48x/skip-nul-translation-except-for-fulltbl
Browse files Browse the repository at this point in the history
Change inner loops to use int not YY_CHAR, removing need for separate NUL table
  • Loading branch information
eric-s-raymond authored Oct 15, 2020
2 parents 30d0e5f + c084f88 commit 84c26ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
11 changes: 10 additions & 1 deletion src/cpp-flex.skl
Original file line number Diff line number Diff line change
Expand Up @@ -1778,8 +1778,17 @@ m4_ifdef([[M4_MODE_NO_FULLSPD]], [[
]])
]])

%# yy_c was formerly YY_CHAR, changed to int because table can now
%# have up to 0x101 entries, since we no longer generate a separate
%# NUL table.
%#
%# Note: on x86-64 architecture with gcc -O2, we save an instruction
%# in the main loop, since the character can now be zero-extended in
%# the process of retrieving it from the input stream or the yy_ec[]
%# or yy_meta[] arrays, whereas previously it was zero-extended by a
%# register-to-register move just prior to the yy_chk[] table lookup
m4_define([[M4_GEN_NEXT_COMPRESSED_STATE]], [[
YY_CHAR yy_c = $1;
int yy_c = $1;
/* Save the backing-up info \before/ computing the next state
* because we always compute one more state than needed - we
* always proceed until we reach a jam state
Expand Down
29 changes: 5 additions & 24 deletions src/dfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,31 +455,12 @@ size_t ntod (void)

/* Note that the test for ecgroup[0] == numecs below accomplishes
* both (1) and (2) above
*
* New way: we will only use NUL table for fulltbl, because the
* scanner will use an integer instead of YY_CHAR as noted above
*/
if (!ctrl.fullspd && ecgroup[0] == numecs) {
/* NUL is alone in its equivalence class, which is the
* last one.
*/
int use_NUL_table = (numecs == ctrl.csize);

if (ctrl.fulltbl && !use_NUL_table) {
/* We still may want to use the table if numecs
* is a power of 2.
*/
if (numecs <= ctrl.csize && is_power_of_2(numecs)) {
use_NUL_table = true;
}
}

if (use_NUL_table)
nultrans =
allocate_integer_array (current_max_dfas);

/* From now on, nultrans != nil indicates that we're
* saving null transitions for later, separate encoding.
*/
}

if (ctrl.fulltbl && ecgroup[0] == numecs && is_power_of_2(numecs))
nultrans = allocate_integer_array (current_max_dfas);

if (ctrl.fullspd) {
for (i = 0; i <= numecs; ++i)
Expand Down

0 comments on commit 84c26ba

Please sign in to comment.