Ejemplo n.º 1
0
        public static void S2r(EmitterContext context)
        {
            // TODO: Better impl.
            OpCodeAlu op = (OpCodeAlu)context.CurrOp;

            SystemRegister sysReg = (SystemRegister)op.RawOpCode.Extract(20, 8);

            Operand src;

            switch (sysReg)
            {
            case SystemRegister.LaneId: src = Attribute(AttributeConsts.LaneId); break;

            // TODO: Use value from Y direction GPU register.
            case SystemRegister.YDirection: src = ConstF(1); break;

            case SystemRegister.ThreadId:
            {
                Operand tidX = Attribute(AttributeConsts.ThreadIdX);
                Operand tidY = Attribute(AttributeConsts.ThreadIdY);
                Operand tidZ = Attribute(AttributeConsts.ThreadIdZ);

                tidY = context.ShiftLeft(tidY, Const(16));
                tidZ = context.ShiftLeft(tidZ, Const(26));

                src = context.BitwiseOr(tidX, context.BitwiseOr(tidY, tidZ));

                break;
            }

            case SystemRegister.ThreadIdX: src = Attribute(AttributeConsts.ThreadIdX); break;

            case SystemRegister.ThreadIdY: src = Attribute(AttributeConsts.ThreadIdY); break;

            case SystemRegister.ThreadIdZ: src = Attribute(AttributeConsts.ThreadIdZ); break;

            case SystemRegister.CtaIdX:    src = Attribute(AttributeConsts.CtaIdX);    break;

            case SystemRegister.CtaIdY:    src = Attribute(AttributeConsts.CtaIdY);    break;

            case SystemRegister.CtaIdZ:    src = Attribute(AttributeConsts.CtaIdZ);    break;

            case SystemRegister.EqMask:    src = Attribute(AttributeConsts.EqMask);    break;

            case SystemRegister.LtMask:    src = Attribute(AttributeConsts.LtMask);    break;

            case SystemRegister.LeMask:    src = Attribute(AttributeConsts.LeMask);    break;

            case SystemRegister.GtMask:    src = Attribute(AttributeConsts.GtMask);    break;

            case SystemRegister.GeMask:    src = Attribute(AttributeConsts.GeMask);    break;

            default: src = Const(0); break;
            }

            context.Copy(GetDest(context), src);
        }
Ejemplo n.º 2
0
        public FlagsRegister4Bit(SystemRegister id, IClock clock, IControlUnit controlUnit, IAlu alu)
        {
            this.id = id;
            Value   = 0;

            this.controlUnit = controlUnit;

            this.alu = alu;

            clock.AddConnectedComponent(this);

            updateFlagsLine = controlUnit.GetControlLine(ControlLineId.UPDATE_FLAGS);
        }
Ejemplo n.º 3
0
        public SystemRegister NewSystemRequest(string switchName)
        {
            var requestPrivateData = new SystemRegisterPrivateData
            {
                invertFilter          = true,
                invertFilterSpecified = true,
                switchName            = switchName,
            };
            var requestPrivateDataElement = XmlHelper.InstanceToElement <SystemRegisterPrivateData>(requestPrivateData);

            var request = new SystemRegister
            {
                requestTypes = new RequestTypes
                {
                    systemStatus          = true,
                    systemStatusSpecified = true,
                    //requestSystemStatus = true,
                    //requestSystemStatusSpecified = true,
                },
                requestedStatusFilter = new StatusFilter
                {
                    normal            = true,
                    normalSpecified   = true,
                    disabled          = true,
                    disabledSpecified = true,
                },
                extensions = new CSTACommonArguments
                {
                    privateData = new CSTAPrivateData
                    {
                        Item = new CSTAPrivateDataPrivate
                        {
                            Any = new XmlElement[] { requestPrivateDataElement }
                        }
                    }
                }
            };

            return(request);
        }
Ejemplo n.º 4
0
        public void NoBusRead(byte expectedValue, SystemRegister registerId, ControlLineId lineId)
        {
            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus = new Mock <IBus>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            var controlUnit = new Mock <IControlUnit>();

            ControlLine busInputLine = new ControlLine(lineId);

            controlUnit.Setup(x => x.GetControlLine(lineId)).Returns(busInputLine);

            Register reg = new Register(registerId, clock.Object, bus.Object, controlUnit.Object);

            busInputLine.State = false;
            reg.OnRisingEdge();

            // A register should not read a value when it's controlline is low
            Assert.Equal(0, reg.Value);
        }
Ejemplo n.º 5
0
        public void ReadValueFromBus(byte expectedValue, SystemRegister registerId, ControlLineId lineId)
        {
            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus = new Mock <IBus>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            var controlUnit = new Mock <IControlUnit>();

            ControlLine busInputLine = new ControlLine(lineId);

            controlUnit.Setup(x => x.GetControlLine(lineId)).Returns(busInputLine);

            Register reg = new Register(registerId, clock.Object, bus.Object, controlUnit.Object);

            busInputLine.State = true;
            reg.OnRisingEdge();

            // Register has it's input line high so should read the value currently on the bus
            Assert.Equal(expectedValue, reg.Value);
        }
Ejemplo n.º 6
0
        public Register(SystemRegister id, IClock clock, IBus bus, IControlUnit controlUnit)
        {
            this.id = id;
            Bus     = bus;
            Value   = 0;

            this.controlUnit = controlUnit;

            clock.AddConnectedComponent(this);

            switch (id)
            {
            case SystemRegister.A:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.A_REG_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.A_REG_IN);
                break;

            case SystemRegister.B:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.B_REG_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.B_REG_IN);
                break;

            case SystemRegister.MAR:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.MAR_IN);
                break;

            case SystemRegister.IR:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.IR_IN);
                break;

            case SystemRegister.IR_PARAM:
                busOutputLine = controlUnit.GetControlLine(ControlLineId.IR_PARAM_OUT);
                busInputLine  = controlUnit.GetControlLine(ControlLineId.IR_PARAM_IN);
                break;

            case SystemRegister.OUT:
                busOutputLine = null;
                busInputLine  = controlUnit.GetControlLine(ControlLineId.OUT_REG_IN);
                break;

            default:
                throw new ArgumentException("missing reg type");
            }

            // Setup the callback for when the bus output line goes high or low. Depending on which, we either start or stop driving the bus
            if (busOutputLine != null)
            {
                busOutputLine.onTransition = () =>
                {
                    if (busOutputLine.State == true)
                    {
                        Bus.Driver = this;
                    }
                    else
                    {
                        if (Bus.Driver == this)
                        {
                            Bus.Driver = null;
                        }
                    }
                    return(true);
                };
            }
        }
Ejemplo n.º 7
0
 public RegisterAtom(SystemRegister register)
 {
     AtomType      = ExpressionAtomType.Register;
     this.Register = register;
 }