Skip to content

Commit

Permalink
bugfix: Decrement rank if c is not in label_group_starts.
Browse files Browse the repository at this point in the history
Get the rank of the *previous* label group, unless c starts a new one.
  • Loading branch information
silentbicycle committed Oct 9, 2024
1 parent 1267d1c commit 517ed40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libfsm/print/cdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,11 @@ generate_interpreter(FILE *f, const struct cdata_config *config, const struct fs
"\t\tif (debug_traces) {\n"
"\t\t\tfprintf(stderr, \"-- label '%%c' (0x%%02x) -> w_i %%zd, bit 0x%%016lx\\n\", isprint(c) ? c : 'c', c, w_i, bit);\n"
"\t\t}\n"
"\t\t\tconst uint64_t lgs_word = state->label_group_starts[w_i];\n"
"\t\t\tconst size_t back = (lgs_word & bit) ? 0 : 1; /* back to start of label group */\n"
"\t\t\tconst uint64_t mask = bit - 1;\n"
"\t\t\tconst uint64_t masked_word = state->label_group_starts[w_i] & mask;\n"
"\t\t\tconst size_t bit_rank_in_masked_word = %s(masked_word);\n"
"\t\t\tconst uint64_t masked_word = lgs_word & mask;\n"
"\t\t\tconst size_t bit_rank_in_masked_word = %s(masked_word) - back;\n"
"\t\t\tconst size_t rank = state->rank_sums[w_i] + bit_rank_in_masked_word;\n"
"\t\t\tconst size_t dst_offset = state->dst_table_offset + rank;\n"
"\t\t\tcur_state = %s_dfa_data.dst_table[dst_offset];\n"
Expand Down

0 comments on commit 517ed40

Please sign in to comment.