mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-11-18 18:20:35 +03:00
refactor mcclellan runtime
1. use u32 to hold the state during runtime to prevent repeated zero extension 2. have a tight small loop for processing characters which breaks when something interesting happens
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -33,7 +33,7 @@ enum MatchMode {
|
||||
};
|
||||
|
||||
static really_inline
|
||||
const struct mstate_aux *get_aux(const struct mcclellan *m, u16 s) {
|
||||
const struct mstate_aux *get_aux(const struct mcclellan *m, u32 s) {
|
||||
const char *nfa = (const char *)m - sizeof(struct NFA);
|
||||
const struct mstate_aux *aux
|
||||
= s + (const struct mstate_aux *)(nfa + m->aux_offset);
|
||||
@@ -43,7 +43,7 @@ const struct mstate_aux *get_aux(const struct mcclellan *m, u16 s) {
|
||||
}
|
||||
|
||||
static really_inline
|
||||
u16 mcclellanEnableStarts(const struct mcclellan *m, u16 s) {
|
||||
u32 mcclellanEnableStarts(const struct mcclellan *m, u32 s) {
|
||||
const struct mstate_aux *aux = get_aux(m, s);
|
||||
|
||||
DEBUG_PRINTF("enabling starts %hu->%hu\n", s, aux->top);
|
||||
@@ -51,7 +51,7 @@ u16 mcclellanEnableStarts(const struct mcclellan *m, u16 s) {
|
||||
}
|
||||
|
||||
static really_inline
|
||||
u16 doSherman16(const char *sherman_state, u8 cprime, const u16 *succ_table,
|
||||
u32 doSherman16(const char *sherman_state, u8 cprime, const u16 *succ_table,
|
||||
u32 as) {
|
||||
assert(ISALIGNED_N(sherman_state, 16));
|
||||
|
||||
@@ -70,15 +70,15 @@ u16 doSherman16(const char *sherman_state, u8 cprime, const u16 *succ_table,
|
||||
if (z) {
|
||||
u32 i = ctz32(z & ~0xf) - 4;
|
||||
|
||||
u16 s_out = unaligned_load_u16((const u8 *)sherman_state
|
||||
u32 s_out = unaligned_load_u16((const u8 *)sherman_state
|
||||
+ SHERMAN_STATES_OFFSET(len)
|
||||
+ sizeof(u16) * i);
|
||||
DEBUG_PRINTF("found sherman match at %u/%u for c'=%hhu "
|
||||
"s=%hu\n", i, len, cprime, s_out);
|
||||
DEBUG_PRINTF("found sherman match at %u/%u for c'=%hhu s=%u\n", i,
|
||||
len, cprime, s_out);
|
||||
return s_out;
|
||||
}
|
||||
}
|
||||
|
||||
u16 daddy = *(const u16 *)(sherman_state + SHERMAN_DADDY_OFFSET);
|
||||
return succ_table[((u32)daddy << as) + cprime];
|
||||
u32 daddy = *(const u16 *)(sherman_state + SHERMAN_DADDY_OFFSET);
|
||||
return succ_table[(daddy << as) + cprime];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user