Пример #1
0
        public static string Convert_SLV_UFix(string value, TypeDescriptor ttype)
        {
            FixFormat fmt = UFix.GetFormat(ttype);

            return("lv_to_ufixed(" + value + ", sc_fixed<" + fmt.TotalWidth + ", " + fmt.IntWidth + "> (0))");
            //return "sc_ufixed<" + fmt.TotalWidth + ", " + fmt.IntWidth + "> (sc_bigint<" + fmt.TotalWidth + ">(" + value + "))";
        }
Пример #2
0
        public IEnumerable <IXILMapping> TryMap(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            var       fu     = taSite.Host;
            FixFPMod1 fpmod1 = fu as FixFPMod1;

            if (fpmod1 == null)
            {
                yield break;
            }
            if (instr.Name != InstructionCodes.Mod2 &&
                instr.Name != InstructionCodes.Rempow2)
            {
                yield break;
            }

            if (instr.Name == InstructionCodes.Rempow2)
            {
                int n = (int)instr.Operand;
                if (n != 0)
                {
                    yield break;
                }
            }

            FixFormat infmt  = GetFixFormat(operandTypes[0]);
            FixFormat outfmt = GetFixFormat(resultTypes[0]);

            if (infmt == null || outfmt == null)
            {
                yield break;
            }

            if (infmt.IntWidth < 2 || outfmt.IntWidth < 2)
            {
                yield break;
            }
            if (infmt.FracWidth != outfmt.FracWidth)
            {
                yield break;
            }

            if (infmt.IntWidth != fpmod1.InIntWidth)
            {
                yield break;
            }
            if (infmt.FracWidth != fpmod1.FracWidth)
            {
                yield break;
            }
            if (outfmt.IntWidth != fpmod1.OutIntWidth)
            {
                yield break;
            }

            yield return(new FPMod1XILMapping(fpmod1));
        }
Пример #3
0
 private bool IsFix(TypeDescriptor inType, out FixFormat format)
 {
     if (inType.CILType.Equals(typeof(SFix)) ||
         inType.CILType.Equals(typeof(UFix)))
     {
         format = inType.GetFixFormat();
         return(true);
     }
     format = null;
     return(false);
 }
Пример #4
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="floatWidth">total bit-width of input floating-point number
        /// (actual partitioning between exponent and mantissa bits does not matter)</param>
        /// <param name="outFormat">desired fixed-point output format</param>
        public FloatSignAsSigned(int floatWidth, FixFormat outFormat)
        {
            FloatWidth = floatWidth;
            OutFormat  = outFormat;

            _outM1 = SFix.FromDouble(-1.0, outFormat.IntWidth, outFormat.FracWidth).SLVValue;
            _out0  = SFix.FromDouble(0.0, outFormat.IntWidth, outFormat.FracWidth).SLVValue;
            _out1  = SFix.FromDouble(1.0, outFormat.IntWidth, outFormat.FracWidth).SLVValue;
            _zeros = StdLogicVector._0s(floatWidth - 1);

            TASite = new TransactionSite(this);
        }
Пример #5
0
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject proj)
        {
            if (instr.Name != InstructionCodes.Mod2 &&
                instr.Name != InstructionCodes.Rempow2)
            {
                return(null);
            }

            if (instr.Name == InstructionCodes.Rempow2)
            {
                int n = (int)instr.Operand;
                if (n != 0)
                {
                    return(null);
                }
            }

            FixFormat infmt  = GetFixFormat(operandTypes[0]);
            FixFormat outfmt = GetFixFormat(resultTypes[0]);

            if (infmt == null || outfmt == null)
            {
                return(null);
            }

            if (infmt.IntWidth < 2 || outfmt.IntWidth < 2)
            {
                return(null);
            }
            if (infmt.FracWidth != outfmt.FracWidth)
            {
                return(null);
            }

            FixFPMod1 slicer = new FixFPMod1(infmt.IntWidth, infmt.FracWidth, outfmt.IntWidth);

            return(new FPMod1XILMapping(slicer));
        }
