Ejemplo n.º 1
0
 public DecodeBufferEntry(DynamicInstruction dynamicInst)
 {
     this.Id = CurrentId++;
     this.DynamicInstruction = dynamicInst;
 }
Ejemplo n.º 2
0
        public void Update(uint baddr, uint btarget, bool isTaken, bool isPredTaken, bool isCorrect, DynamicInstruction dynamicInst, BranchPredictorUpdate dirUpdate)
        {
            StaticInstruction staticInst = dynamicInst.StaticInstruction;

            BranchTargetBufferEntry btbEntry = null;

            if (!staticInst.IsControl) {
                return;
            }

            if (staticInst.IsControl && !staticInst.IsUnconditionalBranch) {
                uint l1Index = (baddr >> (int)BranchPredictorConstants.BRANCH_SHIFT) & (this.TwoLevel.L1Size - 1);
                uint shiftReg = (this.TwoLevel.ShiftRegs[l1Index] << 1) | (uint)(isTaken ? 1 : 0);
                this.TwoLevel.ShiftRegs[l1Index] = (uint)(shiftReg & ((1 << (int)this.TwoLevel.ShiftWidth) - 1));
            }

            if (isTaken) {
                uint index = (baddr >> (int)BranchPredictorConstants.BRANCH_SHIFT) & (this.Btb.NumSets - 1);

                if (this.Btb.Associativity > 1) {
                    index *= this.Btb.Associativity;

                    BranchTargetBufferEntry lruHead = null, lruItem = null;

                    for (uint i = index; i < (index + this.Btb.Associativity); i++) {
                        if (this.Btb[i].Addr == baddr) {
                            btbEntry = this.Btb[i];
                        }

                        if (this.Btb[i].Prev == null) {
                            lruHead = this.Btb[i];
                        }

                        if (this.Btb[i].Next == null) {
                            lruItem = this.Btb[i];
                        }
                    }

                    if (btbEntry == null) {
                        btbEntry = lruItem;
                    }

                    if (btbEntry != lruHead) {
                        if (btbEntry.Prev != null) {
                            btbEntry.Prev.Next = btbEntry.Next;
                        }

                        if (btbEntry.Next != null) {
                            btbEntry.Next.Prev = btbEntry.Prev;
                        }

                        btbEntry.Next = lruHead;
                        btbEntry.Prev = null;
                        lruHead.Prev = btbEntry;
                    }
                } else {
                    btbEntry = this.Btb[index];
                }
            }

            if (dirUpdate.Pdir1 != null) {
                if (isTaken) {
                    if (dirUpdate.Pdir1.Value < 3) {
                        dirUpdate.Pdir1.Value++;
                    }
                } else {
                    if (dirUpdate.Pdir1.Value > 0) {
                        dirUpdate.Pdir1.Value--;
                    }
                }
            }

            if (dirUpdate.Pdir2 != null) {
                if (isTaken) {
                    if (dirUpdate.Pdir2.Value < 3) {
                        dirUpdate.Pdir2.Value++;
                    }
                } else {
                    if (dirUpdate.Pdir2.Value > 0) {
                        dirUpdate.Pdir2.Value--;
                    }
                }
            }

            if (dirUpdate.Pmeta != null) {
                if (dirUpdate.Bimod != dirUpdate.TwoLevel) {
                    if (dirUpdate.TwoLevel == isTaken) {
                        if (dirUpdate.Pmeta.Value < 3) {
                            dirUpdate.Pmeta.Value++;
                        }
                    } else {
                        if (dirUpdate.Pmeta.Value > 0) {
                            dirUpdate.Pmeta.Value--;
                        }
                    }
                }
            }

            if (btbEntry != null) {
                if (btbEntry.Addr == baddr) {
                    if (!isCorrect) {
                        btbEntry.Target = btarget;
                    }
                } else {
                    btbEntry.Addr = baddr;
                    btbEntry.StaticInstruction = staticInst;
                    btbEntry.Target = btarget;
                }
            }
        }
Ejemplo n.º 3
0
        private DynamicInstruction DecodeAndExecute()
        {
            this.Regs.Pc = this.Regs.Npc;
            this.Regs.Npc = this.Regs.Nnpc;
            this.Regs.Nnpc += (uint)Marshal.SizeOf (typeof(uint));

            StaticInstruction staticInst = this.Core.Isa.Decode (this.Regs.Pc, this.Mem);
            DynamicInstruction dynamicInst = new DynamicInstruction (this, this.Regs.Pc, staticInst);

            dynamicInst.Execute ();

            return dynamicInst;
        }
