Beispiel #1
0
 private void ImplementFlow(Flow flow, IAlgorithmBuilder pbuilder, SLVSignal cwSignal, HashSet <ISignalOrPortDescriptor> sensitivity)
 {
     if (FlowMatrix.IsDontCareFlow(flow))
     {
         int valOffset = _vfc.GetValueWordOffset(flow.Target);
         int valWidth  = _vfc.GetValueWordWidth(flow.Target);
         LiteralReference lrCWValSlice;
         if (flow.Target.Desc.ElementType.CILType.Equals(typeof(StdLogic)))
         {
             lrCWValSlice = new LiteralReference(
                 ((ISignal)cwSignal[valOffset])
                 .ToSignalRef(SignalRef.EReferencedProperty.Cur));
         }
         else
         {
             lrCWValSlice = new LiteralReference(
                 ((ISignal)cwSignal[valOffset + valWidth - 1, valOffset])
                 .ToSignalRef(SignalRef.EReferencedProperty.Cur));
         }
         pbuilder.Store(flow.Target, lrCWValSlice);
     }
     else if (flow is SignalFlow)
     {
         var sflow = flow as SignalFlow;
         pbuilder.Store(flow.Target, sflow.Source);
         sensitivity.Add(sflow.Source.Desc);
     }
     else
     {
         var vflow = flow as ValueFlow;
         pbuilder.Store(vflow.Target,
                        LiteralReference.CreateConstant(vflow.Value));
     }
 }
            private void BuildFlowMap()
            {
                _elseFlows         = new Dictionary <SignalRef, Flow>();
                _enablingStatesMap = new Dictionary <Flow, List <object> >();

                foreach (Flow flow in _flowSpec.NeutralFlow.Flows)
                {
                    if (FlowMatrix.IsDontCareFlow(flow))
                    {
                        var zflow = FlowMatrix.AsDontCareFlow((ValueFlow)flow, StdLogic.Z);
                        _elseFlows[flow.Target] = zflow;
                    }
                    else
                    {
                        NonTristateTargets.Add(flow.Target);
                    }
                }

                Array stateValues = _cpb._stateSignal.Descriptor.ElementType.CILType.GetEnumValues();

                for (int cstep = 0; cstep < stateValues.Length; cstep++)
                {
                    var state = stateValues.GetValue(cstep);
                    var pflow = _flowSpec.GetFlow(cstep);
                    foreach (var flow in pflow.Flows)
                    {
                        if (!_enablingStatesMap.ContainsKey(flow))
                        {
                            _enablingStatesMap[flow] = new List <object>();
                        }
                        _enablingStatesMap[flow].Add(state);
                    }
                }
            }
Beispiel #3
0
        public void Encode(int cstep, ParFlow pflow, ref StdLogicVector cw)
        {
            foreach (var flow in pflow.Flows)
            {
                if (FlowMatrix.IsDontCareFlow(flow))
                {
                    continue;
                }

                var vflow = flow as ValueFlow;
                if (vflow != null)
                {
                    int offs = _vfc.GetValueWordOffset(flow.Target);
                    var ser  = Marshal.SerializeForHW(vflow.Value);
                    cw[offs + ser.Size - 1, offs] = ser;
                }
            }

            if (SelWidth <= 0)
            {
                return;
            }

            int symbol = _encFlow.EncodedSymbols[cstep];

            if (symbol == 0)
            {
                symbol = 1;
            }
            uint index = (uint)(symbol - 1);

            cw[SelOffset + SelWidth - 1, SelOffset] = StdLogicVector.FromUInt(index, SelWidth);
        }
Beispiel #4
0
        public void AddFlow(ParFlow pflow)
        {
            var vflows = pflow.Flows.Where(f => f is ValueFlow && !FlowMatrix.IsDontCareFlow(f));

            _flowList.Add(new ParFlow(vflows));
            foreach (var f in vflows)
            {
                var vflow = (ValueFlow)f;
                int width = Marshal.SerializeForHW(vflow.Value).Size;
                _widthMap[f.Target] = width;
            }
        }
Beispiel #5
0
        public EncodedFlow(List <Flow> flows, int order)
        {
            Contract.Requires(flows != null && flows.Any());
            Contract.Requires(flows.All(f => f.Target.Equals(flows.First().Target)));

            Targets        = new SignalRef[] { flows.First().Target };
            EncodedSymbols = new int[flows.Count];
            Order          = order;
            _bwdEnc        = new List <ParFlow>();
            int i = 0;

            foreach (var flow in flows)
            {
                int sym = 0;
                if (!FlowMatrix.IsDontCareFlow(flow))
                {
                    var  vflow = flow as ValueFlow;
                    Flow cflow;
                    if (vflow != null)
                    {
                        cflow = FlowMatrix.AsDontCareFlow(vflow);
                    }
                    else
                    {
                        cflow = flow;
                    }
                    var cpflow = new ParFlow(new Flow[] { cflow });
                    if (!_fwdEnc.TryGetValue(cpflow, out sym))
                    {
                        sym             = ++NumSymbols;
                        _fwdEnc[cpflow] = sym;
                        _bwdEnc.Add(new ParFlow(new Flow[] { cflow }));
                    }
                }
                EncodedSymbols[i] = sym;
                i++;
            }
            if (_bwdEnc.Count == 0)
            {
                var dummy = new ParFlow();
                _bwdEnc.Add(dummy);
                _fwdEnc[dummy] = 1;
                NumSymbols     = 1;
            }
        }
