1/*
2 * Copyright (c) 2015, 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 GOUGH_INTERNAL_H
30#define GOUGH_INTERNAL_H
31
32#include "accel.h"
33#include "mcclellan_internal.h"
34#include "ue2common.h"
35
36#define INVALID_SLOT (~0U)
37
38#define GOUGH_INS_END 0
39#define GOUGH_INS_MOV 1
40#define GOUGH_INS_NEW 2
41#define GOUGH_INS_MIN 3
42/* todo: add instructions targeting acc reg? */
43
44struct gough_ins {
45 u32 op; /* u32 to avoid padding */
46 u32 dest;
47 u32 src; /* for GOUGH_INS_NEW, this specifies the adjustment to apply to the
48 * current offset */
49};
50
51/*
52 * HAPPY FUN ASCII ART TIME
53 *
54 * ----
55 * | | struct NFA
56 * ----
57 * ~~~~ normal(ish) mcclellan engine
58 * ~~~~
59 * ~~~~
60 * ~~~~
61 * ~~~~
62 * ~~~~
63 * ~~~~
64 * ~~~~
65 * ---- = m->haig_offset
66 * | | } struct gough_info
67 * ----
68 * | | }
69 * | | } edge prog table -> provides the offset of the start of the program
70 * | | } to run when the edge is taken. 0 indicates no
71 * | | } work to do
72 * ---- = h->top_prog_offset
73 * | | }
74 * | | } top prog table -> provides the offset of the start of the program
75 * | | } to run when a top is taken from this state. 0
76 * | | } indicates nothing to do
77 * ---- = h->prog_base_offset
78 * | | }
79 * | | } programs to run
80 * | | }
81 * | | }
82 * ----
83 */
84
85struct gough_info {
86 u32 top_prog_offset; /**< offset to the base of the top prog table */
87 u32 prog_base_offset; /**< not used at runtime */
88 u32 stream_som_loc_count; /**< number of som locs in the stream state */
89 u8 stream_som_loc_width; /**< number of bytes per som loc */
90};
91
92static really_inline
93const struct gough_info *get_gough(const struct mcclellan *m) {
94 assert(m->haig_offset);
95 const char *n = (const char *)m - sizeof(struct NFA);
96 return (const struct gough_info *)(n + m->haig_offset);
97}
98
99static really_inline
100const u32 *get_gough_top_offsets(const struct mcclellan *m) {
101 const struct gough_info *g = get_gough(m);
102 if (!g->top_prog_offset) {
103 return NULL;
104 }
105 const char *n = (const char *)m - sizeof(struct NFA);
106 return (const u32 *)(n + g->top_prog_offset);
107}
108
109/* Gough state representation in scratch.
110 *
111 * During execution, gough tracks a number of variables containing potential
112 * starts of match. These are all stored in a large array of u64a slots.
113 */
114struct gough_som_info {
115 u64a slots[1]; /* 'flexible' member array */
116};
117
118struct gough_report {
119 ReportID r;
120 u32 som; /* som slot to report */
121};
122
123struct gough_report_list {
124 u32 count;
125 struct gough_report report[];
126};
127
128struct gough_accel {
129 union AccelAux accel;
130 u8 margin_dist;
131 u32 prog_offset;
132};
133
134#endif
135