private void _read()
 {
     _unsignedMin = new Unsigned(m_io, this, m_root);
     _unsignedMax = new Unsigned(m_io, this, m_root);
     _signedMin   = new Signed(m_io, this, m_root);
     _signedMax   = new Signed(m_io, this, m_root);
 }
Example #2
0
        public void MergeFrom(CreateResponse other)
        {
            if (other == null)
            {
                return;
            }
            switch (other.MessageCase)
            {
            case MessageOneofCase.Unsigned:
                if (Unsigned == null)
                {
                    Unsigned = new global::NeoFS.API.Session.Token();
                }
                Unsigned.MergeFrom(other.Unsigned);
                break;

            case MessageOneofCase.Result:
                if (Result == null)
                {
                    Result = new global::NeoFS.API.Session.Token();
                }
                Result.MergeFrom(other.Result);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
Example #3
0
        /// <summary>
        /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow.
        /// </summary>
        /// <remarks>Currently, conversions between all primitive numeric CIL types, enum types, and System#-intrinsic datatypes
        /// Signed, Unsigned, SFix, UFix and StdLogicVector are supported.</remarks>
        /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception>
        /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception>
        public static object ConvertLong(long src, TypeDescriptor dstType)
        {
            Contract.Requires <ArgumentNullException>(dstType != null, "dstType");

            if (dstType.CILType.Equals(typeof(Signed)))
            {
                return(Signed.FromLong(src, SFix.GetFormat(dstType).IntWidth));
            }
            else if (dstType.CILType.Equals(typeof(Unsigned)))
            {
                return(Unsigned.FromBigInt(new System.Numerics.BigInteger(src), UFix.GetFormat(dstType).IntWidth));
            }
            else if (dstType.CILType.Equals(typeof(SFix)))
            {
                return(SFix.FromSigned(Signed.FromLong(src, SFix.GetFormat(dstType).IntWidth), SFix.GetFormat(dstType).FracWidth));
            }
            else if (dstType.CILType.Equals(typeof(StdLogicVector)))
            {
                return(StdLogicVector.FromLong(src, StdLogicVector.GetLength(dstType)));
            }
            else
            {
                return(ConvertLong(src, dstType.CILType));
            }
        }
Example #4
0
        private void HandleLdelemFixAFixI(XILSInstr xilsi)
        {
            FixedArrayRef far   = (FixedArrayRef)xilsi.StaticOperand;
            Array         array = far.ArrayObj;

            long[] indices             = far.Indices;
            var    preds               = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            TypeDescriptor dwType = minfo.GetRawWordType();

            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Unsigned addr = ComputeConstAddress(array, indices, i);
                Emit(_iset.LdConst(addr)
                     .CreateStk(0, TypeDescriptor.GetTypeOf(addr)));
                Emit(_iset.RdMem(region)
                     .CreateStk(preds, 1, TypeDescriptor.GetTypeOf(addr), dwType));
            }
            uint           concatTypeSize = minfo.WordSize * layout.WordsPerElement;
            TypeDescriptor concatType     = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatTypeSize));

            if (layout.WordsPerElement > 1)
            {
                TypeDescriptor[] stackTypes = new TypeDescriptor[layout.WordsPerElement + 1];
                for (uint i = 0; i < layout.WordsPerElement; i++)
                {
                    stackTypes[i] = dwType;
                }
                stackTypes[layout.WordsPerElement] = concatType;
                Emit(_iset.Concat().CreateStk((int)layout.WordsPerElement, stackTypes));
            }

            TypeDescriptor elemTypeRaw = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((int)layout.ElementLayout.SizeInBits));

            if (concatTypeSize != layout.ElementLayout.SizeInBits)
            {
                Emit(_iset.Convert().CreateStk(1, concatType, elemTypeRaw));
            }
            TypeDescriptor elemType = layout.ElementLayout.LayoutedType;

            Emit(_iset.Convert().CreateStk(1, elemTypeRaw, elemType));
        }
