• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "match.h"
2 #include <limits.h>
3 #include <stdlib.h>
4 
5 typedef unsigned char u8;
6 typedef unsigned int u32;
7 
8 /* generated by mtdev-kernel - do not edit */
9 static const u8 match_data[] = {
10 	0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 0, 0, 0, 1, 1,
11 	1, 0, 0, 0, 1, 2, 1, 1, 0, 2, 2, 1, 2, 0, 0, 0,
12 	1, 2, 3, 1, 1, 0, 2, 3, 2, 1, 2, 0, 3, 3, 1, 2,
13 	3, 0, 0, 0, 1, 1, 1, 2, 1, 0, 0, 3, 0, 1, 1, 3,
14 	1, 0, 2, 2, 3, 1, 2, 0, 0, 4, 0, 1, 2, 2, 4, 2,
15 	1, 0, 0, 5, 0, 2, 1, 1, 5, 2, 0, 1, 1, 4, 1, 0,
16 	2, 3, 2, 4, 1, 2, 0, 3, 3, 4, 1, 2, 3, 0, 0, 5,
17 	0, 1, 2, 3, 2, 5, 2, 1, 0, 3, 3, 5, 2, 1, 3, 0,
18 	0, 6, 0, 2, 1, 3, 1, 6, 2, 0, 1, 3, 3, 6, 2, 3,
19 	1, 0, 0, 7, 0, 2, 3, 1, 1, 7, 2, 0, 3, 1, 2, 7,
20 	2, 3, 0, 1, 0, 0, 1, 1, 2, 2, 1, 2, 1, 0, 0, 3,
21 	0, 1, 1, 4, 2, 0, 3, 4, 2, 1, 0, 5, 0, 2, 2, 5,
22 	1, 2, 2, 4, 6, 2, 1, 0, 1, 5, 6, 2, 0, 1, 2, 3,
23 	7, 1, 2, 0, 0, 5, 7, 0, 2, 1, 1, 3, 8, 1, 0, 2,
24 	0, 4, 8, 0, 1, 2, 2, 5, 8, 2, 1, 0, 3, 3, 5, 8,
25 	2, 1, 3, 0, 1, 6, 8, 2, 0, 1, 3, 3, 6, 8, 2, 3,
26 	1, 0, 1, 7, 8, 2, 0, 3, 1, 2, 7, 8, 2, 3, 0, 1,
27 	2, 4, 9, 1, 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, 3, 6, 9, 12, 3, 2, 1, 0, 2, 7,
48 	9, 12, 3, 2, 0, 1, 3, 5, 10, 12, 3, 1, 2, 0, 1, 7,
49 	10, 12, 3, 0, 2, 1, 2, 5, 11, 12, 3, 1, 0, 2, 1, 6,
50 	11, 12, 3, 0, 1, 2, 3, 6, 8, 13, 2, 3, 1, 0, 2, 7,
51 	8, 13, 2, 3, 0, 1, 3, 4, 10, 13, 1, 3, 2, 0, 0, 7,
52 	10, 13, 0, 3, 2, 1, 2, 4, 11, 13, 1, 3, 0, 2, 0, 6,
53 	11, 13, 0, 3, 1, 2, 3, 5, 8, 14, 2, 1, 3, 0, 1, 7,
54 	8, 14, 2, 0, 3, 1, 3, 4, 9, 14, 1, 2, 3, 0, 0, 7,
55 	9, 14, 0, 2, 3, 1, 1, 4, 11, 14, 1, 0, 3, 2, 0, 5,
56 	11, 14, 0, 1, 3, 2, 2, 5, 8, 15, 2, 1, 0, 3, 1, 6,
57 	8, 15, 2, 0, 1, 3, 2, 4, 9, 15, 1, 2, 0, 3, 0, 6,
58 	9, 15, 0, 2, 1, 3, 1, 4, 10, 15, 1, 0, 2, 3, 0, 5,
59 	10, 15, 0, 1, 2, 3,
60 };
61 
62 /* generated by mtdev-kernel - do not edit */
63 static const int match_index[][5] = {
64 	{ 0, 0, 1, 3, 6 },
65 	{ 10, 10, 12, 18, 30 },
66 	{ 50, 50, 54, 62, 92 },
67 	{ 164, 164, 170, 194, 230 },
68 	{ 398, 398, 406, 454, 598 },
69 	{ 790 }
70 };
71 
set_dist(u32 * dist,const struct trk_coord * b1,const struct trk_coord * e1,const struct trk_coord * b2,const struct trk_coord * e2)72 static void set_dist(u32 *dist,
73 		     const struct trk_coord *b1, const struct trk_coord *e1,
74 		     const struct trk_coord *b2, const struct trk_coord *e2)
75 {
76 	const struct trk_coord *p, *q;
77 
78 	for (p = b1; p != e1; p++)
79 		for (q = b2; q != e2; q++)
80 			*dist++ = abs(q->x - p->x) + abs(q->y - p->y);
81 }
82 
mtdev_match_four(const struct trk_coord * old,int nslot,const struct trk_coord * pos,int npos)83 const u8 *mtdev_match_four(const struct trk_coord *old, int nslot,
84 			   const struct trk_coord *pos, int npos)
85 {
86 	u32 d[16], obj, t;
87 	const u8 *p, *b, *e;
88 	const int *at;
89 
90 	set_dist(d, old, old + nslot, pos, pos + npos);
91 
92 	at = &match_index[nslot][npos];
93 	b = &match_data[at[0]];
94 	e = &match_data[at[1]];
95 
96 	obj = UINT_MAX, p = b;
97 
98 	switch (minval(nslot, npos)) {
99 	case 1:
100 		for (; b != e; b += npos) {
101 			t = d[*b++];
102 			if (t < obj)
103 				obj = t, p = b;
104 		}
105 		break;
106 	case 2:
107 		for (; b != e; b += npos) {
108 			t = d[*b++], t += d[*b++];
109 			if (t < obj)
110 				obj = t, p = b;
111 		}
112 		break;
113 	case 3:
114 		for (; b != e; b += npos) {
115 			t = d[*b++], t += d[*b++], t += d[*b++];
116 			if (t < obj)
117 				obj = t, p = b;
118 		}
119 		break;
120 	case 4:
121 		for (; b != e; b += npos) {
122 			t = d[*b++], t += d[*b++], t += d[*b++], t += d[*b++];
123 			if (t < obj)
124 				obj = t, p = b;
125 		}
126 		break;
127 	}
128 
129 	return p;
130 }
131