예제 #1
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));
        }