From c78f153ddb6345012ad5ea685b58d4bbe2ed2b5b Mon Sep 17 00:00:00 2001 From: MerryMage Date: Thu, 22 Dec 2016 15:25:38 +0000 Subject: [PATCH] decoder/arm: Sort decoders according to number of bits in mask --- src/frontend/decoder/arm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/frontend/decoder/arm.h b/src/frontend/decoder/arm.h index 62f39aa2..d1a240a8 100644 --- a/src/frontend/decoder/arm.h +++ b/src/frontend/decoder/arm.h @@ -14,6 +14,7 @@ #include +#include "common/bit_util.h" #include "common/common_types.h" #include "frontend/decoder/decoder_detail.h" #include "frontend/decoder/matcher.h" @@ -318,7 +319,10 @@ std::vector> GetArmDecodeTable() { }; - std::stable_partition(table.begin(), table.end(), [](const auto& matcher) { return (matcher.GetMask() & 0xF0000000) != 0; }); + // If a matcher has more bits in its mask it is more specific, so it should come first. + std::stable_sort(table.begin(), table.end(), [](const auto& matcher1, const auto& matcher2) { + return Common::BitCount(matcher1.GetMask()) > Common::BitCount(matcher2.GetMask()); + }); return table; }