| 1 | /* |
| 2 | * Copyright (c) 2016, Intel Corporation |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * * Redistributions of source code must retain the above copyright notice, |
| 8 | * this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of Intel Corporation nor the names of its contributors |
| 13 | * may be used to endorse or promote products derived from this software |
| 14 | * without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef SHENG_DEFS_H |
| 30 | #define SHENG_DEFS_H |
| 31 | |
| 32 | /* |
| 33 | * Utility functions used by various versions of Sheng engine |
| 34 | */ |
| 35 | static really_inline |
| 36 | u8 isDeadState(const u8 a) { |
| 37 | return a & SHENG_STATE_DEAD; |
| 38 | } |
| 39 | |
| 40 | static really_inline |
| 41 | u8 isAcceptState(const u8 a) { |
| 42 | return a & SHENG_STATE_ACCEPT; |
| 43 | } |
| 44 | |
| 45 | static really_inline |
| 46 | u8 isAccelState(const u8 a) { |
| 47 | return a & SHENG_STATE_ACCEL; |
| 48 | } |
| 49 | |
| 50 | static really_inline |
| 51 | u8 hasInterestingStates(const u8 a, const u8 b, const u8 c, const u8 d) { |
| 52 | return (a | b | c | d) & (SHENG_STATE_FLAG_MASK); |
| 53 | } |
| 54 | |
| 55 | /* these functions should be optimized out, used by NO_MATCHES mode */ |
| 56 | static really_inline |
| 57 | u8 dummyFunc4(UNUSED const u8 a, UNUSED const u8 b, UNUSED const u8 c, |
| 58 | UNUSED const u8 d) { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static really_inline |
| 63 | u8 dummyFunc(UNUSED const u8 a) { |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | /* |
| 68 | * Sheng function definitions for single byte loops |
| 69 | */ |
| 70 | /* callback output, can die */ |
| 71 | #define SHENG_IMPL sheng_cod |
| 72 | #define DEAD_FUNC isDeadState |
| 73 | #define ACCEPT_FUNC isAcceptState |
| 74 | #define STOP_AT_MATCH 0 |
| 75 | #include "sheng_impl.h" |
| 76 | #undef SHENG_IMPL |
| 77 | #undef DEAD_FUNC |
| 78 | #undef ACCEPT_FUNC |
| 79 | #undef STOP_AT_MATCH |
| 80 | |
| 81 | /* callback output, can't die */ |
| 82 | #define SHENG_IMPL sheng_co |
| 83 | #define DEAD_FUNC dummyFunc |
| 84 | #define ACCEPT_FUNC isAcceptState |
| 85 | #define STOP_AT_MATCH 0 |
| 86 | #include "sheng_impl.h" |
| 87 | #undef SHENG_IMPL |
| 88 | #undef DEAD_FUNC |
| 89 | #undef ACCEPT_FUNC |
| 90 | #undef STOP_AT_MATCH |
| 91 | |
| 92 | /* stop at match, can die */ |
| 93 | #define SHENG_IMPL sheng_samd |
| 94 | #define DEAD_FUNC isDeadState |
| 95 | #define ACCEPT_FUNC isAcceptState |
| 96 | #define STOP_AT_MATCH 1 |
| 97 | #include "sheng_impl.h" |
| 98 | #undef SHENG_IMPL |
| 99 | #undef DEAD_FUNC |
| 100 | #undef ACCEPT_FUNC |
| 101 | #undef STOP_AT_MATCH |
| 102 | |
| 103 | /* stop at match, can't die */ |
| 104 | #define SHENG_IMPL sheng_sam |
| 105 | #define DEAD_FUNC dummyFunc |
| 106 | #define ACCEPT_FUNC isAcceptState |
| 107 | #define STOP_AT_MATCH 1 |
| 108 | #include "sheng_impl.h" |
| 109 | #undef SHENG_IMPL |
| 110 | #undef DEAD_FUNC |
| 111 | #undef ACCEPT_FUNC |
| 112 | #undef STOP_AT_MATCH |
| 113 | |
| 114 | /* no match, can die */ |
| 115 | #define SHENG_IMPL sheng_nmd |
| 116 | #define DEAD_FUNC isDeadState |
| 117 | #define ACCEPT_FUNC dummyFunc |
| 118 | #define STOP_AT_MATCH 0 |
| 119 | #include "sheng_impl.h" |
| 120 | #undef SHENG_IMPL |
| 121 | #undef DEAD_FUNC |
| 122 | #undef ACCEPT_FUNC |
| 123 | #undef STOP_AT_MATCH |
| 124 | |
| 125 | /* no match, can't die */ |
| 126 | #define SHENG_IMPL sheng_nm |
| 127 | #define DEAD_FUNC dummyFunc |
| 128 | #define ACCEPT_FUNC dummyFunc |
| 129 | #define STOP_AT_MATCH 0 |
| 130 | #include "sheng_impl.h" |
| 131 | #undef SHENG_IMPL |
| 132 | #undef DEAD_FUNC |
| 133 | #undef ACCEPT_FUNC |
| 134 | #undef STOP_AT_MATCH |
| 135 | |
| 136 | /* |
| 137 | * Sheng function definitions for 4-byte loops |
| 138 | */ |
| 139 | /* callback output, can die, accelerated */ |
| 140 | #define SHENG_IMPL sheng4_coda |
| 141 | #define INTERESTING_FUNC hasInterestingStates |
| 142 | #define INNER_DEAD_FUNC isDeadState |
| 143 | #define OUTER_DEAD_FUNC dummyFunc |
| 144 | #define INNER_ACCEL_FUNC isAccelState |
| 145 | #define OUTER_ACCEL_FUNC dummyFunc |
| 146 | #define ACCEPT_FUNC isAcceptState |
| 147 | #define STOP_AT_MATCH 0 |
| 148 | #include "sheng_impl4.h" |
| 149 | #undef SHENG_IMPL |
| 150 | #undef INTERESTING_FUNC |
| 151 | #undef INNER_DEAD_FUNC |
| 152 | #undef OUTER_DEAD_FUNC |
| 153 | #undef INNER_ACCEL_FUNC |
| 154 | #undef OUTER_ACCEL_FUNC |
| 155 | #undef ACCEPT_FUNC |
| 156 | #undef STOP_AT_MATCH |
| 157 | |
| 158 | /* callback output, can die, not accelerated */ |
| 159 | #define SHENG_IMPL sheng4_cod |
| 160 | #define INTERESTING_FUNC hasInterestingStates |
| 161 | #define INNER_DEAD_FUNC isDeadState |
| 162 | #define OUTER_DEAD_FUNC dummyFunc |
| 163 | #define INNER_ACCEL_FUNC dummyFunc |
| 164 | #define OUTER_ACCEL_FUNC dummyFunc |
| 165 | #define ACCEPT_FUNC isAcceptState |
| 166 | #define STOP_AT_MATCH 0 |
| 167 | #include "sheng_impl4.h" |
| 168 | #undef SHENG_IMPL |
| 169 | #undef INTERESTING_FUNC |
| 170 | #undef INNER_DEAD_FUNC |
| 171 | #undef OUTER_DEAD_FUNC |
| 172 | #undef INNER_ACCEL_FUNC |
| 173 | #undef OUTER_ACCEL_FUNC |
| 174 | #undef ACCEPT_FUNC |
| 175 | #undef STOP_AT_MATCH |
| 176 | |
| 177 | /* callback output, can't die, accelerated */ |
| 178 | #define SHENG_IMPL sheng4_coa |
| 179 | #define INTERESTING_FUNC hasInterestingStates |
| 180 | #define INNER_DEAD_FUNC dummyFunc |
| 181 | #define OUTER_DEAD_FUNC dummyFunc |
| 182 | #define INNER_ACCEL_FUNC isAccelState |
| 183 | #define OUTER_ACCEL_FUNC dummyFunc |
| 184 | #define ACCEPT_FUNC isAcceptState |
| 185 | #define STOP_AT_MATCH 0 |
| 186 | #include "sheng_impl4.h" |
| 187 | #undef SHENG_IMPL |
| 188 | #undef INTERESTING_FUNC |
| 189 | #undef INNER_DEAD_FUNC |
| 190 | #undef OUTER_DEAD_FUNC |
| 191 | #undef INNER_ACCEL_FUNC |
| 192 | #undef OUTER_ACCEL_FUNC |
| 193 | #undef ACCEPT_FUNC |
| 194 | #undef STOP_AT_MATCH |
| 195 | |
| 196 | /* callback output, can't die, not accelerated */ |
| 197 | #define SHENG_IMPL sheng4_co |
| 198 | #define INTERESTING_FUNC hasInterestingStates |
| 199 | #define INNER_DEAD_FUNC dummyFunc |
| 200 | #define OUTER_DEAD_FUNC dummyFunc |
| 201 | #define INNER_ACCEL_FUNC dummyFunc |
| 202 | #define OUTER_ACCEL_FUNC dummyFunc |
| 203 | #define ACCEPT_FUNC isAcceptState |
| 204 | #define STOP_AT_MATCH 0 |
| 205 | #include "sheng_impl4.h" |
| 206 | #undef SHENG_IMPL |
| 207 | #undef INTERESTING_FUNC |
| 208 | #undef INNER_DEAD_FUNC |
| 209 | #undef OUTER_DEAD_FUNC |
| 210 | #undef INNER_ACCEL_FUNC |
| 211 | #undef OUTER_ACCEL_FUNC |
| 212 | #undef ACCEPT_FUNC |
| 213 | #undef STOP_AT_MATCH |
| 214 | |
| 215 | /* stop at match, can die, accelerated */ |
| 216 | #define SHENG_IMPL sheng4_samda |
| 217 | #define INTERESTING_FUNC hasInterestingStates |
| 218 | #define INNER_DEAD_FUNC isDeadState |
| 219 | #define OUTER_DEAD_FUNC dummyFunc |
| 220 | #define INNER_ACCEL_FUNC isAccelState |
| 221 | #define OUTER_ACCEL_FUNC dummyFunc |
| 222 | #define ACCEPT_FUNC isAcceptState |
| 223 | #define STOP_AT_MATCH 1 |
| 224 | #include "sheng_impl4.h" |
| 225 | #undef SHENG_IMPL |
| 226 | #undef INTERESTING_FUNC |
| 227 | #undef INNER_DEAD_FUNC |
| 228 | #undef OUTER_DEAD_FUNC |
| 229 | #undef INNER_ACCEL_FUNC |
| 230 | #undef OUTER_ACCEL_FUNC |
| 231 | #undef ACCEPT_FUNC |
| 232 | #undef STOP_AT_MATCH |
| 233 | |
| 234 | /* stop at match, can die, not accelerated */ |
| 235 | #define SHENG_IMPL sheng4_samd |
| 236 | #define INTERESTING_FUNC hasInterestingStates |
| 237 | #define INNER_DEAD_FUNC isDeadState |
| 238 | #define OUTER_DEAD_FUNC dummyFunc |
| 239 | #define INNER_ACCEL_FUNC dummyFunc |
| 240 | #define OUTER_ACCEL_FUNC dummyFunc |
| 241 | #define ACCEPT_FUNC isAcceptState |
| 242 | #define STOP_AT_MATCH 1 |
| 243 | #include "sheng_impl4.h" |
| 244 | #undef SHENG_IMPL |
| 245 | #undef INTERESTING_FUNC |
| 246 | #undef INNER_DEAD_FUNC |
| 247 | #undef OUTER_DEAD_FUNC |
| 248 | #undef INNER_ACCEL_FUNC |
| 249 | #undef OUTER_ACCEL_FUNC |
| 250 | #undef ACCEPT_FUNC |
| 251 | #undef STOP_AT_MATCH |
| 252 | |
| 253 | /* stop at match, can't die, accelerated */ |
| 254 | #define SHENG_IMPL sheng4_sama |
| 255 | #define INTERESTING_FUNC hasInterestingStates |
| 256 | #define INNER_DEAD_FUNC dummyFunc |
| 257 | #define OUTER_DEAD_FUNC dummyFunc |
| 258 | #define INNER_ACCEL_FUNC isAccelState |
| 259 | #define OUTER_ACCEL_FUNC dummyFunc |
| 260 | #define ACCEPT_FUNC isAcceptState |
| 261 | #define STOP_AT_MATCH 1 |
| 262 | #include "sheng_impl4.h" |
| 263 | #undef SHENG_IMPL |
| 264 | #undef INTERESTING_FUNC |
| 265 | #undef INNER_DEAD_FUNC |
| 266 | #undef OUTER_DEAD_FUNC |
| 267 | #undef INNER_ACCEL_FUNC |
| 268 | #undef OUTER_ACCEL_FUNC |
| 269 | #undef ACCEPT_FUNC |
| 270 | #undef STOP_AT_MATCH |
| 271 | |
| 272 | /* stop at match, can't die, not accelerated */ |
| 273 | #define SHENG_IMPL sheng4_sam |
| 274 | #define INTERESTING_FUNC hasInterestingStates |
| 275 | #define INNER_DEAD_FUNC dummyFunc |
| 276 | #define OUTER_DEAD_FUNC dummyFunc |
| 277 | #define INNER_ACCEL_FUNC dummyFunc |
| 278 | #define OUTER_ACCEL_FUNC dummyFunc |
| 279 | #define ACCEPT_FUNC isAcceptState |
| 280 | #define STOP_AT_MATCH 1 |
| 281 | #include "sheng_impl4.h" |
| 282 | #undef SHENG_IMPL |
| 283 | #undef INTERESTING_FUNC |
| 284 | #undef INNER_DEAD_FUNC |
| 285 | #undef OUTER_DEAD_FUNC |
| 286 | #undef INNER_ACCEL_FUNC |
| 287 | #undef OUTER_ACCEL_FUNC |
| 288 | #undef ACCEPT_FUNC |
| 289 | #undef STOP_AT_MATCH |
| 290 | |
| 291 | /* no-match have interesting func as dummy, and die/accel checks are outer */ |
| 292 | |
| 293 | /* no match, can die, accelerated */ |
| 294 | #define SHENG_IMPL sheng4_nmda |
| 295 | #define INTERESTING_FUNC dummyFunc4 |
| 296 | #define INNER_DEAD_FUNC dummyFunc |
| 297 | #define OUTER_DEAD_FUNC isDeadState |
| 298 | #define INNER_ACCEL_FUNC dummyFunc |
| 299 | #define OUTER_ACCEL_FUNC isAccelState |
| 300 | #define ACCEPT_FUNC dummyFunc |
| 301 | #define STOP_AT_MATCH 0 |
| 302 | #include "sheng_impl4.h" |
| 303 | #undef SHENG_IMPL |
| 304 | #undef INTERESTING_FUNC |
| 305 | #undef INNER_DEAD_FUNC |
| 306 | #undef OUTER_DEAD_FUNC |
| 307 | #undef INNER_ACCEL_FUNC |
| 308 | #undef OUTER_ACCEL_FUNC |
| 309 | #undef ACCEPT_FUNC |
| 310 | #undef STOP_AT_MATCH |
| 311 | |
| 312 | /* no match, can die, not accelerated */ |
| 313 | #define SHENG_IMPL sheng4_nmd |
| 314 | #define INTERESTING_FUNC dummyFunc4 |
| 315 | #define INNER_DEAD_FUNC dummyFunc |
| 316 | #define OUTER_DEAD_FUNC isDeadState |
| 317 | #define INNER_ACCEL_FUNC dummyFunc |
| 318 | #define OUTER_ACCEL_FUNC dummyFunc |
| 319 | #define ACCEPT_FUNC dummyFunc |
| 320 | #define STOP_AT_MATCH 0 |
| 321 | #include "sheng_impl4.h" |
| 322 | #undef SHENG_IMPL |
| 323 | #undef INTERESTING_FUNC |
| 324 | #undef INNER_DEAD_FUNC |
| 325 | #undef OUTER_DEAD_FUNC |
| 326 | #undef INNER_ACCEL_FUNC |
| 327 | #undef OUTER_ACCEL_FUNC |
| 328 | #undef ACCEPT_FUNC |
| 329 | #undef STOP_AT_MATCH |
| 330 | |
| 331 | /* there is no performance benefit in accelerating a no-match case that can't |
| 332 | * die */ |
| 333 | |
| 334 | /* no match, can't die */ |
| 335 | #define SHENG_IMPL sheng4_nm |
| 336 | #define INTERESTING_FUNC dummyFunc4 |
| 337 | #define INNER_DEAD_FUNC dummyFunc |
| 338 | #define OUTER_DEAD_FUNC dummyFunc |
| 339 | #define INNER_ACCEL_FUNC dummyFunc |
| 340 | #define OUTER_ACCEL_FUNC dummyFunc |
| 341 | #define ACCEPT_FUNC dummyFunc |
| 342 | #define STOP_AT_MATCH 0 |
| 343 | #include "sheng_impl4.h" |
| 344 | #undef SHENG_IMPL |
| 345 | #undef INTERESTING_FUNC |
| 346 | #undef INNER_DEAD_FUNC |
| 347 | #undef OUTER_DEAD_FUNC |
| 348 | #undef INNER_ACCEL_FUNC |
| 349 | #undef OUTER_ACCEL_FUNC |
| 350 | #undef ACCEPT_FUNC |
| 351 | #undef STOP_AT_MATCH |
| 352 | |
| 353 | #endif // SHENG_DEFS_H |
| 354 | |