Exemplo n.º 1
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));
                    }
                }
            }
        }