Ejemplo n.º 1
0
        /// <summary>
        /// Get inputs from instruction partitioner.
        /// We assume that host core can only process intructions(Not Functions and InstrcutionBlocks).
        /// When core encountered a non-instruction, return error.
        /// </summary>
        /// <returns>Instruction to be processed. If none, NOP.</returns>
        public Instruction get_ins_from_insp()
        {
            //current block has un-processed instructions
            if (current_block != null)
            {
                //get current instructions
                var item = current_block.get_ins(this.cycle);
                if (item != null)
                {
                    bandwidth_bit = bandwidth_bit + item.Length();
                    return(item);
                }
                else
                {
                    //current block is empty
                    if (block_latency.Any(s => s.Key == current_block.name))
                    {
                        block_latency[current_block.name] += cycle - current_block.servetime;
                    }
                    block_latency.Add(current_block.name, cycle - current_block.servetime);
                    current_block = null;
                }
            }

            Input tp;

            if (Config.trace_type == Trace_Type.PC)
            {
                tp = ins_p.get_req(this.pid, false, this.pc);
            }
            else
            {
                tp = ins_p.get_req(this.pid, false);
            }
            if (tp is Instruction)
            {
                switch ((tp as Instruction).type)
                {
                case InstructionType.READ:
                    read_reqs++;
                    break;

                case InstructionType.WRITE:
                    write_reqs++;
                    break;

                case InstructionType.NOP:
                    nop++;
                    break;

                case InstructionType.CALCULATION:
                    cal_ins++;
                    break;

                default:
                    break;
                }

                if ((tp as Instruction).is_mem)
                {
                    (tp as Instruction).block_addr = tlb.scan_page((tp as Instruction).address);
                }

                if (Config.DEBUG_PIM)
                {
                    DEBUG.WriteLine("-- Current Instruction : " + (tp as Instruction).ToString());
                }
                bandwidth_bit = bandwidth_bit + (tp as Instruction).Length();
                return(tp as Instruction);
            }
            else
            {
                if (tp is InstructionBlock)
                {
                    total_block_load++;
                    current_block = tp as InstructionBlock;
                    var item = current_block.get_ins(this.cycle);
                    if (item == null)
                    {
                        DEBUG.Error("Block Instructions cannot be none!");
                        Environment.Exit(2);
                    }
                    if (block_count.Any(s => s.Key == current_block.name))
                    {
                        block_count[current_block.name]++;
                    }
                    else
                    {
                        block_count.Add(current_block.name, 1);
                    }
                    if (Config.DEBUG_PIM)
                    {
                        DEBUG.WriteLine("-- Fetched Block : " + (tp as InstructionBlock).ToString());
                    }
                    bandwidth_bit = bandwidth_bit + (item as Instruction).Length();
                    return(item);
                }
                else
                {
                    if (tp is PCTrace)
                    {
                        pc = (tp as PCTrace).PC - 1;
                        var res = (tp as PCTrace).parsetoIns();
                        res.block_addr = tlb.scan_page(res.address);
                        return(res);
                    }
                    else
                    {
                        if (Config.DEBUG_PIM)
                        {
                            DEBUG.Error("-- Receieved a FUNCTION Input.");
                        }
                        Environment.Exit(Error.InputArgsError);
                        return(null);
                    }
                }
            }
        }