Example #5
0
        private void Processing()
        {
            switch (PortAType)
            {
            case ESignedness.Signed:
                switch (PortBType)
                {
                case ESignedness.Signed:
                {
                    Signed temp = A.Cur.SignedValue * B.Cur.SignedValue;
                    _pipeIn.Next = temp.SLVValue[OutputWidthHigh, OutputWidthLow];
                }
                break;

                case ESignedness.Unsigned:
                {
                    Signed temp = A.Cur.SignedValue * B.Cur.UnsignedValue.SignedValue;
                    _pipeIn.Next = temp.SLVValue[OutputWidthHigh, OutputWidthLow];
                }
                break;

                default:
                    throw new NotImplementedException();
                }
                break;

            case ESignedness.Unsigned:
                switch (PortBType)
                {
                case ESignedness.Signed:
                {
                    Signed temp = A.Cur.UnsignedValue.SignedValue * B.Cur.SignedValue;
                    _pipeIn.Next = temp.SLVValue[OutputWidthHigh, OutputWidthLow];
                }
                break;

                case ESignedness.Unsigned:
                {
                    Unsigned temp = A.Cur.UnsignedValue * B.Cur.UnsignedValue;
                    _pipeIn.Next = temp.SLVValue[OutputWidthHigh, OutputWidthLow];
                }
                break;

                default:
                    throw new NotImplementedException();
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #6
0
        /// <summary>
        /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow.
        /// </summary>
        /// <remarks>Currently, conversions between all primitive numeric CIL types and enum types are supported.</remarks>
        /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception>
        /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception>
        public static object ConvertUnsigned(Unsigned src, Type dstType)
        {
            Contract.Requires <ArgumentNullException>(dstType != null, "dstType");

            if (dstType.Equals(typeof(double)))
            {
                return(UFix.FromUnsigned(src, 0).DoubleValue);
            }
            else
            {
                return(ConvertValue(src.ULongValue, dstType));
            }
        }
Example #7
0
        private void HandleStoreVar(XILSInstr xilsi)
        {
            var      var          = (Variable)xilsi.StaticOperand;
            var      mms          = GetVariableLayout(var);
            Unsigned addr         = mms.BaseAddress;
            var      addrType     = TypeDescriptor.GetTypeOf(addr);
            int      addrSize     = addr.Size;
            var      rawWordType  = Mapper.MarshalInfo.GetRawWordType();
            uint     concatSize   = (uint)(mms.Size * Mapper.MarshalInfo.WordSize);
            var      concatType   = TypeDescriptor.GetTypeOf(StdLogicVector._0s(concatSize));
            var      valueType    = var.Type;
            var      slvValue     = Marshal.SerializeForHW(valueType.GetSampleInstance());
            var      rawValueType = TypeDescriptor.GetTypeOf(slvValue);

            if (!rawValueType.Equals(valueType))
            {
                Emit(_iset.Convert().CreateStk(1, valueType, rawValueType));
            }
            if (!rawValueType.Equals(concatType))
            {
                Emit(_iset.Convert().CreateStk(1, rawValueType, concatType));
            }
            int shiftSize = MathExt.CeilLog2(concatSize);

            if (mms.Layout.Size > 1)
            {
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            Unsigned       shift     = Unsigned.FromULong(Mapper.MarshalInfo.WordSize, shiftSize);
            TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);

            for (ulong i = 0; i < mms.Layout.Size; i++)
            {
                if (!rawWordType.Equals(concatType))
                {
                    Emit(_iset.Convert().CreateStk(1, concatType, rawWordType));
                }
                Emit(_iset.WrMemFix(Mapper.DefaultRegion, addr).CreateStk(1, rawWordType));
                if (i < mms.Layout.Size - 1)
                {
                    if (i + 1 < mms.Layout.Size - 1)
                    {
                        Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
                    }
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(1, concatType, concatType));
                }
                addr = (addr + Unsigned.FromULong(1, 1)).Resize(addrSize);
            }
        }
Example #8
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="xIntWidth">integer bits of operand</param>
        /// <param name="xFracWidth">fractional bits of operand</param>
        /// <param name="yIntWidth">integer bits of result</param>
        /// <param name="yFracWidth">fractional bits of result</param>
        /// <param name="pipeStages">desired computation-only latency</param>
        /// <param name="data">data table</param>
        public LERP11Core(int xIntWidth, int xFracWidth, int yIntWidth, int yFracWidth, int pipeStages,
                          SFix[] data)
        {
            Contract.Requires <ArgumentOutOfRangeException>(xIntWidth > 0, "xIntWidth must be positive.");
            Contract.Requires <ArgumentOutOfRangeException>(xFracWidth >= 0, "xFracWidth must be non-negative.");
            Contract.Requires <ArgumentOutOfRangeException>(yIntWidth + yFracWidth > 0, "total bit-width of result must be positive");
            Contract.Requires <ArgumentOutOfRangeException>(pipeStages >= 0, "pipeStages must be non-negative.");
            Contract.Requires <ArgumentOutOfRangeException>(xFracWidth > 0 || pipeStages == 0, "xFracWidth == 0 is a degenerate case (lookup-only). No additional pipeline stages allowed.");
            Contract.Requires <ArgumentNullException>(data != null, "data");

            PipeStages = pipeStages;
            XIntWidth  = xIntWidth;
            XFracWidth = xFracWidth;
            YIntWidth  = yIntWidth;
            YFracWidth = yFracWidth;
            DIntWidth  = data[0].Format.IntWidth;
            DFracWidth = data[0].Format.FracWidth;

            _x = new Signal <UFix>()
            {
                InitialValue = UFix.FromDouble(0.0, xIntWidth, xFracWidth)
            };
            _y = new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(0.0, yIntWidth, yFracWidth)
            };
            AddrWidth = MathExt.CeilPow2(data.Length);
            _unitAddr = new Signal <Unsigned>()
            {
                InitialValue = Unsigned.FromUInt(0, AddrWidth)
            };
            _memContent = new VSignal <SFix>(data.Length, _ => new Signal <SFix>()
            {
                InitialValue = data[_]
            });

            _lerpUnit = new LERPUnit(xIntWidth, xFracWidth, yIntWidth, yFracWidth, pipeStages);
            Bind(() =>
            {
                _lerpUnit.Clk  = Clk;
                _lerpUnit.X    = _x;
                _lerpUnit.Y    = _y;
                _lerpUnit.Addr = _unitAddr;
                _lerpUnit.Data = _unitData;
            });
        }
Example #9
0
        /// <summary>
        /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow.
        /// </summary>
        /// <remarks>Currently, conversions between all primitive numeric CIL types, enum types, and System#-intrinsic datatypes
        /// Signed, Unsigned, SFix, UFix and StdLogicVector are supported.</remarks>
        /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception>
        /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception>
        public static object ConvertUnsigned(Unsigned src, TypeDescriptor dstType)
        {
            Contract.Requires <ArgumentNullException>(dstType != null, "dstType");

            if (dstType.CILType.Equals(typeof(Unsigned)))
            {
                return(src.Resize(UFix.GetFormat(dstType).IntWidth));
            }
            else if (dstType.CILType.Equals(typeof(UFix)))
            {
                return(UFix.FromUnsigned(src.Resize(UFix.GetFormat(dstType).TotalWidth), UFix.GetFormat(dstType).FracWidth));
            }
            else
            {
                return(ConvertUnsigned(src, dstType.CILType));
            }
        }
Example #10
0
 private void ComputeOutAddrWithRstQ()
 {
     if (Rst.Cur == '1')
     {
         _outAddr.Next = StartupAddr;
     }
     else if (_rstq.Cur[0] == '1' || (BrP.Cur != "1" && BrN.Cur != "0"))
     {
         _outAddr.Next =
             (_lastAddr.Cur.UnsignedValue +
              Unsigned.FromUInt(1, AddrWidth))
             .Resize(AddrWidth).SLVValue;
     }
     else
     {
         _outAddr.Next = AltAddr.Cur;
     }
 }
Example #11
0
 private void ComputeOutAddr()
 {
     if (Rst.Cur == '1')
     {
         _outAddr.Next = StartupAddr;
     }
     else if (BrP.Cur == "1" || BrN.Cur == "0")
     {
         _outAddr.Next = AltAddr.Cur;
     }
     else
     {
         _outAddr.Next =
             (_lastAddr.Cur.UnsignedValue +
              Unsigned.FromUInt(1, AddrWidth))
             .Resize(AddrWidth).SLVValue;
     }
 }
Example #12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (messageCase_ == MessageOneofCase.Unsigned)
            {
                hash ^= Unsigned.GetHashCode();
            }
            if (messageCase_ == MessageOneofCase.Result)
            {
                hash ^= Result.GetHashCode();
            }
            hash ^= (int)messageCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Example #13
0
        private void HandleLoadVar(XILSInstr xilsi)
        {
            var      var         = (Variable)xilsi.StaticOperand;
            var      mms         = GetVariableLayout(var);
            Unsigned addr        = mms.BaseAddress;
            var      addrType    = TypeDescriptor.GetTypeOf(addr);
            int      addrSize    = addr.Size;
            var      rawWordType = Mapper.MarshalInfo.GetRawWordType();
            var      stackTypes  = new TypeDescriptor[mms.Size + 1];

            for (ulong k = 0; k < mms.Size; k++)
            {
                Emit(_iset.RdMemFix(Mapper.DefaultRegion, addr)
                     .CreateStk(RemapPreds(xilsi.Preds), 0, rawWordType));
                addr          = (addr + Unsigned.FromULong(1, 1)).Resize(addrSize);
                stackTypes[k] = rawWordType;
            }
            uint concatSize = (uint)(mms.Size * Mapper.MarshalInfo.WordSize);
            var  concatType = TypeDescriptor.GetTypeOf(StdLogicVector._0s(concatSize));

            if (mms.Size > 1)
            {
                stackTypes[mms.Size] = concatType;
                Emit(_iset.Concat().CreateStk(stackTypes.Length, stackTypes));
            }
            var valueType    = var.Type;
            var slvValue     = Marshal.SerializeForHW(valueType.GetSampleInstance());
            var rawValueType = TypeDescriptor.GetTypeOf(slvValue);

            if (!rawValueType.Equals(concatType))
            {
                Emit(_iset.Convert().CreateStk(1, concatType, rawValueType));
            }
            if (!rawValueType.Equals(valueType))
            {
                Emit(_iset.Convert().CreateStk(1, rawValueType, valueType));
            }
        }
Example #14
0
        private void ImplementLdConst(object value)
        {
            var      mms         = GetDataLayout(value);
            Unsigned addr        = mms.BaseAddress;
            var      addrType    = TypeDescriptor.GetTypeOf(addr);
            int      addrSize    = addr.Size;
            var      rawWordType = Mapper.MarshalInfo.GetRawWordType();
            var      stackTypes  = new TypeDescriptor[mms.Size + 1];

            for (ulong k = 0; k < mms.Size; k++)
            {
                Emit(_iset.RdMemFix(Mapper.DefaultRegion, addr).CreateStk(0, rawWordType));
                addr          = (addr + Unsigned.FromULong(1, 1)).Resize(addrSize);
                stackTypes[k] = rawWordType;
            }
            uint concatSize = (uint)(mms.Size * Mapper.MarshalInfo.WordSize);
            var  concatType = TypeDescriptor.GetTypeOf(StdLogicVector._0s(concatSize));

            if (mms.Size > 1)
            {
                stackTypes[mms.Size] = concatType;
                Emit(_iset.Concat().CreateStk(stackTypes.Length, stackTypes));
            }
            var valueType    = TypeDescriptor.GetTypeOf(value);
            var slvValue     = StdLogicVector.Serialize(value);
            var rawValueType = TypeDescriptor.GetTypeOf(slvValue);

            if (!rawValueType.Equals(concatType))
            {
                Emit(_iset.Convert().CreateStk(1, concatType, rawValueType));
            }
            if (!rawValueType.Equals(valueType))
            {
                Emit(_iset.Convert().CreateStk(1, rawValueType, valueType));
            }
        }
Example #15
0
        private Unsigned ComputeConstAddress(Array array, long[] indices, uint nword)
        {
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            Unsigned addr = mms.BaseAddress;

            for (int i = 0; i < indices.Length; i++)
            {
                Unsigned offs = Unsigned.FromULong((ulong)indices[i] * layout.Strides[i], mms.Region.AddressWidth);
                addr += offs;
            }
            addr += Unsigned.FromUInt(nword, mms.Region.AddressWidth);
            addr  = addr.Resize(mms.Region.AddressWidth);

            return(addr);
        }
Example #16
0
 public static string ValueOf(ulong value)
 {
     return(ValueOf(Unsigned.FromULong(value, 64)));
 }
Example #17
0
        private void _parse()
        {
            _datatype = ((DataType)m_io.ReadU1());
            switch (Datatype)
            {
            case DataType.Integer:
            {
                _dataValue = new Integer(m_io, this, m_root);
                break;
            }

            case DataType.Unsigned:
            {
                _dataValue = new Unsigned(m_io, this, m_root);
                break;
            }

            case DataType.Long:
            {
                _dataValue = new Long(m_io, this, m_root);
                break;
            }

            case DataType.Boolean:
            {
                _dataValue = new Boolean(m_io, this, m_root);
                break;
            }

            case DataType.Structure:
            {
                _dataValue = new Structure(m_io, this, m_root);
                break;
            }

            case DataType.Array:
            {
                _dataValue = new Array(m_io, this, m_root);
                break;
            }

            case DataType.Float64:
            {
                _dataValue = new Float64(m_io, this, m_root);
                break;
            }

            case DataType.DoNotCare:
            {
                _dataValue = new DoNotCare(m_io, this, m_root);
                break;
            }

            case DataType.LongUnsigned:
            {
                _dataValue = new LongUnsigned(m_io, this, m_root);
                break;
            }

            case DataType.Time:
            {
                _dataValue = new Time(m_io, this, m_root);
                break;
            }

            case DataType.OctetString:
            {
                _dataValue = new OctetString(m_io, this, m_root);
                break;
            }

            case DataType.NullData:
            {
                _dataValue = new NullData(m_io, this, m_root);
                break;
            }

            case DataType.CompactArray:
            {
                _dataValue = new CompactArray(m_io, this, m_root);
                break;
            }

            case DataType.DateTime:
            {
                _dataValue = new DateTime(m_io, this, m_root);
                break;
            }

            case DataType.DoubleLongUnsigned:
            {
                _dataValue = new DoubleLongUnsigned(m_io, this, m_root);
                break;
            }

            case DataType.Float32:
            {
                _dataValue = new Float32(m_io, this, m_root);
                break;
            }

            case DataType.Long64Unsigned:
            {
                _dataValue = new Long64Unsigned(m_io, this, m_root);
                break;
            }

            case DataType.DoubleLong:
            {
                _dataValue = new DoubleLong(m_io, this, m_root);
                break;
            }

            case DataType.Long64:
            {
                _dataValue = new Long64(m_io, this, m_root);
                break;
            }

            case DataType.Date:
            {
                _dataValue = new Date(m_io, this, m_root);
                break;
            }

            case DataType.Enum:
            {
                _dataValue = new Enum(m_io, this, m_root);
                break;
            }

            case DataType.Bcd:
            {
                _dataValue = new Bcd(m_io, this, m_root);
                break;
            }

            case DataType.VisibleString:
            {
                _dataValue = new VisibleString(m_io, this, m_root);
                break;
            }

            case DataType.BitString:
            {
                _dataValue = new BitString(m_io, this, m_root);
                break;
            }
            }
        }
Example #18
0
        private async void Process()
        {
            float[,] sample = new float[16, 2];
            uint index;

            data_fin_out.Next = false;
            do
            {
                data_req.Next   = false;
                data_ready.Next = false;
                index           = 0;
                //Reading in the Samples
                Log.WriteLine();
                Log.WriteLine("Reading in the samples...");
                while (index < 16)
                {
                    data_req.Next = true;
                    do
                    {
                        await RisingEdge(CLK);
                    }while (!data_valid.Cur && !data_fin_in.Cur);
                    if (data_fin_in.Cur)
                    {
                        break;
                    }
                    sample[index, 0] = in_real.Cur;
                    sample[index, 1] = in_imag.Cur;
                    index++;
                    data_req.Next = false;
                    await RisingEdge(CLK);
                }

                if (index < 16)
                {
                    break;
                }

                index = 0;

                //////////////////////////////////////////////////////////////////////////
                ///  Computation - 1D Complex DFT In-Place DIF Computation Algorithm  ////
                //////////////////////////////////////////////////////////////////////////

                //Size of FFT, N = 2**M
                uint  N, M, len;
                float theta;
                float[,] W = new float[7, 2];
                float w_real, w_imag, w_rec_real, w_rec_imag, w_temp;

                //Initialize
                M     = 4; N = 16;
                len   = N / 2;
                theta = (float)(8.0 * Math.Atan(1.0) / N);

                Log.WriteLine();
                Log.WriteLine("Computing...");

                //Calculate the W-values recursively
                w_real = (float)Math.Cos(theta);
                w_imag = (float)-Math.Sin(theta);

                w_rec_real = 1;
                w_rec_imag = 0;

                index = 0;
                while (index < len - 1)
                {
                    w_temp      = w_rec_real * w_real - w_rec_imag * w_imag;
                    w_rec_imag  = w_rec_real * w_imag + w_rec_imag * w_real;
                    w_rec_real  = w_temp;
                    W[index, 0] = w_rec_real;
                    W[index, 1] = w_rec_imag;
                    index++;
                }

                float tmp_real, tmp_imag, tmp_real2, tmp_imag2;
                uint  stage, i, j, index2, windex, incr;

                //Begin Computation
                stage = 0;

                len  = N;
                incr = 1;

                while (stage < M)
                {
                    len = len / 2;

                    //First Iteration :  With No Multiplies
                    i = 0;

                    while (i < N)
                    {
                        index = i; index2 = index + len;

                        tmp_real = sample[index, 0] + sample[index2, 0];
                        tmp_imag = sample[index, 1] + sample[index2, 1];

                        sample[index2, 0] = sample[index, 0] - sample[index2, 0];
                        sample[index2, 1] = sample[index, 1] - sample[index2, 1];

                        sample[index, 0] = tmp_real;
                        sample[index, 1] = tmp_imag;

                        i = i + 2 * len;
                    }

                    //Remaining Iterations: Use Stored W
                    j = 1; windex = incr - 1;
                    while (j < len) // This loop executes N/2 times at first stage, .. once at last stage.
                    {
                        i = j;
                        while (i < N)
                        {
                            index  = i;
                            index2 = index + len;

                            tmp_real  = sample[index, 0] + sample[index2, 0];
                            tmp_imag  = sample[index, 1] + sample[index2, 1];
                            tmp_real2 = sample[index, 0] - sample[index2, 0];
                            tmp_imag2 = sample[index, 1] - sample[index2, 1];

                            sample[index2, 0] = tmp_real2 * W[windex, 0] - tmp_imag2 * W[windex, 1];
                            sample[index2, 1] = tmp_real2 * W[windex, 1] + tmp_imag2 * W[windex, 0];

                            sample[index, 0] = tmp_real;
                            sample[index, 1] = tmp_imag;

                            i = i + 2 * len;
                        }
                        windex = windex + incr;
                        j++;
                    }
                    stage++;
                    incr = 2 * incr;
                }

                //////////////////////////////////////////////////////////////////////////
                //Writing out the normalized transform values in bit reversed order
                Unsigned bits_i, bits_index;
                bits_index = Unsigned.FromULong(0, 4);
                bits_i     = Unsigned.FromULong(0, 4);
                i          = 0;

                Log.WriteLine("Writing the transform values...");
                while (i < 16)
                {
                    bits_i          = Unsigned.FromULong(i, 4);
                    bits_index[3]   = bits_i[0];
                    bits_index[2]   = bits_i[1];
                    bits_index[1]   = bits_i[2];
                    bits_index[0]   = bits_i[3];
                    index           = (uint)bits_index;
                    out_real.Next   = sample[index, 0];
                    out_imag.Next   = sample[index, 1];
                    data_ready.Next = true;
                    do
                    {
                        await RisingEdge(CLK);
                    }while (!data_ack.Cur);
                    data_ready.Next = false;
                    i++;
                    await RisingEdge(CLK);
                }
                index = 0;
                Log.WriteLine("Done...");
            } while (!data_fin_in.Cur);
            data_fin_out.Next = true;
            DesignContext.ExitProcess();
        }
Example #19
0
 /// <summary>
 /// Creates a write memory instruction with fixed address
 /// </summary>
 /// <param name="region">memory region to write to</param>
 /// <param name="addr">address to write to</param>
 public XILInstr WrMemFix(MemoryRegion region, Unsigned addr)
 {
     return(new XILInstr(InstructionCodes.WrMemFix, Tuple.Create(region, addr)));
 }
Example #20
0
        private static FixFormat Equalize(UFix a, UFix b, out Unsigned an, out Unsigned bn)
        {
            an = a._value;
            bn = b._value;
            FixFormat dfmt;
            switch (DesignContext.Instance.FixPoint.ArithSizingMode)
            {
                case EArithSizingMode.Safe:
                    dfmt = new FixFormat(false,
                        Math.Max(a.Format.IntWidth, b.Format.IntWidth) + 1,
                        Math.Max(a.Format.FracWidth, b.Format.FracWidth));
                    an = an.Resize(dfmt.TotalWidth - 1);
                    bn = bn.Resize(dfmt.TotalWidth - 1);
                    if (a.Format.FracWidth > b.Format.FracWidth)
                        bn = bn << (int)(a.Format.FracWidth - b.Format.FracWidth);
                    else if (b.Format.FracWidth > a.Format.FracWidth)
                        an = an << (int)(b.Format.FracWidth - a.Format.FracWidth);
                    return dfmt;

                case EArithSizingMode.VHDLCompliant:
                    dfmt = new FixFormat(false,
                        Math.Max(a.Format.IntWidth, b.Format.IntWidth) + 1,
                        Math.Max(a.Format.FracWidth, b.Format.FracWidth));
                    an = an.Resize(dfmt.TotalWidth);
                    bn = bn.Resize(dfmt.TotalWidth);
                    if (a.Format.FracWidth > b.Format.FracWidth)
                        bn = bn << (int)(a.Format.FracWidth - b.Format.FracWidth);
                    else if (b.Format.FracWidth > a.Format.FracWidth)
                        an = an << (int)(b.Format.FracWidth - a.Format.FracWidth);
                    return dfmt;

                case EArithSizingMode.InSizeIsOutSize:
                    dfmt = a.Format;
                    bn = bn.Resize(dfmt.TotalWidth);
                    if (a.Format.FracWidth > b.Format.FracWidth)
                        bn = bn << (int)(a.Format.FracWidth - b.Format.FracWidth);
                    else if (b.Format.FracWidth > a.Format.FracWidth)
                        an = an << (int)(b.Format.FracWidth - a.Format.FracWidth);
                    return dfmt;

                default:
                    throw new NotImplementedException();
            }
        }
Example #21
0
 private UFix(Unsigned value, int intWidth, int fracWidth)
 {
     Contract.Requires(intWidth + fracWidth >= 0);
     Debug.Assert(value.Size <= intWidth + fracWidth);
     _value = value;
     _format = new FixFormat(false, intWidth, fracWidth);
 }
        /// <summary>
        /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow.
        /// </summary>
        /// <remarks>Currently, conversions between all primitive numeric CIL types, enum types, and System#-intrinsic datatypes
        /// Signed, Unsigned, SFix, UFix and StdLogicVector are supported.</remarks>
        /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception>
        /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception>
        public static object ConvertUnsigned(Unsigned src, TypeDescriptor dstType)
        {
            Contract.Requires<ArgumentNullException>(dstType != null, "dstType");

            if (dstType.CILType.Equals(typeof(Unsigned)))
                return src.Resize(UFix.GetFormat(dstType).IntWidth);
            else if (dstType.CILType.Equals(typeof(UFix)))
                return UFix.FromUnsigned(src.Resize(UFix.GetFormat(dstType).TotalWidth), UFix.GetFormat(dstType).FracWidth);
            else
                return ConvertUnsigned(src, dstType.CILType);
        }
Example #23
0
        private void HandleStelemFixAFixI(XILSInstr xilsi)
        {
            FixedArrayRef far   = (FixedArrayRef)xilsi.StaticOperand;
            Array         array = far.ArrayObj;

            long[] indices             = far.Indices;
            var    preds               = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            TypeDescriptor elemType    = layout.ElementLayout.LayoutedType;
            TypeDescriptor rawElemType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((long)layout.ElementLayout.SizeInBits));

            if (!elemType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, elemType, rawElemType));
            }

            uint           concatSize = layout.WordsPerElement * minfo.WordSize;
            TypeDescriptor concatType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatSize));

            if (!concatType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, rawElemType, concatType));
            }

            TypeDescriptor rawWordType = minfo.GetRawWordType();
            int            shiftSize   = MathExt.CeilLog2(concatSize);

            if (layout.WordsPerElement > 1)
            {
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            Unsigned       shift     = Unsigned.FromULong(minfo.WordSize, shiftSize);
            TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);
            TypeDescriptor dwType    = minfo.GetRawWordType();

            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Unsigned addr = ComputeConstAddress(array, indices, i);
                Emit(_iset.LdConst(addr)
                     .CreateStk(0, TypeDescriptor.GetTypeOf(addr)));
                Emit(_iset.WrMem(region)
                     .CreateStk(preds, 2, dwType, TypeDescriptor.GetTypeOf(addr)));
                if (i < layout.WordsPerElement - 1)
                {
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(2, concatType, shiftType, concatType));
                    if (i + 1 < layout.WordsPerElement - 1)
                    {
                        Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
                    }
                }
            }
        }