Ejemplo n.º 4
0
        public uint Lookup(uint baddr, uint btarget, DynamicInstruction dynamicInst, out BranchPredictorUpdate dirUpdate, out uint stackRecoverIndex)
        {
            StaticInstruction staticInst = dynamicInst.StaticInstruction;

            if (!staticInst.IsControl) {
                dirUpdate = null;
                stackRecoverIndex = 0;

                return 0;
            }

            dirUpdate = new BranchPredictorUpdate ();
            dirUpdate.Ras = false;
            dirUpdate.Pdir1 = null;
            dirUpdate.Pdir2 = null;
            dirUpdate.Pmeta = null;

            if (staticInst.IsControl && !staticInst.IsUnconditionalBranch) {
                BranchPredictorInfo bimodCtr = this.Bimod.Lookup (baddr);
                BranchPredictorInfo twoLevelCtr = this.TwoLevel.Lookup (baddr);
                BranchPredictorInfo metaCtr = this.Meta.Lookup (baddr);

                dirUpdate.Pmeta = metaCtr;
                dirUpdate.Meta = (metaCtr.Value >= 2);
                dirUpdate.Bimod = (bimodCtr.Value >= 2);
                dirUpdate.TwoLevel = (bimodCtr.Value >= 2);

                if (metaCtr.Value >= 2) {
                    dirUpdate.Pdir1 = twoLevelCtr;
                    dirUpdate.Pdir2 = bimodCtr;
                } else {
                    dirUpdate.Pdir1 = bimodCtr;
                    dirUpdate.Pdir2 = twoLevelCtr;
                }
            }

            if (this.Ras.Size > 0) {
                stackRecoverIndex = this.Ras.TopOfStack;
            } else {
                stackRecoverIndex = 0;
            }

            if (staticInst.IsFunctionReturn && this.Ras.Size > 0) {
                this.Ras.TopOfStack = (this.Ras.TopOfStack + this.Ras.Size - 1) % this.Ras.Size;
                dirUpdate.Ras = true;
            }

            if (staticInst.IsFunctionCall && this.Ras.Size > 0) {
                this.Ras.TopOfStack = (this.Ras.TopOfStack + 1) % this.Ras.Size;
                this.Ras[this.Ras.TopOfStack].Target = (uint)(baddr + Marshal.SizeOf (typeof(uint)));
            }

            uint index = (baddr >> (int)BranchPredictorConstants.BRANCH_SHIFT) & (this.Btb.NumSets - 1);

            BranchTargetBufferEntry btbEntry = null;

            if (this.Btb.Associativity > 1) {
                index *= this.Btb.Associativity;

                for (uint i = index; i < (index + this.Btb.Associativity); i++) {
                    if (this.Btb[i].Addr == baddr) {
                        btbEntry = this.Btb[i];
                        break;
                    }
                }
            } else {
                btbEntry = this.Btb[index];
                if (btbEntry.Addr != baddr) {
                    btbEntry = null;
                }
            }

            if (staticInst.IsControl && staticInst.IsUnconditionalBranch) {
                return btbEntry != null ? btbEntry.Target : 1;
            }

            if (btbEntry == null) {
                return (uint)(dirUpdate.Pdir1.Value >= 2 ? 1 : 0);
            } else {
                return (uint)(dirUpdate.Pdir1.Value >= 2 ? btbEntry.Target : 0);
            }
        }
Ejemplo n.º 5
0
        public ReorderBufferEntry(DynamicInstruction dynamicInst, List<RegisterDependency> iDeps, List<RegisterDependency> oDeps)
        {
            this.Id = CurrentId++;
            this.DynamicInstruction = dynamicInst;
            this.IDeps = iDeps;
            this.ODeps = oDeps;

            this.OldPhysRegs = new Dictionary<RegisterDependency, PhysicalRegister> ();
            this.PhysRegs = new Dictionary<RegisterDependency, PhysicalRegister> ();
            this.SrcPhysRegs = new Dictionary<RegisterDependency, PhysicalRegister> ();

            this.IsValid = true;
        }