From 2da7656a9a2fbf30cac0caffa4a2d168f736b4a1 Mon Sep 17 00:00:00 2001 From: Rekai Gonzalez-Alberquilla Date: Wed, 5 Apr 2017 13:20:30 -0500 Subject: cpu: Result refactoring The Result union used to collect the result of an instruction is now a class of its own, with its constructor, and explicit casting methods for cleanliness. This is also a stepping stone to have vector registers, and instructions that produce a vector register as output. Change-Id: I6f40c11cb5e835d8b11f7804a4e967aff18025b9 Reviewed-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/2703 Reviewed-by: Anthony Gutierrez Reviewed-by: Jason Lowe-Power Maintainer: Andreas Sandberg --- src/cpu/base_dyn_inst.hh | 61 +++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'src/cpu/base_dyn_inst.hh') diff --git a/src/cpu/base_dyn_inst.hh b/src/cpu/base_dyn_inst.hh index 9c6952310..a8e619cd9 100644 --- a/src/cpu/base_dyn_inst.hh +++ b/src/cpu/base_dyn_inst.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011,2013 ARM Limited + * Copyright (c) 2011,2013,2016 ARM Limited * Copyright (c) 2013 Advanced Micro Devices, Inc. * All rights reserved. * @@ -49,18 +49,19 @@ #include #include #include -#include #include +#include #include "arch/generic/tlb.hh" #include "arch/utility.hh" #include "base/trace.hh" #include "config/the_isa.hh" #include "cpu/checker/cpu.hh" -#include "cpu/o3/comm.hh" #include "cpu/exec_context.hh" #include "cpu/exetrace.hh" +#include "cpu/inst_res.hh" #include "cpu/inst_seq.hh" +#include "cpu/o3/comm.hh" #include "cpu/op_class.hh" #include "cpu/static_inst.hh" #include "cpu/translation.hh" @@ -94,15 +95,6 @@ class BaseDynInst : public ExecContext, public RefCounted MaxInstDestRegs = TheISA::MaxInstDestRegs /// Max dest regs }; - union Result { - uint64_t integer; - double dbl; - void set(uint64_t i) { integer = i; } - void set(double d) { dbl = d; } - void get(uint64_t& i) { i = integer; } - void get(double& d) { d = dbl; } - }; - protected: enum Status { IqEntry, /// Instruction is in the IQ @@ -174,7 +166,7 @@ class BaseDynInst : public ExecContext, public RefCounted /** The result of the instruction; assumes an instruction can have many * destination registers. */ - std::queue instResult; + std::queue instResult; /** PC state for this instruction. */ TheISA::PCState pc; @@ -606,56 +598,55 @@ class BaseDynInst : public ExecContext, public RefCounted /** Returns the logical register index of the i'th source register. */ const RegId& srcRegIdx(int i) const { return staticInst->srcRegIdx(i); } - /** Pops a result off the instResult queue */ - template - void popResult(T& t) + /** Return the size of the instResult queue. */ + uint8_t resultSize() { return instResult.size(); } + + /** Pops a result off the instResult queue. + * If the result stack is empty, return the default value. + * */ + InstResult popResult(InstResult dflt = InstResult()) { if (!instResult.empty()) { - instResult.front().get(t); + InstResult t = instResult.front(); instResult.pop(); + return t; } + return dflt; } - /** Read the most recent result stored by this instruction */ - template - void readResult(T& t) - { - instResult.back().get(t); - } - - /** Pushes a result onto the instResult queue */ - template - void setResult(T t) + /** Pushes a result onto the instResult queue. */ + template + void setScalarResult(T&& t) { if (instFlags[RecordResult]) { - Result instRes; - instRes.set(t); - instResult.push(instRes); + instResult.push(InstResult(std::forward(t), + InstResult::ResultType::Scalar)); } } /** Records an integer register being set to a value. */ void setIntRegOperand(const StaticInst *si, int idx, IntReg val) { - setResult(val); + setScalarResult(val); } /** Records a CC register being set to a value. */ void setCCRegOperand(const StaticInst *si, int idx, CCReg val) { - setResult(val); + setScalarResult(val); } /** Records an fp register being set to a value. */ void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) { - setResult(val); + setScalarResult(val); } /** Records an fp register being set to an integer value. */ - void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val) + void + setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val) { - setResult(val); + setScalarResult(val); } /** Records that one of the source registers is ready. */ -- cgit v1.2.3