/* src/simd/mds_classifier_lut.h — generated by tools/gen_classifier_lut.pl
 *
 * Two 16-byte LUTs such that for every byte b in [0x00, 0xFF]:
 *     (lo_tbl[b & 0xF] & hi_tbl[(b >> 4) & 0xF]) != 0
 * iff b is one of the structural Markdown bytes:
 *
 *     \t \n \r ' ' ! " # & ( ) * + - . : < = > [ \ ] _ ` | ~
 *
 * Encoding: each LUT entry is 8 bits, one bit per possible high nibble
 * (0..7). hi_tbl[h] = (1<<h) iff h < 8, else 0. lo_tbl[l] is the OR of
 * (1<<hi(b)) over every structural byte b with (b & 0xF) == l.
 *
 * All structural bytes have hi nibble in {0,2,3,5,6,7}, so the scheme
 * fits in 8 bits with zero collisions across [0x00, 0xFF].
 */
#ifndef MDS_CLASSIFIER_LUT_H
#define MDS_CLASSIFIER_LUT_H

#include <stdint.h>

static const uint8_t MDS_CLASSIFIER_LO[16] = {
    /* 0x0 */ 0x44, /* ' ' (hi=2), '`' (hi=6)              */
    /* 0x1 */ 0x04, /* '!' (hi=2)                          */
    /* 0x2 */ 0x04, /* '"' (hi=2)                          */
    /* 0x3 */ 0x04, /* '#' (hi=2)                          */
    /* 0x4 */ 0x00,
    /* 0x5 */ 0x00,
    /* 0x6 */ 0x04, /* '&' (hi=2)                          */
    /* 0x7 */ 0x00,
    /* 0x8 */ 0x04, /* '(' (hi=2)                          */
    /* 0x9 */ 0x05, /* '\t' (hi=0), ')' (hi=2)             */
    /* 0xA */ 0x0D, /* '\n' (hi=0), '*' (hi=2), ':' (hi=3) */
    /* 0xB */ 0x24, /* '+' (hi=2), '[' (hi=5)              */
    /* 0xC */ 0xA8, /* '<' (hi=3), '\\' (hi=5), '|' (hi=7) */
    /* 0xD */ 0x2D, /* '\r' (hi=0), '-' (hi=2), '=' (hi=3), ']' (hi=5) */
    /* 0xE */ 0x8C, /* '.' (hi=2), '>' (hi=3), '~' (hi=7)  */
    /* 0xF */ 0x20  /* '_' (hi=5)                          */
};

static const uint8_t MDS_CLASSIFIER_HI[16] = {
    /* hi=0: \t \n \r            -> bit 0 */
    0x01,
    /* hi=1: no structural bytes */
    0x00,
    /* hi=2: space ! " # & ( ) * + - .  -> bit 2 */
    0x04,
    /* hi=3: : < = >             -> bit 3 */
    0x08,
    /* hi=4: no structural bytes */
    0x00,
    /* hi=5: [ \ ] _             -> bit 5 */
    0x20,
    /* hi=6: `                   -> bit 6 */
    0x40,
    /* hi=7: | ~                 -> bit 7 */
    0x80,
    /* hi=8..F: high-bit-set bytes are never structural */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

/* Per-byte truth table used by the scalar reference and the fuzz test.
 * 1 iff the byte is structural per the same encoding as the LUTs. */
static inline int mds_classifier_truth(unsigned char b) {
    return (MDS_CLASSIFIER_LO[b & 0xF] & MDS_CLASSIFIER_HI[b >> 4]) != 0;
}

#endif /* MDS_CLASSIFIER_LUT_H */
