1/* 2 * Copyright (c) 2013-2014 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Andrew Bardsley 38 */ 39 40#include "cpu/minor/decode.hh" 41#include "cpu/minor/pipeline.hh" 42#include "debug/Decode.hh" 43 44namespace Minor 45{ 46 47Decode::Decode(const std::string &name, 48 MinorCPU &cpu_, 49 MinorCPUParams ¶ms, 50 Latch<ForwardInstData>::Output inp_, 51 Latch<ForwardInstData>::Input out_, 52 Reservable &next_stage_input_buffer) : 53 Named(name), 54 cpu(cpu_), 55 inp(inp_), 56 out(out_), 57 nextStageReserve(next_stage_input_buffer), 58 outputWidth(params.executeInputWidth), 59 processMoreThanOneInput(params.decodeCycleInput), 60 inputBuffer(name + ".inputBuffer", "insts", params.decodeInputBufferSize), 61 inputIndex(0), 62 inMacroop(false),
| 1/* 2 * Copyright (c) 2013-2014 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Andrew Bardsley 38 */ 39 40#include "cpu/minor/decode.hh" 41#include "cpu/minor/pipeline.hh" 42#include "debug/Decode.hh" 43 44namespace Minor 45{ 46 47Decode::Decode(const std::string &name, 48 MinorCPU &cpu_, 49 MinorCPUParams ¶ms, 50 Latch<ForwardInstData>::Output inp_, 51 Latch<ForwardInstData>::Input out_, 52 Reservable &next_stage_input_buffer) : 53 Named(name), 54 cpu(cpu_), 55 inp(inp_), 56 out(out_), 57 nextStageReserve(next_stage_input_buffer), 58 outputWidth(params.executeInputWidth), 59 processMoreThanOneInput(params.decodeCycleInput), 60 inputBuffer(name + ".inputBuffer", "insts", params.decodeInputBufferSize), 61 inputIndex(0), 62 inMacroop(false),
|
64{ 65 if (outputWidth < 1) 66 fatal("%s: executeInputWidth must be >= 1 (%d)\n", name, outputWidth); 67 68 if (params.decodeInputBufferSize < 1) { 69 fatal("%s: decodeInputBufferSize must be >= 1 (%d)\n", name, 70 params.decodeInputBufferSize); 71 } 72} 73 74const ForwardInstData * 75Decode::getInput() 76{ 77 /* Get insts from the inputBuffer to work with */ 78 if (!inputBuffer.empty()) { 79 const ForwardInstData &head = inputBuffer.front(); 80 81 return (head.isBubble() ? NULL : &(inputBuffer.front())); 82 } else { 83 return NULL; 84 } 85} 86 87void 88Decode::popInput() 89{ 90 if (!inputBuffer.empty()) 91 inputBuffer.pop(); 92 93 inputIndex = 0; 94 inMacroop = false; 95} 96 97#if TRACING_ON 98/** Add the tracing data to an instruction. This originates in 99 * decode because this is the first place that execSeqNums are known 100 * (these are used as the 'FetchSeq' in tracing data) */ 101static void 102dynInstAddTracing(MinorDynInstPtr inst, StaticInstPtr static_inst, 103 MinorCPU &cpu) 104{ 105 inst->traceData = cpu.getTracer()->getInstRecord(curTick(), 106 cpu.getContext(inst->id.threadId), 107 inst->staticInst, inst->pc, static_inst); 108 109 /* Use the execSeqNum as the fetch sequence number as this most closely 110 * matches the other processor models' idea of fetch sequence */ 111 if (inst->traceData) 112 inst->traceData->setFetchSeq(inst->id.execSeqNum); 113} 114#endif 115 116void 117Decode::evaluate() 118{ 119 inputBuffer.setTail(*inp.outputWire); 120 ForwardInstData &insts_out = *out.inputWire; 121 122 assert(insts_out.isBubble()); 123 124 blocked = false; 125 126 if (!nextStageReserve.canReserve()) { 127 blocked = true; 128 } else { 129 const ForwardInstData *insts_in = getInput(); 130 131 unsigned int output_index = 0; 132 133 /* Pack instructions into the output while we can. This may involve 134 * using more than one input line */ 135 while (insts_in && 136 inputIndex < insts_in->width() && /* Still more input */ 137 output_index < outputWidth /* Still more output to fill */) 138 { 139 MinorDynInstPtr inst = insts_in->insts[inputIndex]; 140 141 if (inst->isBubble()) { 142 /* Skip */ 143 inputIndex++; 144 inMacroop = false; 145 } else { 146 StaticInstPtr static_inst = inst->staticInst; 147 /* Static inst of a macro-op above the output_inst */ 148 StaticInstPtr parent_static_inst = NULL; 149 MinorDynInstPtr output_inst = inst; 150 151 if (inst->isFault()) { 152 DPRINTF(Decode, "Fault being passed: %d\n", 153 inst->fault->name()); 154 155 inputIndex++; 156 inMacroop = false; 157 } else if (static_inst->isMacroop()) { 158 /* Generate a new micro-op */ 159 StaticInstPtr static_micro_inst; 160 161 /* Set up PC for the next micro-op emitted */ 162 if (!inMacroop) { 163 microopPC = inst->pc; 164 inMacroop = true; 165 } 166 167 /* Get the micro-op static instruction from the 168 * static_inst. */ 169 static_micro_inst = 170 static_inst->fetchMicroop(microopPC.microPC()); 171 172 output_inst = new MinorDynInst(inst->id); 173 output_inst->pc = microopPC; 174 output_inst->staticInst = static_micro_inst; 175 output_inst->fault = NoFault; 176 177 /* Allow a predicted next address only on the last 178 * microop */ 179 if (static_micro_inst->isLastMicroop()) { 180 output_inst->predictedTaken = inst->predictedTaken; 181 output_inst->predictedTarget = inst->predictedTarget; 182 } 183 184 DPRINTF(Decode, "Microop decomposition inputIndex:" 185 " %d output_index: %d lastMicroop: %s microopPC:" 186 " %d.%d inst: %d\n", 187 inputIndex, output_index, 188 (static_micro_inst->isLastMicroop() ? 189 "true" : "false"), 190 microopPC.instAddr(), microopPC.microPC(), 191 *output_inst); 192 193 /* Acknowledge that the static_inst isn't mine, it's my 194 * parent macro-op's */ 195 parent_static_inst = static_inst; 196 197 static_micro_inst->advancePC(microopPC); 198 199 /* Step input if this is the last micro-op */ 200 if (static_micro_inst->isLastMicroop()) { 201 inputIndex++; 202 inMacroop = false; 203 } 204 } else { 205 /* Doesn't need decomposing, pass on instruction */ 206 DPRINTF(Decode, "Passing on inst: %s inputIndex:" 207 " %d output_index: %d\n", 208 *output_inst, inputIndex, output_index); 209 210 parent_static_inst = static_inst; 211 212 /* Step input */ 213 inputIndex++; 214 inMacroop = false; 215 } 216 217 /* Set execSeqNum of output_inst */ 218 output_inst->id.execSeqNum = execSeqNum; 219 /* Add tracing */ 220#if TRACING_ON 221 dynInstAddTracing(output_inst, parent_static_inst, cpu); 222#endif 223 224 /* Step to next sequence number */ 225 execSeqNum++; 226 227 /* Correctly size the output before writing */ 228 if(output_index == 0) insts_out.resize(outputWidth); 229 /* Push into output */ 230 insts_out.insts[output_index] = output_inst; 231 output_index++; 232 } 233 234 /* Have we finished with the input? */ 235 if (inputIndex == insts_in->width()) { 236 /* If we have just been producing micro-ops, we *must* have 237 * got to the end of that for inputIndex to be pushed past 238 * insts_in->width() */ 239 assert(!inMacroop); 240 popInput(); 241 insts_in = NULL; 242 243 if (processMoreThanOneInput) { 244 DPRINTF(Decode, "Wrapping\n"); 245 insts_in = getInput(); 246 } 247 } 248 } 249 250 /* The rest of the output (if any) should already have been packed 251 * with bubble instructions by insts_out's initialisation 252 * 253 * for (; output_index < outputWidth; output_index++) 254 * assert(insts_out.insts[output_index]->isBubble()); 255 */ 256 } 257 258 /* If we generated output, reserve space for the result in the next stage 259 * and mark the stage as being active this cycle */ 260 if (!insts_out.isBubble()) { 261 /* Note activity of following buffer */ 262 cpu.activityRecorder->activity(); 263 nextStageReserve.reserve(); 264 } 265 266 /* If we still have input to process and somewhere to put it, 267 * mark stage as active */ 268 if (getInput() && nextStageReserve.canReserve()) 269 cpu.activityRecorder->activateStage(Pipeline::DecodeStageId); 270 271 /* Make sure the input (if any left) is pushed */ 272 inputBuffer.pushTail(); 273} 274 275bool 276Decode::isDrained() 277{ 278 return inputBuffer.empty() && (*inp.outputWire).isBubble(); 279} 280 281void 282Decode::minorTrace() const 283{ 284 std::ostringstream data; 285 286 if (blocked) 287 data << 'B'; 288 else 289 (*out.inputWire).reportData(data); 290 291 MINORTRACE("insts=%s\n", data.str()); 292 inputBuffer.minorTrace(); 293} 294 295}
| 65{ 66 if (outputWidth < 1) 67 fatal("%s: executeInputWidth must be >= 1 (%d)\n", name, outputWidth); 68 69 if (params.decodeInputBufferSize < 1) { 70 fatal("%s: decodeInputBufferSize must be >= 1 (%d)\n", name, 71 params.decodeInputBufferSize); 72 } 73} 74 75const ForwardInstData * 76Decode::getInput() 77{ 78 /* Get insts from the inputBuffer to work with */ 79 if (!inputBuffer.empty()) { 80 const ForwardInstData &head = inputBuffer.front(); 81 82 return (head.isBubble() ? NULL : &(inputBuffer.front())); 83 } else { 84 return NULL; 85 } 86} 87 88void 89Decode::popInput() 90{ 91 if (!inputBuffer.empty()) 92 inputBuffer.pop(); 93 94 inputIndex = 0; 95 inMacroop = false; 96} 97 98#if TRACING_ON 99/** Add the tracing data to an instruction. This originates in 100 * decode because this is the first place that execSeqNums are known 101 * (these are used as the 'FetchSeq' in tracing data) */ 102static void 103dynInstAddTracing(MinorDynInstPtr inst, StaticInstPtr static_inst, 104 MinorCPU &cpu) 105{ 106 inst->traceData = cpu.getTracer()->getInstRecord(curTick(), 107 cpu.getContext(inst->id.threadId), 108 inst->staticInst, inst->pc, static_inst); 109 110 /* Use the execSeqNum as the fetch sequence number as this most closely 111 * matches the other processor models' idea of fetch sequence */ 112 if (inst->traceData) 113 inst->traceData->setFetchSeq(inst->id.execSeqNum); 114} 115#endif 116 117void 118Decode::evaluate() 119{ 120 inputBuffer.setTail(*inp.outputWire); 121 ForwardInstData &insts_out = *out.inputWire; 122 123 assert(insts_out.isBubble()); 124 125 blocked = false; 126 127 if (!nextStageReserve.canReserve()) { 128 blocked = true; 129 } else { 130 const ForwardInstData *insts_in = getInput(); 131 132 unsigned int output_index = 0; 133 134 /* Pack instructions into the output while we can. This may involve 135 * using more than one input line */ 136 while (insts_in && 137 inputIndex < insts_in->width() && /* Still more input */ 138 output_index < outputWidth /* Still more output to fill */) 139 { 140 MinorDynInstPtr inst = insts_in->insts[inputIndex]; 141 142 if (inst->isBubble()) { 143 /* Skip */ 144 inputIndex++; 145 inMacroop = false; 146 } else { 147 StaticInstPtr static_inst = inst->staticInst; 148 /* Static inst of a macro-op above the output_inst */ 149 StaticInstPtr parent_static_inst = NULL; 150 MinorDynInstPtr output_inst = inst; 151 152 if (inst->isFault()) { 153 DPRINTF(Decode, "Fault being passed: %d\n", 154 inst->fault->name()); 155 156 inputIndex++; 157 inMacroop = false; 158 } else if (static_inst->isMacroop()) { 159 /* Generate a new micro-op */ 160 StaticInstPtr static_micro_inst; 161 162 /* Set up PC for the next micro-op emitted */ 163 if (!inMacroop) { 164 microopPC = inst->pc; 165 inMacroop = true; 166 } 167 168 /* Get the micro-op static instruction from the 169 * static_inst. */ 170 static_micro_inst = 171 static_inst->fetchMicroop(microopPC.microPC()); 172 173 output_inst = new MinorDynInst(inst->id); 174 output_inst->pc = microopPC; 175 output_inst->staticInst = static_micro_inst; 176 output_inst->fault = NoFault; 177 178 /* Allow a predicted next address only on the last 179 * microop */ 180 if (static_micro_inst->isLastMicroop()) { 181 output_inst->predictedTaken = inst->predictedTaken; 182 output_inst->predictedTarget = inst->predictedTarget; 183 } 184 185 DPRINTF(Decode, "Microop decomposition inputIndex:" 186 " %d output_index: %d lastMicroop: %s microopPC:" 187 " %d.%d inst: %d\n", 188 inputIndex, output_index, 189 (static_micro_inst->isLastMicroop() ? 190 "true" : "false"), 191 microopPC.instAddr(), microopPC.microPC(), 192 *output_inst); 193 194 /* Acknowledge that the static_inst isn't mine, it's my 195 * parent macro-op's */ 196 parent_static_inst = static_inst; 197 198 static_micro_inst->advancePC(microopPC); 199 200 /* Step input if this is the last micro-op */ 201 if (static_micro_inst->isLastMicroop()) { 202 inputIndex++; 203 inMacroop = false; 204 } 205 } else { 206 /* Doesn't need decomposing, pass on instruction */ 207 DPRINTF(Decode, "Passing on inst: %s inputIndex:" 208 " %d output_index: %d\n", 209 *output_inst, inputIndex, output_index); 210 211 parent_static_inst = static_inst; 212 213 /* Step input */ 214 inputIndex++; 215 inMacroop = false; 216 } 217 218 /* Set execSeqNum of output_inst */ 219 output_inst->id.execSeqNum = execSeqNum; 220 /* Add tracing */ 221#if TRACING_ON 222 dynInstAddTracing(output_inst, parent_static_inst, cpu); 223#endif 224 225 /* Step to next sequence number */ 226 execSeqNum++; 227 228 /* Correctly size the output before writing */ 229 if(output_index == 0) insts_out.resize(outputWidth); 230 /* Push into output */ 231 insts_out.insts[output_index] = output_inst; 232 output_index++; 233 } 234 235 /* Have we finished with the input? */ 236 if (inputIndex == insts_in->width()) { 237 /* If we have just been producing micro-ops, we *must* have 238 * got to the end of that for inputIndex to be pushed past 239 * insts_in->width() */ 240 assert(!inMacroop); 241 popInput(); 242 insts_in = NULL; 243 244 if (processMoreThanOneInput) { 245 DPRINTF(Decode, "Wrapping\n"); 246 insts_in = getInput(); 247 } 248 } 249 } 250 251 /* The rest of the output (if any) should already have been packed 252 * with bubble instructions by insts_out's initialisation 253 * 254 * for (; output_index < outputWidth; output_index++) 255 * assert(insts_out.insts[output_index]->isBubble()); 256 */ 257 } 258 259 /* If we generated output, reserve space for the result in the next stage 260 * and mark the stage as being active this cycle */ 261 if (!insts_out.isBubble()) { 262 /* Note activity of following buffer */ 263 cpu.activityRecorder->activity(); 264 nextStageReserve.reserve(); 265 } 266 267 /* If we still have input to process and somewhere to put it, 268 * mark stage as active */ 269 if (getInput() && nextStageReserve.canReserve()) 270 cpu.activityRecorder->activateStage(Pipeline::DecodeStageId); 271 272 /* Make sure the input (if any left) is pushed */ 273 inputBuffer.pushTail(); 274} 275 276bool 277Decode::isDrained() 278{ 279 return inputBuffer.empty() && (*inp.outputWire).isBubble(); 280} 281 282void 283Decode::minorTrace() const 284{ 285 std::ostringstream data; 286 287 if (blocked) 288 data << 'B'; 289 else 290 (*out.inputWire).reportData(data); 291 292 MINORTRACE("insts=%s\n", data.str()); 293 inputBuffer.minorTrace(); 294} 295 296}
|