From e7175251940b8331c874646be3c998b986571b09 Mon Sep 17 00:00:00 2001 From: Alex Coyte Date: Mon, 27 Feb 2017 14:22:35 +1100 Subject: [PATCH] Check if any tugs are alive when compressing/expanding repeats --- src/nfa/limex_compile.cpp | 8 +++++++- src/nfa/limex_internal.h | 4 ++-- src/nfa/limex_runtime_impl.h | 20 ++++++++++---------- src/nfa/repeat.c | 6 +++++- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index ba4d0f0d..c75eae59 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -1803,6 +1803,12 @@ struct Factory { assert(cyclic != NO_STATE); maskSetBit(limex->repeatCyclicMask, cyclic); } + /* also include tugs in repeat cyclic mask */ + for (NFAVertex v : args.tugs) { + u32 v_state = args.state_ids.at(v); + assert(v_state != NO_STATE); + maskSetBit(limex->repeatCyclicMask, v_state); + } } static diff --git a/src/nfa/limex_internal.h b/src/nfa/limex_internal.h index 723803c1..ccbf3422 100644 --- a/src/nfa/limex_internal.h +++ b/src/nfa/limex_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -151,7 +151,7 @@ struct LimExNFA##size { \ * followers */ \ u_##size compressMask; /**< switch off before compress */ \ u_##size exceptionMask; \ - u_##size repeatCyclicMask; \ + u_##size repeatCyclicMask; /**< also includes tug states */ \ u_##size zombieMask; /**< zombie if in any of the set states */ \ u_##size shift[MAX_SHIFT_COUNT]; \ u32 shiftCount; /**< number of shift masks used */ \ diff --git a/src/nfa/limex_runtime_impl.h b/src/nfa/limex_runtime_impl.h index 45ceb2b5..016d1f92 100644 --- a/src/nfa/limex_runtime_impl.h +++ b/src/nfa/limex_runtime_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -393,19 +393,16 @@ void COMPRESS_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, void *src, DEBUG_PRINTF("repeat %u\n", i); const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i); - if (!TESTBIT_STATE(s, info->cyclicState)) { + const ENG_STATE_T *tug_mask = + (const ENG_STATE_T *)((const char *)info + info->tugMaskOffset); + /* repeat may still be inspected if its tug state is on */ + if (!TESTBIT_STATE(s, info->cyclicState) + && ISZERO_STATE(AND_STATE(s, LOAD_FROM_ENG(tug_mask)))) { DEBUG_PRINTF("is dead\n"); continue; } const struct RepeatInfo *repeat = getRepeatInfo(info); - if (repeatHasMatch(repeat, &ctrl[i], state_base + info->stateOffset, - offset) == REPEAT_STALE) { - DEBUG_PRINTF("is stale, clearing state\n"); - CLEARBIT_STATE(&s, info->cyclicState); - continue; - } - DEBUG_PRINTF("packing state (packedCtrlOffset=%u)\n", info->packedCtrlOffset); repeatPack(state_base + info->packedCtrlOffset, repeat, &ctrl[i], @@ -448,8 +445,11 @@ void EXPAND_REPEATS_FN(const IMPL_NFA_T *limex, void *dest, const void *src, for (u32 i = 0; i < limex->repeatCount; i++) { DEBUG_PRINTF("repeat %u\n", i); const struct NFARepeatInfo *info = GET_NFA_REPEAT_INFO_FN(limex, i); + const ENG_STATE_T *tug_mask = + (const ENG_STATE_T *)((const char *)info + info->tugMaskOffset); - if (!TESTBIT_STATE(cyclics, info->cyclicState)) { + if (!TESTBIT_STATE(cyclics, info->cyclicState) + && ISZERO_STATE(AND_STATE(cyclics, LOAD_FROM_ENG(tug_mask)))) { DEBUG_PRINTF("is dead\n"); continue; } diff --git a/src/nfa/repeat.c b/src/nfa/repeat.c index 339829a5..5b2e4df4 100644 --- a/src/nfa/repeat.c +++ b/src/nfa/repeat.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016, Intel Corporation + * Copyright (c) 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -177,6 +177,10 @@ u64a repeatLastTopRange(const union RepeatControl *ctrl, const void *state) { u64a repeatLastTopBitmap(const union RepeatControl *ctrl) { const struct RepeatBitmapControl *xs = &ctrl->bitmap; + if (!xs->bitmap) { + /* last top was too long ago */ + return 0; + } return xs->offset + 63 - clz64(xs->bitmap); }