Beispiel #6
0
        public IEnumerable <ParFlow> ToFlow(int numCsteps, ParFlow neutralFlow, bool[,] pipeEnMatrix)
        {
            int muxCount = _pipeInSignals.Count;

            int[,] flowMatrix = new int[numCsteps, muxCount];

            // 1st pass: set some arbitrary MUX selection
            for (int i = 0; i < numCsteps; i++)
            {
                for (int j = 0; j < muxCount; j++)
                {
                    if (_preds[j].Any())
                    {
                        flowMatrix[i, j] = _preds[j].First();
                    }
                    else
                    {
                        flowMatrix[i, j] = -1;
                    }
                }
            }

            // 2nd pass: reset MUX selection whenever neutral flow requires
            //           some value transfer which is not "don't care"
            foreach (var flow in neutralFlow.Flows)
            {
                if (FlowMatrix.IsDontCareFlow(flow) ||
                    !_signal2Idx.IsCached(flow.Target))
                {
                    continue;
                }

                int idx = _signal2Idx[flow.Target];
                for (int i = 0; i < numCsteps; i++)
                {
                    flowMatrix[i, idx] = -1;
                }
            }

            // 3rd pass: transfer MUX reservations to matrix
            for (int i = 0; i < _resTable.Count; i++)
            {
                var rmap = _resTable[i];
                var pi   = _pipes[i];
                foreach (var kvp in rmap)
                {
                    flowMatrix[kvp.Key + pi.delay, pi.sink] = i;
                }
            }

            var pipeen = pipeEnMatrix;

            // last pass: convert to flows
            for (int i = 0; i < numCsteps; i++)
            {
                var flows = new List <Flow>();
                for (int j = 0; j < muxCount; j++)
                {
                    int k = flowMatrix[i, j];
                    if (k >= 0)
                    {
                        flows.Add(
                            new SignalFlow(
                                _pipeOutSignals[k].ToSignalRef(SignalRef.EReferencedProperty.Cur),
                                _pipeInSignals[j].ToSignalRef(SignalRef.EReferencedProperty.Next)));
                    }
                }
                for (int pipe = 0; pipe < _pipes.Count; pipe++)
                {
                    if (!_pipes[pipe].useEn)
                    {
                        continue;
                    }
                    flows.Add(
                        new ValueFlow(
                            pipeen[i, pipe] ? StdLogic._1 : StdLogic._0,
                            _pipeEnSignals[pipe].ToSignalRef(SignalRef.EReferencedProperty.Next)));
                }
                yield return(new ParFlow(flows));
            }
        }
Beispiel #7
0
        public void Encode()
        {
            // This is a simple, inefficient greedy heuristic which essentially finds maximal cliques
            // within the graph of mutually exclusive signal targets.
            var mutexSet = new HashSet <Tuple <SignalRef, SignalRef> >();

            foreach (var pflow in _flowList)
            {
                var flows = pflow.Flows.ToArray();
                for (int i = 0; i < flows.Length; i++)
                {
                    for (int j = 0; j < flows.Length; j++)
                    {
                        var vf0 = (ValueFlow)flows[i];
                        var vf1 = (ValueFlow)flows[j];
                        if (!FlowMatrix.IsDontCareFlow(vf0) &&
                            !FlowMatrix.IsDontCareFlow(vf1) &&
                            !vf0.Value.Equals(vf1.Value))
                        {
                            mutexSet.Add(Tuple.Create(vf0.Target, vf1.Target));
                        }
                    }
                }
            }
            var order     = _widthMap.OrderByDescending(kvp => kvp.Value).Select(kvp => kvp.Key);
            var list      = new LinkedList <SignalRef>(order);
            int curOffset = 0;

            while (list.First != null)
            {
                var lln      = list.First;
                var curGroup = new HashSet <SignalRef>();
                curGroup.Add(lln.Value);
                int width = _widthMap[lln.Value];
                _offsetMap[lln.Value] = curOffset;
                var next = lln.Next;
                list.Remove(lln);
                lln = next;
                while (lln != null)
                {
                    bool found = true;
                    foreach (var elem in curGroup)
                    {
                        if (mutexSet.Contains(Tuple.Create(elem, lln.Value)))
                        {
                            found = false;
                            break;
                        }
                    }
                    if (found)
                    {
                        curGroup.Add(lln.Value);
                        _offsetMap[lln.Value] = curOffset;
                        next = lln.Next;
                        list.Remove(lln);
                        lln = next;
                    }
                    else
                    {
                        lln = lln.Next;
                    }
                }
                curOffset += width;
            }
            ValueWordWidth = curOffset;
        }