Example #24
0
 public static Unsigned Abs(Signed value)
 {
     return(value.BigIntValue.Sign < 0 ?
            Unsigned.FromBigInt(-value.BigIntValue, value.Size) :
            Unsigned.FromBigInt(value.BigIntValue, value.Size));
 }
Example #25
0
        private void HandleStelemFixA(XILSInstr xilsi)
        {
            Array array                = (Array)xilsi.StaticOperand;
            var   preds                = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            EmitIndexComputation(array);

            TypeDescriptor indexType = TypeDescriptor.GetTypeOf(mms.BaseAddress);
            TypeDescriptor elemType  = layout.ElementLayout.LayoutedType;

            Emit(_iset.Swap().CreateStk(2, elemType, indexType, indexType, elemType));

            TypeDescriptor rawElemType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((long)layout.ElementLayout.SizeInBits));

            if (!elemType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, elemType, rawElemType));
            }

            uint           concatSize = layout.WordsPerElement * minfo.WordSize;
            TypeDescriptor concatType = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatSize));

            if (!concatType.Equals(rawElemType))
            {
                Emit(_iset.Convert().CreateStk(1, rawElemType, concatType));
            }

            TypeDescriptor rawWordType = minfo.GetRawWordType();
            int            shiftSize   = MathExt.CeilLog2(concatSize);

            if (layout.WordsPerElement > 1)
            {
                Emit(_iset.Swap().CreateStk(2, indexType, rawElemType, rawElemType, indexType));
                Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                Emit(_iset.Dig(2).CreateStk(3, concatType, indexType, indexType, indexType, indexType, concatType));
                Emit(_iset.Dup().CreateStk(1, concatType, concatType, concatType));
            }
            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Emit(_iset.Convert().CreateStk(1, concatType, rawWordType));
                if (i < layout.WordsPerElement - 1)
                {
                    Emit(_iset.Dig(2).CreateStk(3, indexType, concatType, rawWordType, concatType, rawWordType, indexType));
                }
                else
                {
                    Emit(_iset.Swap().CreateStk(2, indexType, rawWordType, rawWordType, indexType));
                }
                Emit(_iset.WrMem(region).CreateStk(preds, 2, rawWordType, indexType));
                if (i < layout.WordsPerElement - 1)
                {
                    Unsigned       shift     = Unsigned.FromULong(minfo.WordSize, shiftSize);
                    TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);
                    Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                    Emit(_iset.RShift().CreateStk(2, concatType, shiftType, concatType));
                    Emit(_iset.Swap().CreateStk(2, indexType, concatType, concatType, indexType));
                    if (minfo.UseStrongPow2Alignment)
                    {
                        if (i + 1 < layout.WordsPerElement)
                        {
                            Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                        }
                        Unsigned inc = Unsigned.FromULong(i + 1, region.AddressWidth);
                        Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType));
                        if (i + 1 < layout.WordsPerElement)
                        {
                            Emit(_iset.Dig(2).CreateStk(1, concatType, indexType, indexType, indexType, indexType, concatType));
                            Emit(_iset.Swap().CreateStk(2, concatType, indexType, indexType, concatType));
                        }
                    }
                    else
                    {
                        Unsigned inc = Unsigned.FromULong(1, region.AddressWidth);
                        Emit(_iset.LdConst(inc).CreateStk(0, indexType));
                        Emit(_iset.Add().CreateStk(2, indexType, indexType, indexType));
                        Emit(_iset.Swap().CreateStk(2, concatType, indexType, indexType, concatType));
                    }
                }
            }
        }
