From 4d38873096c337aa6471489ba091bebd4dc8da61 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Sun, 24 Feb 2013 22:38:58 -0700 Subject: [PATCH] begin merging target assembler multimethod code --- src/codegen/target/arm/assembler.cpp | 3 +- src/codegen/target/arm/multimethod.cpp | 33 ++++++++++------------ src/codegen/target/arm/multimethod.h | 2 -- src/codegen/target/multimethod.h | 29 +++++++++++++++++++ src/codegen/target/powerpc/assembler.cpp | 5 ++-- src/codegen/target/powerpc/multimethod.cpp | 32 +++++++++------------ src/codegen/target/powerpc/multimethod.h | 3 -- src/codegen/target/x86/assembler.cpp | 3 +- src/codegen/target/x86/multimethod.cpp | 33 ++++++++++------------ src/codegen/target/x86/multimethod.h | 2 -- 10 files changed, 80 insertions(+), 65 deletions(-) create mode 100644 src/codegen/target/multimethod.h diff --git a/src/codegen/target/arm/assembler.cpp b/src/codegen/target/arm/assembler.cpp index 8be76085e1..089c56379f 100644 --- a/src/codegen/target/arm/assembler.cpp +++ b/src/codegen/target/arm/assembler.cpp @@ -21,6 +21,7 @@ #include "encode.h" #include "operations.h" #include "registers.h" +#include "../multimethod.h" #include "alloc-vector.h" #include @@ -769,7 +770,7 @@ class MyAssembler: public Assembler { virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->con.unaryOperations[index(&(arch_->con), op, a.type)] + arch_->con.unaryOperations[Multimethod::index(op, a.type)] (&con, a.size, a.operand); } diff --git a/src/codegen/target/arm/multimethod.cpp b/src/codegen/target/arm/multimethod.cpp index 4e789cc18c..a88180fc9b 100644 --- a/src/codegen/target/arm/multimethod.cpp +++ b/src/codegen/target/arm/multimethod.cpp @@ -9,20 +9,17 @@ details. */ #include "context.h" -#include "multimethod.h" #include "operations.h" +#include "multimethod.h" +#include "../multimethod.h" + namespace avian { namespace codegen { namespace arm { using namespace util; -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) -{ - return operation + (lir::UnaryOperationCount * operand); -} - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, @@ -66,25 +63,25 @@ void populateTables(ArchitectureContext* con) { zo[lir::StoreLoadBarrier] = memoryBarrier; zo[lir::Trap] = trap; - uo[index(con, lir::LongCall, C)] = CAST1(longCallC); + uo[Multimethod::index(lir::LongCall, C)] = CAST1(longCallC); - uo[index(con, lir::AlignedLongCall, C)] = CAST1(longCallC); + uo[Multimethod::index(lir::AlignedLongCall, C)] = CAST1(longCallC); - uo[index(con, lir::LongJump, C)] = CAST1(longJumpC); + uo[Multimethod::index(lir::LongJump, C)] = CAST1(longJumpC); - uo[index(con, lir::AlignedLongJump, C)] = CAST1(longJumpC); + uo[Multimethod::index(lir::AlignedLongJump, C)] = CAST1(longJumpC); - uo[index(con, lir::Jump, R)] = CAST1(jumpR); - uo[index(con, lir::Jump, C)] = CAST1(jumpC); + uo[Multimethod::index(lir::Jump, R)] = CAST1(jumpR); + uo[Multimethod::index(lir::Jump, C)] = CAST1(jumpC); - uo[index(con, lir::AlignedJump, R)] = CAST1(jumpR); - uo[index(con, lir::AlignedJump, C)] = CAST1(jumpC); + uo[Multimethod::index(lir::AlignedJump, R)] = CAST1(jumpR); + uo[Multimethod::index(lir::AlignedJump, C)] = CAST1(jumpC); - uo[index(con, lir::Call, C)] = CAST1(callC); - uo[index(con, lir::Call, R)] = CAST1(callR); + uo[Multimethod::index(lir::Call, C)] = CAST1(callC); + uo[Multimethod::index(lir::Call, R)] = CAST1(callR); - uo[index(con, lir::AlignedCall, C)] = CAST1(callC); - uo[index(con, lir::AlignedCall, R)] = CAST1(callR); + uo[Multimethod::index(lir::AlignedCall, C)] = CAST1(callC); + uo[Multimethod::index(lir::AlignedCall, R)] = CAST1(callR); bo[index(con, lir::Move, R, R)] = CAST2(moveRR); bo[index(con, lir::Move, C, R)] = CAST2(moveCR); diff --git a/src/codegen/target/arm/multimethod.h b/src/codegen/target/arm/multimethod.h index 7c574b588c..cda1daff37 100644 --- a/src/codegen/target/arm/multimethod.h +++ b/src/codegen/target/arm/multimethod.h @@ -23,8 +23,6 @@ namespace avian { namespace codegen { namespace arm { -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand); - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, diff --git a/src/codegen/target/multimethod.h b/src/codegen/target/multimethod.h new file mode 100644 index 0000000000..750a02d8c8 --- /dev/null +++ b/src/codegen/target/multimethod.h @@ -0,0 +1,29 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_CODEGEN_TARGET_MULTIMETHOD_H +#define AVIAN_CODEGEN_TARGET_MULTIMETHOD_H + + +namespace avian { +namespace codegen { + +class Multimethod { +public: + inline static unsigned index(lir::UnaryOperation operation, lir::OperandType operand) { + return operation + (lir::UnaryOperationCount * operand); + } +}; + +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_TARGET_MULTIMETHOD_H + diff --git a/src/codegen/target/powerpc/assembler.cpp b/src/codegen/target/powerpc/assembler.cpp index 5ad517871a..414ab71884 100644 --- a/src/codegen/target/powerpc/assembler.cpp +++ b/src/codegen/target/powerpc/assembler.cpp @@ -19,8 +19,9 @@ #include "context.h" #include "fixup.h" #include "block.h" -#include "multimethod.h" #include "operations.h" +#include "multimethod.h" +#include "../multimethod.h" using namespace vm; using namespace avian::util; @@ -824,7 +825,7 @@ class MyAssembler: public Assembler { virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->c.unaryOperations[index(&(arch_->c), op, a.type)] + arch_->c.unaryOperations[Multimethod::index(op, a.type)] (&c, a.size, a.operand); } diff --git a/src/codegen/target/powerpc/multimethod.cpp b/src/codegen/target/powerpc/multimethod.cpp index d8ffba5008..234a4e055c 100644 --- a/src/codegen/target/powerpc/multimethod.cpp +++ b/src/codegen/target/powerpc/multimethod.cpp @@ -11,9 +11,10 @@ #include "context.h" #include "block.h" #include "common.h" - #include "operations.h" + #include "multimethod.h" +#include "../multimethod.h" namespace avian { namespace codegen { @@ -21,11 +22,6 @@ namespace powerpc { using namespace util; -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) -{ - return operation + (lir::UnaryOperationCount * operand); -} - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, @@ -69,25 +65,25 @@ void populateTables(ArchitectureContext* c) { zo[lir::StoreLoadBarrier] = memoryBarrier; zo[lir::Trap] = trap; - uo[index(c, lir::LongCall, C)] = CAST1(longCallC); + uo[Multimethod::index(lir::LongCall, C)] = CAST1(longCallC); - uo[index(c, lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); + uo[Multimethod::index(lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); - uo[index(c, lir::LongJump, C)] = CAST1(longJumpC); + uo[Multimethod::index(lir::LongJump, C)] = CAST1(longJumpC); - uo[index(c, lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); + uo[Multimethod::index(lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); - uo[index(c, lir::Jump, R)] = CAST1(jumpR); - uo[index(c, lir::Jump, C)] = CAST1(jumpC); + uo[Multimethod::index(lir::Jump, R)] = CAST1(jumpR); + uo[Multimethod::index(lir::Jump, C)] = CAST1(jumpC); - uo[index(c, lir::AlignedJump, R)] = CAST1(jumpR); - uo[index(c, lir::AlignedJump, C)] = CAST1(jumpC); + uo[Multimethod::index(lir::AlignedJump, R)] = CAST1(jumpR); + uo[Multimethod::index(lir::AlignedJump, C)] = CAST1(jumpC); - uo[index(c, lir::Call, C)] = CAST1(callC); - uo[index(c, lir::Call, R)] = CAST1(callR); + uo[Multimethod::index(lir::Call, C)] = CAST1(callC); + uo[Multimethod::index(lir::Call, R)] = CAST1(callR); - uo[index(c, lir::AlignedCall, C)] = CAST1(callC); - uo[index(c, lir::AlignedCall, R)] = CAST1(callR); + uo[Multimethod::index(lir::AlignedCall, C)] = CAST1(callC); + uo[Multimethod::index(lir::AlignedCall, R)] = CAST1(callR); bo[index(c, lir::Move, R, R)] = CAST2(moveRR); bo[index(c, lir::Move, C, R)] = CAST2(moveCR); diff --git a/src/codegen/target/powerpc/multimethod.h b/src/codegen/target/powerpc/multimethod.h index 06b881e97a..b3565d0ed9 100644 --- a/src/codegen/target/powerpc/multimethod.h +++ b/src/codegen/target/powerpc/multimethod.h @@ -20,9 +20,6 @@ namespace avian { namespace codegen { namespace powerpc { - -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand); - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, diff --git a/src/codegen/target/x86/assembler.cpp b/src/codegen/target/x86/assembler.cpp index 6b1a1679ad..deeb6879f2 100644 --- a/src/codegen/target/x86/assembler.cpp +++ b/src/codegen/target/x86/assembler.cpp @@ -39,6 +39,7 @@ #include "operations.h" #include "detect.h" #include "multimethod.h" +#include "../multimethod.h" #define CAST1(x) reinterpret_cast(x) #define CAST2(x) reinterpret_cast(x) @@ -1043,7 +1044,7 @@ class MyAssembler: public Assembler { virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->c.unaryOperations[index(&(arch_->c), op, a.type)] + arch_->c.unaryOperations[Multimethod::index(op, a.type)] (&c, a.size, a.operand); } diff --git a/src/codegen/target/x86/multimethod.cpp b/src/codegen/target/x86/multimethod.cpp index 9146c9d9cb..ddd6a1fe1d 100644 --- a/src/codegen/target/x86/multimethod.cpp +++ b/src/codegen/target/x86/multimethod.cpp @@ -15,20 +15,17 @@ #include #include "context.h" -#include "multimethod.h" #include "operations.h" +#include "multimethod.h" +#include "../multimethod.h" + namespace avian { namespace codegen { namespace x86 { using namespace util; - -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) { - return operation + (lir::UnaryOperationCount * operand); -} - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, lir::OperandType operand2) @@ -74,25 +71,25 @@ void populateTables(ArchitectureContext* c) { zo[lir::StoreLoadBarrier] = storeLoadBarrier; zo[lir::Trap] = trap; - uo[index(c, lir::Call, C)] = CAST1(callC); - uo[index(c, lir::Call, R)] = CAST1(callR); - uo[index(c, lir::Call, M)] = CAST1(callM); + uo[Multimethod::index(lir::Call, C)] = CAST1(callC); + uo[Multimethod::index(lir::Call, R)] = CAST1(callR); + uo[Multimethod::index(lir::Call, M)] = CAST1(callM); - uo[index(c, lir::AlignedCall, C)] = CAST1(alignedCallC); + uo[Multimethod::index(lir::AlignedCall, C)] = CAST1(alignedCallC); - uo[index(c, lir::LongCall, C)] = CAST1(longCallC); + uo[Multimethod::index(lir::LongCall, C)] = CAST1(longCallC); - uo[index(c, lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); + uo[Multimethod::index(lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); - uo[index(c, lir::Jump, R)] = CAST1(jumpR); - uo[index(c, lir::Jump, C)] = CAST1(jumpC); - uo[index(c, lir::Jump, M)] = CAST1(jumpM); + uo[Multimethod::index(lir::Jump, R)] = CAST1(jumpR); + uo[Multimethod::index(lir::Jump, C)] = CAST1(jumpC); + uo[Multimethod::index(lir::Jump, M)] = CAST1(jumpM); - uo[index(c, lir::AlignedJump, C)] = CAST1(alignedJumpC); + uo[Multimethod::index(lir::AlignedJump, C)] = CAST1(alignedJumpC); - uo[index(c, lir::LongJump, C)] = CAST1(longJumpC); + uo[Multimethod::index(lir::LongJump, C)] = CAST1(longJumpC); - uo[index(c, lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); + uo[Multimethod::index(lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); bo[index(c, lir::Negate, R, R)] = CAST2(negateRR); diff --git a/src/codegen/target/x86/multimethod.h b/src/codegen/target/x86/multimethod.h index 6ede17f17a..6846f2f042 100644 --- a/src/codegen/target/x86/multimethod.h +++ b/src/codegen/target/x86/multimethod.h @@ -21,8 +21,6 @@ namespace x86 { class ArchitectureContext; -unsigned index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand); - unsigned index(ArchitectureContext*, lir::BinaryOperation operation, lir::OperandType operand1, lir::OperandType operand2);