Пример #6
0
        public IXILMapping TryMapOne(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            var           fu      = taSite.Host;
            XilinxDivider divider = fu as XilinxDivider;

            if (divider == null)
            {
                return(null);
            }

            if (instr.Name != InstructionCodes.Div &&
                instr.Name != InstructionCodes.DivQF)
            {
                return(null);
            }

            FixFormat fmtDividend   = GetFixFormat(operandTypes[0]);
            FixFormat fmtDivisor    = GetFixFormat(operandTypes[1]);
            FixFormat fmtQuotient   = GetFixFormat(resultTypes[0]);
            FixFormat fmtFractional = null;

            if (instr.Name == InstructionCodes.DivQF)
            {
                fmtFractional = GetFixFormat(resultTypes[1]);
            }

            if (fmtDividend.IsSigned != fmtDivisor.IsSigned ||
                fmtDividend.IsSigned != fmtQuotient.IsSigned)
            {
                return(null);
            }

            if (fmtDividend.TotalWidth != fmtQuotient.TotalWidth)
            {
                return(null);
            }

            int qFracWidth = fmtDividend.FracWidth - fmtDivisor.FracWidth;

            if (qFracWidth != fmtQuotient.FracWidth)
            {
                return(null);
            }

            int fracWidth = 0;

            if (fmtFractional != null)
            {
                fracWidth = fmtFractional.TotalWidth;
            }

            if (divider.DividendAndQuotientWidth != fmtDividend.TotalWidth)
            {
                return(null);
            }

            if (divider.DivisorWidth != fmtDivisor.TotalWidth)
            {
                return(null);
            }

            if ((divider.OperandSign == XilinxDivider.ESignedness.Signed) !=
                fmtDividend.IsSigned)
            {
                return(null);
            }

            if (divider.FractionWidth != fracWidth)
            {
                return(null);
            }

            return(new DividerXILMapping(divider));
        }
Пример #7
0
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject proj)
        {
            if (instr.Name != InstructionCodes.Div &&
                instr.Name != InstructionCodes.DivQF)
            {
                return(null);
            }

            FixFormat fmtDividend = GetFixFormat(operandTypes[0]);
            FixFormat fmtDivisor  = GetFixFormat(operandTypes[1]);
            FixFormat fmtQuotient = GetFixFormat(resultTypes[0]);

            if (fmtDividend == null ||
                fmtDivisor == null ||
                fmtQuotient == null)
            {
                return(null);
            }

            FixFormat fmtFractional = null;

            if (instr.Name == InstructionCodes.DivQF)
            {
                fmtFractional = GetFixFormat(resultTypes[1]);
            }

            if (fmtDividend.IsSigned != fmtDivisor.IsSigned ||
                fmtDividend.IsSigned != fmtQuotient.IsSigned)
            {
                return(null);
            }

            if (fmtDividend.TotalWidth != fmtQuotient.TotalWidth)
            {
                return(null);
            }

            int qFracWidth = fmtDividend.FracWidth - fmtDivisor.FracWidth;

            if (qFracWidth != fmtQuotient.FracWidth)
            {
                return(null);
            }

            int fracWidth = 0;

            if (fmtFractional != null)
            {
                fracWidth = fmtFractional.TotalWidth;
            }

            XilinxDivider divider = new XilinxDivider()
            {
                DividendAndQuotientWidth = fmtDividend.TotalWidth,
                DivisorWidth             = fmtDivisor.TotalWidth,
                FractionWidth            = fracWidth,
                OperandSign          = fmtDividend.IsSigned ? XilinxDivider.ESignedness.Signed : XilinxDivider.ESignedness.Unsigned,
                AlgorithmType        = XilinxDivider.ERadix.HighRadix,
                RemainderType        = XilinxDivider.ERemainder.Fractional,
                HasCE                = false,
                HasSCLR              = false,
                DivideByZeroDetect   = false,
                LatencyConfiguration = XilinxDivider.ELatencyConfiguration.Manual,
                ClocksPerDivision    = 1
            };
            int min          = divider.MinLatency;
            int max          = divider.MaxLatency;
            int scaledStages = (int)Math.Round(min + Config.PipeStageScaling * (max - min));

            if (scaledStages < min)
            {
                scaledStages = min;
            }
            else if (scaledStages > max)
            {
                scaledStages = max;
            }
            divider.Latency = scaledStages;

            return(new DividerXILMapping(divider));
        }