From ad46ecb125bd15601bcb28a6f76664a14fdf8bb8 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 5 Apr 2016 09:22:53 +0100 Subject: [PATCH] fixup! ARM/Decoder: Misc fixes --- src/core/arm/decoder/arm.cpp | 26 +++++++++++++++++--------- src/core/arm/decoder/decoder.h | 10 +++++----- src/core/arm/decoder/thumb.cpp | 15 ++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/core/arm/decoder/arm.cpp b/src/core/arm/decoder/arm.cpp index fb51074fd..4899cf1b1 100644 --- a/src/core/arm/decoder/arm.cpp +++ b/src/core/arm/decoder/arm.cpp @@ -44,18 +44,19 @@ namespace Impl { std::array masks = {}; std::array shifts = {}; Function fn = nullptr; - virtual void visit(Visitor *v, u32 inst) override { + void visit(Visitor *v, u32 inst) override { std::array values; - for (size_t i = 0; i < NumArgs; i++) { - values[i] = (inst & masks[i]) >> shifts[i]; - } + std::transform(masks.begin(), masks.begin() + NumArgs, shifts.begin(), values.begin(), + [inst](u32 mask, size_t shift) { return (inst & mask) >> shift; }); call(v, fn, values); } }; } template -static std::unique_ptr MakeMatcher(const char format[32], Function fn) { +static std::unique_ptr MakeMatcher(const char* const format, Function fn) { + ASSERT(strlen(format) == 32); + auto ret = Common::make_unique>(); ret->fn = fn; ret->masks.fill(0); @@ -64,19 +65,23 @@ static std::unique_ptr MakeMatcher(const char format[32], Function f char ch = 0; int arg = -1; - for (int i = 0; i < 32; i++) { - const u32 bit = 1 << (31 - i); + for (size_t i = 0; i < 32; i++) { + const size_t bit_position = 31 - i; + const u32 bit = 1 << bit_position; if (format[i] == '0') { + // 0: A zero must be found here ret->bit_mask |= bit; ch = 0; continue; } else if (format[i] == '1') { + // 1: A one must be found here ret->bit_mask |= bit; ret->expected |= bit; ch = 0; continue; } else if (format[i] == '-') { + // -: Ignore this bit ch = 0; continue; } @@ -86,14 +91,17 @@ static std::unique_ptr MakeMatcher(const char format[32], Function f ASSERT(format[i] != 'l'); ASSERT(format[i] != 'O'); - if (format[i] != ch){ + // otherwise: This bit is part of a field to extract + + // strings of the same character make up a field + if (format[i] != ch) { arg++; ASSERT(arg < NumArgs); ch = format[i]; } ret->masks[arg] |= bit; - ret->shifts[arg] = 31 - i; + ret->shifts[arg] = bit_position; } ASSERT(arg == NumArgs - 1); diff --git a/src/core/arm/decoder/decoder.h b/src/core/arm/decoder/decoder.h index 96c4132ad..e3f463ab1 100644 --- a/src/core/arm/decoder/decoder.h +++ b/src/core/arm/decoder/decoder.h @@ -23,14 +23,14 @@ class ThumbInstruction; class Visitor; /** - * This funtion identifies an ARM instruction and returns the relevant ArmInstruction. - * Returns boost::none if the instruction could not be deocoded. + * This function identifies an ARM instruction and returns the relevant ArmInstruction. + * Returns boost::none if the instruction was not recognised. */ boost::optional DecodeArm(u32 instruction); /** -* This funtion identifies a Thumb instruction and returns the relevant ThumbInstruction. -* Returns boost::none if the instruction could not be deocoded. +* This function identifies a Thumb instruction and returns the relevant ThumbInstruction. +* Returns boost::none if the instruction was not recognised. */ boost::optional DecodeThumb(u16 instruction); @@ -91,7 +91,7 @@ public: return name; } - bool Match(u32 instruction) const { + bool Match(u16 instruction) const { return matcher.Match(instruction); } diff --git a/src/core/arm/decoder/thumb.cpp b/src/core/arm/decoder/thumb.cpp index 0c4bb9e30..4eb0e0a86 100644 --- a/src/core/arm/decoder/thumb.cpp +++ b/src/core/arm/decoder/thumb.cpp @@ -22,22 +22,19 @@ ThumbMatcher MakeMatcher(const char* const str, std::function