Example #26
0
 public InOut <T> this[Unsigned i, Unsigned j]
 {
     get { return(this[i.IntValue, j.IntValue]); }
 }
Example #27
0
 public static Unsigned Abs(Signed value)
 {
     return(value.IntXValue < 0 ?
            Unsigned.FromIntX(-value.IntXValue, value.Size) :
            Unsigned.FromIntX(value.IntXValue, value.Size));
 }
Example #28
0
        /// <summary>
        /// Returns a sequence of adminissible result types, given instruction operand types.
        /// </summary>
        /// <param name="instr">XIL instruction</param>
        /// <param name="operandTypes">operand types</param>
        /// <returns>admissible result types</returns>
        public static IEnumerable <TypeDescriptor> GetDefaultResultTypes(this XILInstr instr, TypeDescriptor[] operandTypes)
        {
            switch (instr.Name)
            {
            case InstructionCodes.Abs:
                if (operandTypes[0].CILType.Equals(typeof(float)) ||
                    operandTypes[0].CILType.Equals(typeof(double)) ||
                    operandTypes[0].CILType.Equals(typeof(int)) ||
                    operandTypes[0].CILType.Equals(typeof(long)) ||
                    operandTypes[0].CILType.Equals(typeof(sbyte)) ||
                    operandTypes[0].CILType.Equals(typeof(short)))
                {
                    yield return(operandTypes[0]);
                }
                else if (operandTypes[0].CILType.Equals(typeof(double)))
                {
                    yield return(typeof(double));
                }
                else if (operandTypes[0].CILType.Equals(typeof(SFix)))
                {
                    var fmt     = SFix.GetFormat(operandTypes[0]);
                    var ssample = SFix.FromDouble(0.0, fmt.IntWidth + 1, fmt.FracWidth);
                    yield return(TypeDescriptor.GetTypeOf(ssample));

                    var usample = UFix.FromDouble(0.0, fmt.IntWidth, fmt.FracWidth);
                    yield return(TypeDescriptor.GetTypeOf(usample));
                }
                else if (operandTypes[0].CILType.Equals(typeof(UFix)))
                {
                    yield return(operandTypes[0]);
                }
                else
                {
                    throw new NotSupportedException("Operand type not supported");
                }
                break;

            case InstructionCodes.Add:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 + o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.And:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 & o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Barrier:
            case InstructionCodes.BranchIfFalse:
            case InstructionCodes.BranchIfTrue:
                yield break;

            case InstructionCodes.Ceil:
            case InstructionCodes.Floor:
            case InstructionCodes.SinCos:
                if (operandTypes[0].CILType.Equals(typeof(float)) ||
                    operandTypes[0].CILType.Equals(typeof(double)))
                {
                    yield return(operandTypes[0]);
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case InstructionCodes.Cos:
            case InstructionCodes.Sin:
                if (operandTypes[0].CILType.Equals(typeof(float)) ||
                    operandTypes[0].CILType.Equals(typeof(double)))
                {
                    yield return(operandTypes[0]);
                }
                else if (operandTypes[0].CILType.Equals(typeof(UFix)) ||
                         operandTypes[0].CILType.Equals(typeof(SFix)))
                {
                    var fmt = operandTypes[0].GetFixFormat();
                    // computation works for at most 26 fractional bits
                    double xinc = Math.Pow(2.0, Math.Max(-26, -fmt.FracWidth));
                    double yinc = 1.0 - Math.Cos(xinc);
                    int    fw   = -MathExt.FloorLog2(yinc);
                    // Xilinx Cordic doesn't like more than 48 result bits
                    if (fw > 48)
                    {
                        fw = 48;
                    }
                    while (fw >= 0)
                    {
                        yield return(SFix.MakeType(2, fw));

                        --fw;
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case InstructionCodes.ScSin:
            case InstructionCodes.ScCos:
            case InstructionCodes.ScSinCos:
                if (operandTypes[0].CILType.Equals(typeof(float)) ||
                    operandTypes[0].CILType.Equals(typeof(double)))
                {
                    yield return(operandTypes[0]);
                }
                else if (operandTypes[0].CILType.Equals(typeof(UFix)) ||
                         operandTypes[0].CILType.Equals(typeof(SFix)))
                {
                    var fmt = operandTypes[0].GetFixFormat();
                    // computation works for at most 26 fractional bits
                    double xinc = Math.Pow(2.0, Math.Max(-26, -fmt.FracWidth));
                    double yinc = 1.0 - Math.Cos(xinc);
                    int    fw   = -MathExt.FloorLog2(yinc);
                    // Xilinx Cordic doesn't like more than 48 result bits
                    if (fw > 48)
                    {
                        fw = 48;
                    }
                    while (fw >= 0)
                    {
                        yield return(SFix.MakeType(2, fw));

                        --fw;
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case InstructionCodes.Sqrt:
                if (operandTypes[0].CILType.Equals(typeof(float)) ||
                    operandTypes[0].CILType.Equals(typeof(double)))
                {
                    yield return(operandTypes[0]);
                }
                else if (operandTypes[0].CILType.Equals(typeof(UFix)))
                {
                    var fmt = UFix.GetFormat(operandTypes[0]);
                    int iw  = (fmt.IntWidth + 1) / 2;
                    yield return(UFix.MakeType(iw, fmt.TotalWidth - iw));
                }
                else if (operandTypes[0].CILType.Equals(typeof(SFix)))
                {
                    var fmt = SFix.GetFormat(operandTypes[0]);
                    int iw  = fmt.IntWidth / 2;
                    yield return(UFix.MakeType(iw, fmt.TotalWidth - iw - 1));
                }
                else if (operandTypes[0].CILType.Equals(typeof(Unsigned)))
                {
                    var fmt = UFix.GetFormat(operandTypes[0]);
                    int iw  = (fmt.IntWidth + 1) / 2;
                    yield return(Unsigned.MakeType(iw));
                }
                else if (operandTypes[0].CILType.Equals(typeof(Signed)))
                {
                    var fmt = SFix.GetFormat(operandTypes[0]);
                    int iw  = fmt.IntWidth / 2;
                    yield return(Unsigned.MakeType(iw));
                }
                else
                {
                    throw new NotImplementedException();
                }
                break;

            case InstructionCodes.Cmp:
                throw new NotImplementedException();

            case InstructionCodes.Concat:
            {
                var v1 = (StdLogicVector)operandTypes[0].GetSampleInstance();
                var v2 = (StdLogicVector)operandTypes[1].GetSampleInstance();
                var c  = v1.Concat(v2);
                yield return(TypeDescriptor.GetTypeOf(c));
            }
            break;

            case InstructionCodes.Convert:
                throw new NotImplementedException();

            case InstructionCodes.Dig:
            case InstructionCodes.Dup:
            case InstructionCodes.Swap:
                throw new NotSupportedException();

            case InstructionCodes.Div:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance(ETypeCreationOptions.NonZero);
                object  r  = o1 / o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.ExitMarshal:
            case InstructionCodes.Goto:
            case InstructionCodes.Nop:
            case InstructionCodes.Pop:
            case InstructionCodes.Return:
            case InstructionCodes.StelemFixA:
            case InstructionCodes.StelemFixAFixI:
            case InstructionCodes.StoreVar:
            case InstructionCodes.WrMem:
            case InstructionCodes.WrMemFix:
            case InstructionCodes.WrPort:
                yield break;

            case InstructionCodes.Mod2:
            {
                var fmt = operandTypes[0].GetFixFormat();
                if (fmt == null)
                {
                    throw new NotSupportedException("mod2 is only supported for fixed-point types");
                }

                for (int iw = 2; iw <= fmt.IntWidth; iw++)
                {
                    yield return(new FixFormat(fmt.IsSigned, iw, fmt.FracWidth).ToType());
                }
            }
            break;

            case InstructionCodes.DivQF:
            case InstructionCodes.ExtendSign:
            case InstructionCodes.Ld0:
            case InstructionCodes.LdelemFixA:
            case InstructionCodes.LdelemFixAFixI:
            case InstructionCodes.LdMemBase:
            case InstructionCodes.LShift:
            case InstructionCodes.RdMem:
            case InstructionCodes.RdMemFix:
            case InstructionCodes.RShift:
            case InstructionCodes.Sign:
            case InstructionCodes.SliceFixI:
                throw new NotImplementedException();

            case InstructionCodes.IsEq:
            case InstructionCodes.IsGt:
            case InstructionCodes.IsGte:
            case InstructionCodes.IsLt:
            case InstructionCodes.IsLte:
            case InstructionCodes.IsNEq:
                yield return(typeof(bool));

                break;

            case InstructionCodes.LdConst:
                yield return(TypeDescriptor.GetTypeOf(instr.Operand));

                break;

            case InstructionCodes.LoadVar:
            {
                var lit = (IStorableLiteral)instr.Operand;
                yield return(lit.Type);
            }
            break;

            case InstructionCodes.Max:
            case InstructionCodes.Min:
                yield return(operandTypes[0]);

                break;

            case InstructionCodes.Mul:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 * o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Neg:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                object  r  = -o1;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Not:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                object  r  = !o1;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Or:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 | o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.RdPort:
            {
                var port = (ISignalOrPortDescriptor)instr.Operand;
                yield return(port.ElementType);
            }
            break;

            case InstructionCodes.Rem:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance(ETypeCreationOptions.NonZero);
                object  r  = o1 % o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Rempow2:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                int     n  = (int)instr.Operand;
                object  r  = MathExt.Rempow2((dynamic)o1, n);
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Select:
                yield return(operandTypes[1]);

                break;

            case InstructionCodes.Slice:
                yield return(typeof(StdLogicVector));

                break;

            case InstructionCodes.Sub:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 - o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            case InstructionCodes.Xor:
            {
                dynamic o1 = operandTypes[0].GetSampleInstance();
                dynamic o2 = operandTypes[1].GetSampleInstance();
                object  r  = o1 ^ o2;
                yield return(TypeDescriptor.GetTypeOf(r));
            }
            break;

            default:
                throw new NotImplementedException();
            }
        }
Example #29
0
 //      ????
 public static string ValueOf(Unsigned value)
 {
     return("sc_biguint<" + value.Size + ">(" + value.BigIntValue + ")");
 }
Example #30
0
 /// <summary>
 /// Constructs a new view on this signal which results from applying <paramref name="index"/> to it.
 /// </summary>
 public InOut <T> this[Unsigned index]
 {
     [SignalIndexer]
     get { return(_signals[index.IntValue]); }
 }
Example #31
0
        private void EmitIndexComputation(Array array)
        {
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            int            shiftWidth = MathExt.CeilLog2(mms.Region.AddressWidth);
            TypeDescriptor indexType  = TypeDescriptor.GetTypeOf(mms.BaseAddress);

            for (int i = 0; i < layout.Strides.Length; i++)
            {
                TypeDescriptor orgIndexType;
                if (i > 0)
                {
                    orgIndexType = TypeStack.Skip(1).First();
                    Emit(_iset.Swap().CreateStk(2, orgIndexType, indexType, indexType, orgIndexType));
                }
                else
                {
                    orgIndexType = TypeStack.Peek();
                }

                ulong stride = layout.Strides[layout.Strides.Length - i - 1];

                if (MathExt.IsPow2(stride))
                {
                    Emit(_iset.Convert().CreateStk(1, orgIndexType, indexType));
                    int ishift = MathExt.CeilLog2(stride);
                    if (ishift > 0)
                    {
                        Unsigned       shift     = Unsigned.FromULong((ulong)ishift, shiftWidth);
                        TypeDescriptor shiftType = TypeDescriptor.GetTypeOf(shift);
                        Emit(_iset.LdConst(shift).CreateStk(0, shiftType));
                        Emit(_iset.LShift().CreateStk(2, indexType, shiftType, indexType));
                    }
                }
                else
                {
                    throw new NotImplementedException("Stride ain't a power of 2");
                }

                if (i > 0)
                {
                    Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType));
                }
            }

            if (mms.BaseAddress.ULongValue != 0)
            {
                Emit(_iset.LdConst(mms.BaseAddress).CreateStk(0, indexType));
                if (minfo.UseStrongPow2Alignment)
                {
                    Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType));
                }
                else
                {
                    Emit(_iset.Add().CreateStk(2, indexType, indexType, indexType));
                }
            }
        }
Example #32
0
        private void HandleLdelemFixA(XILSInstr xilsi)
        {
            Array array                = (Array)xilsi.StaticOperand;
            var   preds                = RemapPreds(xilsi.Preds);
            MemoryMappedStorage mms    = GetDataLayout(array);
            ArrayMemoryLayout   layout = mms.Layout as ArrayMemoryLayout;

            if (layout.ElementsPerWord > 1)
            {
                throw new NotImplementedException("Multiple elements per word not yet implemented");
            }
            MemoryRegion region = mms.Region;
            IMarshalInfo minfo  = region.MarshalInfo;

            EmitIndexComputation(array);

            TypeDescriptor indexType = TypeDescriptor.GetTypeOf(mms.BaseAddress);
            TypeDescriptor dwType    = minfo.GetRawWordType();

            if (layout.WordsPerElement > 1)
            {
                Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
            }
            for (uint i = 0; i < layout.WordsPerElement; i++)
            {
                Emit(_iset.RdMem(region).CreateStk(preds, 1, indexType, dwType));
                if (i < layout.WordsPerElement - 1)
                {
                    Emit(_iset.Swap().CreateStk(2, indexType, dwType, dwType, indexType));
                    if (minfo.UseStrongPow2Alignment)
                    {
                        if (i + 1 < layout.WordsPerElement - 1)
                        {
                            Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                        }
                        Unsigned inc = Unsigned.FromULong(i + 1, region.AddressWidth);
                        Emit(_iset.LdConst(inc).CreateStk(0, indexType));
                        Emit(_iset.Or().CreateStk(2, indexType, indexType, indexType));
                    }
                    else
                    {
                        Unsigned inc = Unsigned.FromULong(1, region.AddressWidth);
                        Emit(_iset.LdConst(inc).CreateStk(0, indexType));
                        Emit(_iset.Add().CreateStk(2, indexType, indexType, indexType));
                        if (i + 1 < layout.WordsPerElement - 1)
                        {
                            Emit(_iset.Dup().CreateStk(1, indexType, indexType, indexType));
                        }
                    }
                }
            }

            uint           concatTypeSize = minfo.WordSize * layout.WordsPerElement;
            TypeDescriptor concatType     = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s(concatTypeSize));

            if (layout.WordsPerElement > 1)
            {
                TypeDescriptor[] stackTypes = new TypeDescriptor[layout.WordsPerElement + 1];
                for (uint i = 0; i < layout.WordsPerElement; i++)
                {
                    stackTypes[i] = dwType;
                }
                stackTypes[layout.WordsPerElement] = concatType;
                Emit(_iset.Concat().CreateStk((int)layout.WordsPerElement, stackTypes));
            }

            TypeDescriptor elemTypeRaw = TypeDescriptor.GetTypeOf(
                StdLogicVector._0s((int)layout.ElementLayout.SizeInBits));

            if (concatTypeSize != layout.ElementLayout.SizeInBits)
            {
                Emit(_iset.Convert().CreateStk(1, concatType, elemTypeRaw));
            }
            TypeDescriptor elemType = layout.ElementLayout.LayoutedType;

            Emit(_iset.Convert().CreateStk(1, elemTypeRaw, elemType));
        }
        /// <summary>
        /// Converts <paramref name="src"/> to <paramref name="dstType"/> datatype, possibly with loss of precision or overflow.
        /// </summary>
        /// <remarks>Currently, conversions between all primitive numeric CIL types and enum types are supported.</remarks>
        /// <exception cref="ArgumentNullException">if <paramref name="dstType"/> is null</exception>
        /// <exception cref="NotImplementedException">if there is no known conversion to <paramref name="dstType"/></exception>
        public static object ConvertUnsigned(Unsigned src, Type dstType)
        {
            Contract.Requires<ArgumentNullException>(dstType != null, "dstType");

            if (dstType.Equals(typeof(double)))
                return UFix.FromUnsigned(src, 0).DoubleValue;
            else
                return ConvertValue(src.ULongValue, dstType);
        }
