From 871aefb9a0a7ab9137b57e0788f42cd3cafe034f Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 4 Apr 2018 09:03:48 +0100 Subject: [PATCH] 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. --- src/frontend/A64/decoder/a64.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/frontend/A64/decoder/a64.h b/src/frontend/A64/decoder/a64.h index 8aeb613e..73752659 100644 --- a/src/frontend/A64/decoder/a64.h +++ b/src/frontend/A64/decoder/a64.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -31,13 +32,20 @@ std::vector> GetDecodeTable() { }; 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. return Common::BitCount(matcher1.GetMask()) > Common::BitCount(matcher2.GetMask()); }); + // Exceptions to the above rule of thumb. + const std::set 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; }