1
1
#include " decode.h"
2
2
#include " common.h"
3
- #include < unordered_set >
3
+ #include < unordered_map >
4
4
#include < vector>
5
5
#include < string>
6
6
#include < cstdio>
@@ -11,13 +11,9 @@ struct opcode {
11
11
std::string name;
12
12
};
13
13
14
- static void check_overlap (const opcode& a, const opcode& b)
14
+ static bool overlaps (const opcode& a, const opcode& b)
15
15
{
16
- if ((a.match & b.mask ) == b.match ) {
17
- fprintf (stderr, " Instruction %s (%" PRIx64 " ) overlaps instruction %s (%" PRIx64 " , mask %" PRIx64 " )\n " ,
18
- a.name .c_str (), a.match , b.name .c_str (), b.match , b.mask );
19
- exit (-1 );
20
- }
16
+ return (a.mask & b.mask & (a.match ^ b.match )) == 0 ;
21
17
}
22
18
23
19
int main ()
@@ -34,24 +30,47 @@ int main()
34
30
#undef DEFINE_INSN
35
31
};
36
32
37
- std::unordered_set <std::string> overlap_list;
33
+ std::unordered_map <std::string, bool > overlap_list;
38
34
#define DECLARE_OVERLAP_INSN (name, ext ) \
39
- overlap_list. insert ( std::string (#name)) ;
35
+ overlap_list[ std::string (#name)] = false ;
40
36
#include " overlap_list.h"
41
37
#undef DECLARE_OVERLAP_INSN
42
38
43
39
std::vector<const opcode*> list;
44
- for (size_t i = 0 ; i < sizeof (static_list) / sizeof (static_list[ 0 ] ); i++) {
40
+ for (size_t i = 0 ; i < std::size (static_list); i++) {
45
41
if (!overlap_list.count (static_list[i].name ))
46
42
list.push_back (&static_list[i]);
47
43
}
48
44
45
+ bool ok = true ;
46
+
49
47
for (size_t i = 1 ; i < list.size (); i++) {
50
48
for (size_t j = 0 ; j < i; j++) {
51
- check_overlap (*list[i], *list[j]);
52
- check_overlap (*list[j], *list[i]);
49
+ if (overlaps (*list[i], *list[j])) {
50
+ fprintf (stderr, " Instruction %s (%" PRIx64 " ) overlaps instruction %s (%" PRIx64 " , mask %" PRIx64 " )\n " ,
51
+ list[i]->name .c_str (), list[i]->match , list[j]->name .c_str (), list[j]->match , list[j]->mask );
52
+ ok = false ;
53
+ }
54
+ }
55
+ }
56
+
57
+ // make sure nothing in the overlap list is unused
58
+ for (size_t i = 1 ; i < std::size (static_list); i++) {
59
+ for (size_t j = 0 ; j < i; j++) {
60
+ if (overlaps (static_list[i], static_list[j])) {
61
+ overlap_list[static_list[i].name ] = true ;
62
+ overlap_list[static_list[j].name ] = true ;
63
+ }
64
+ }
65
+ }
66
+
67
+ for (auto const & [name, used] : overlap_list) {
68
+ if (!used) {
69
+ fprintf (stderr, " Instruction %s overlaps nothing, so overlap list entry has no effect\n " ,
70
+ name.c_str ());
71
+ ok = false ;
53
72
}
54
73
}
55
74
56
- return 0 ;
75
+ return ok ? 0 : - 1 ;
57
76
}
0 commit comments