Example #34
0
        /// <summary>
        /// Constructs a new instance
        /// </summary>
        /// <param name="lutWidth">resolution of data table</param>
        /// <param name="xFracWidth">fractional width of operand</param>
        /// <param name="yFracWidth">fractional width of result</param>
        /// <param name="pipeStages">additional pipeline stages for interpolation computation</param>
        public SinCosLUTCore(int lutWidth, int xFracWidth, int yFracWidth, int pipeStages)
        {
            PipeStages = pipeStages;
            XIntWidth  = 2;
            XFracWidth = xFracWidth;
            YIntWidth  = 2;
            YFracWidth = yFracWidth;
            DIntWidth  = 2;
            DFracWidth = yFracWidth;
            LUTWidth   = lutWidth;

            _x = new Signal <UFix>()
            {
                InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1)
            };
            _xq = new Signal <UFix>()
            {
                InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1)
            };
            _sinRaw = new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth)
            };
            _cosRaw = new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth)
            };
            _sinIn = new SLVSignal(YIntWidth + YFracWidth)
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue
            };
            _cosIn = new SLVSignal(YIntWidth + YFracWidth)
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue
            };
            _sinOut = new SLVSignal(YIntWidth + YFracWidth)
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue
            };
            _cosOut = new SLVSignal(YIntWidth + YFracWidth)
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue
            };
            AddrWidth = lutWidth + 1;
            _sinAddr  = new Signal <Unsigned>()
            {
                InitialValue = Unsigned.FromUInt(0, AddrWidth)
            };
            _cosAddr = new Signal <Unsigned>()
            {
                InitialValue = Unsigned.FromUInt(0, AddrWidth)
            };
            _sinData = new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth)
            };
            _cosData = new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth)
            };
            _sinLUT = new VSignal <SFix>((1 << lutWidth) + 2, _ => new Signal <SFix>()
            {
                InitialValue = SFix.FromDouble(Math.Sin(Math.PI * 0.5 * _ / (double)(1 << lutWidth)), 2, yFracWidth)
            });
            _sinFlipSignIn = new SLVSignal(1)
            {
                InitialValue = "0"
            };
            _cosFlipSignIn = new SLVSignal(1)
            {
                InitialValue = "0"
            };
            _sinFlipSignOut = new SLVSignal(1)
            {
                InitialValue = "0"
            };
            _cosFlipSignOut = new SLVSignal(1)
            {
                InitialValue = "0"
            };

            _mirror  = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << (xFracWidth + 1), xFracWidth - LUTWidth);
            _mirror2 = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << xFracWidth, xFracWidth - LUTWidth);

            _sinPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth);
            Bind(() => {
                _sinPipe.Clk  = Clk;
                _sinPipe.Din  = _sinIn;
                _sinPipe.Dout = _sinOut;
            });

            _cosPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth);
            Bind(() => {
                _cosPipe.Clk  = Clk;
                _cosPipe.Din  = _cosIn;
                _cosPipe.Dout = _cosOut;
            });

            _sinFlipSignPipe = new RegPipe(2, 1);
            Bind(() => {
                _sinFlipSignPipe.Clk  = Clk;
                _sinFlipSignPipe.Din  = _sinFlipSignIn;
                _sinFlipSignPipe.Dout = _sinFlipSignOut;
            });

            _cosFlipSignPipe = new RegPipe(2, 1);
            Bind(() => {
                _cosFlipSignPipe.Clk  = Clk;
                _cosFlipSignPipe.Din  = _cosFlipSignIn;
                _cosFlipSignPipe.Dout = _cosFlipSignOut;
            });

            _sinUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0);
            Bind(() =>
            {
                _sinUnit.Clk  = Clk;
                _sinUnit.X    = _x;
                _sinUnit.Y    = _sinRaw;
                _sinUnit.Addr = _sinAddr;
                _sinUnit.Data = _sinData;
            });

            _cosUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0);
            Bind(() =>
            {
                _cosUnit.Clk  = Clk;
                _cosUnit.X    = _xq;
                _cosUnit.Y    = _cosRaw;
                _cosUnit.Addr = _cosAddr;
                _cosUnit.Data = _cosData;
            });

            TASite = new TransactionSite(this);
        }
Example #35
0
 public BlockMemWriteFixMapping(IXilinxBlockMemSide site, Unsigned addr) :
     base(site, EMappingKind.ExclusiveResource)
 {
     _site = site;
     _addr = addr;
 }