decoder/a64: Tweak ordering algorithm
Ensuring only instruction families are sorted with each other in the fashion previously devised does not admit a total ordering.
This commit is contained in:
parent
575590d18d
commit
871aefb9a0
1 changed files with 11 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
@ -31,13 +32,20 @@ std::vector<Matcher<Visitor>> GetDecodeTable() {
|
||||||
};
|
};
|
||||||
|
|
||||||
std::stable_sort(table.begin(), table.end(), [](const auto& matcher1, const auto& matcher2) {
|
std::stable_sort(table.begin(), table.end(), [](const auto& matcher1, const auto& matcher2) {
|
||||||
// If the matchers aren't related, keep their relative positions the same.
|
|
||||||
if ((matcher1.GetMask() & ~matcher2.GetMask()) && (~matcher1.GetMask() & matcher2.GetMask()))
|
|
||||||
return false;
|
|
||||||
// If a matcher has more bits in its mask it is more specific, so it should come first.
|
// If a matcher has more bits in its mask it is more specific, so it should come first.
|
||||||
return Common::BitCount(matcher1.GetMask()) > Common::BitCount(matcher2.GetMask());
|
return Common::BitCount(matcher1.GetMask()) > Common::BitCount(matcher2.GetMask());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Exceptions to the above rule of thumb.
|
||||||
|
const std::set<std::string> comes_first {
|
||||||
|
"MOVI, MVNI, ORR, BIC (vector, immediate)",
|
||||||
|
"FMOV (vector, immediate)",
|
||||||
|
};
|
||||||
|
|
||||||
|
std::stable_partition(table.begin(), table.end(), [&](const auto& matcher) {
|
||||||
|
return comes_first.count(matcher.GetName()) > 0;
|
||||||
|
});
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue