From 662bb0cc09f0966f0667cd8e8b7239709ac7df81 Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Wed, 26 Feb 2014 11:59:17 +0000 Subject: [PATCH] A64: Move the dispatching logic of the decoder to a separate class. BUG=none R=ulan@chromium.org, rodolph.perfetta@arm.com LOG=n Review URL: https://codereview.chromium.org/181233002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19561 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/a64/decoder-a64.cc | 133 +++++++++++++++++++++-------------------- src/a64/decoder-a64.h | 27 ++++++--- 2 files changed, 85 insertions(+), 75 deletions(-) diff --git a/src/a64/decoder-a64.cc b/src/a64/decoder-a64.cc index e7383d446a..6a0497b8a3 100644 --- a/src/a64/decoder-a64.cc +++ b/src/a64/decoder-a64.cc @@ -37,6 +37,73 @@ namespace v8 { namespace internal { + +void DispatchingDecoderVisitor::AppendVisitor(DecoderVisitor* new_visitor) { + visitors_.remove(new_visitor); + visitors_.push_front(new_visitor); +} + + +void DispatchingDecoderVisitor::PrependVisitor(DecoderVisitor* new_visitor) { + visitors_.remove(new_visitor); + visitors_.push_back(new_visitor); +} + + +void DispatchingDecoderVisitor::InsertVisitorBefore( + DecoderVisitor* new_visitor, DecoderVisitor* registered_visitor) { + visitors_.remove(new_visitor); + std::list::iterator it; + for (it = visitors_.begin(); it != visitors_.end(); it++) { + if (*it == registered_visitor) { + visitors_.insert(it, new_visitor); + return; + } + } + // We reached the end of the list. The last element must be + // registered_visitor. + ASSERT(*it == registered_visitor); + visitors_.insert(it, new_visitor); +} + + +void DispatchingDecoderVisitor::InsertVisitorAfter( + DecoderVisitor* new_visitor, DecoderVisitor* registered_visitor) { + visitors_.remove(new_visitor); + std::list::iterator it; + for (it = visitors_.begin(); it != visitors_.end(); it++) { + if (*it == registered_visitor) { + it++; + visitors_.insert(it, new_visitor); + return; + } + } + // We reached the end of the list. The last element must be + // registered_visitor. + ASSERT(*it == registered_visitor); + visitors_.push_back(new_visitor); +} + + +void DispatchingDecoderVisitor::RemoveVisitor(DecoderVisitor* visitor) { + visitors_.remove(visitor); +} + + +#define DEFINE_VISITOR_CALLERS(A) \ + void DispatchingDecoderVisitor::Visit##A(Instruction* instr) { \ + if (!(instr->Mask(A##FMask) == A##Fixed)) { \ + ASSERT(instr->Mask(A##FMask) == A##Fixed); \ + } \ + std::list::iterator it; \ + for (it = visitors_.begin(); it != visitors_.end(); it++) { \ + (*it)->Visit##A(instr); \ + } \ + } +VISITOR_LIST(DEFINE_VISITOR_CALLERS) +#undef DEFINE_VISITOR_CALLERS + + // Top-level instruction decode function. void Decoder::Decode(Instruction *instr) { if (instr->Bits(28, 27) == 0) { @@ -116,58 +183,6 @@ void Decoder::Decode(Instruction *instr) { } -void Decoder::AppendVisitor(DecoderVisitor* new_visitor) { - visitors_.remove(new_visitor); - visitors_.push_front(new_visitor); -} - - -void Decoder::PrependVisitor(DecoderVisitor* new_visitor) { - visitors_.remove(new_visitor); - visitors_.push_back(new_visitor); -} - - -void Decoder::InsertVisitorBefore(DecoderVisitor* new_visitor, - DecoderVisitor* registered_visitor) { - visitors_.remove(new_visitor); - std::list::iterator it; - for (it = visitors_.begin(); it != visitors_.end(); it++) { - if (*it == registered_visitor) { - visitors_.insert(it, new_visitor); - return; - } - } - // We reached the end of the list. The last element must be - // registered_visitor. - ASSERT(*it == registered_visitor); - visitors_.insert(it, new_visitor); -} - - -void Decoder::InsertVisitorAfter(DecoderVisitor* new_visitor, - DecoderVisitor* registered_visitor) { - visitors_.remove(new_visitor); - std::list::iterator it; - for (it = visitors_.begin(); it != visitors_.end(); it++) { - if (*it == registered_visitor) { - it++; - visitors_.insert(it, new_visitor); - return; - } - } - // We reached the end of the list. The last element must be - // registered_visitor. - ASSERT(*it == registered_visitor); - visitors_.push_back(new_visitor); -} - - -void Decoder::RemoveVisitor(DecoderVisitor* visitor) { - visitors_.remove(visitor); -} - - void Decoder::DecodePCRelAddressing(Instruction* instr) { ASSERT(instr->Bits(27, 24) == 0x0); // We know bit 28 is set, as = 0 is filtered out at the top level @@ -707,20 +722,6 @@ void Decoder::DecodeAdvSIMDDataProcessing(Instruction* instr) { } -#define DEFINE_VISITOR_CALLERS(A) \ - void Decoder::Visit##A(Instruction *instr) { \ - if (!(instr->Mask(A##FMask) == A##Fixed)) { \ - ASSERT(instr->Mask(A##FMask) == A##Fixed); \ - } \ - std::list::iterator it; \ - for (it = visitors_.begin(); it != visitors_.end(); it++) { \ - (*it)->Visit##A(instr); \ - } \ - } -VISITOR_LIST(DEFINE_VISITOR_CALLERS) -#undef DEFINE_VISITOR_CALLERS - - } } // namespace v8::internal #endif // V8_TARGET_ARCH_A64 diff --git a/src/a64/decoder-a64.h b/src/a64/decoder-a64.h index 1a7f6c4090..56f9ba731b 100644 --- a/src/a64/decoder-a64.h +++ b/src/a64/decoder-a64.h @@ -97,13 +97,11 @@ class DecoderVisitor { }; -class Decoder { +// A visitor that dispatches to a list of visitors. +class DispatchingDecoderVisitor : public DecoderVisitor { public: - Decoder() {} - - // Top-level instruction decoder function. Decodes an instruction and calls - // the visitor functions registered with the Decoder class. - void Decode(Instruction *instr); + DispatchingDecoderVisitor() {} + virtual ~DispatchingDecoderVisitor() {} // Register a new visitor class with the decoder. // Decode() will call the corresponding visitor method from all registered @@ -138,6 +136,20 @@ class Decoder { VISITOR_LIST(DECLARE) #undef DECLARE + private: + // Visitors are registered in a list. + std::list visitors_; +}; + + +class Decoder : public DispatchingDecoderVisitor { + public: + Decoder() {} + + // Top-level instruction decoder function. Decodes an instruction and calls + // the visitor functions registered with the Decoder class. + void Decode(Instruction *instr); + private: // Decode the PC relative addressing instruction, and call the corresponding // visitors. @@ -188,9 +200,6 @@ class Decoder { // tree, and call the corresponding visitors. // On entry, instruction bits 27:25 = 0x7. void DecodeAdvSIMDDataProcessing(Instruction* instr); - - // Visitors are registered in a list. - std::list visitors_; };