Example #1
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 #2
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 #3
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 #4
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 #5
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));
        }
Example #6
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));
                }
            }
        }