From c084f884bd0f29b84999c05dcdd497ff42cd7000 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 15 Oct 2020 13:25:52 -0700 Subject: [PATCH] Change inner loops to use int not YY_CHAR, removing need for separate NUL table --- src/cpp-flex.skl | 11 ++++++++++- src/dfa.c | 29 +++++------------------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/cpp-flex.skl b/src/cpp-flex.skl index a1eb04c91..1fa3f0d18 100644 --- a/src/cpp-flex.skl +++ b/src/cpp-flex.skl @@ -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 diff --git a/src/dfa.c b/src/dfa.c index 06bbd6320..baa42ed12 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -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)