public static string Convert_SLV_SFix(string value, string intWidth, string fracWidth, TypeDescriptor ttype) { var fmt = ttype.GetFixFormat(); return("lv_to_fixed(" + value + ", sc_fixed<" + fmt.TotalWidth + ", " + fmt.IntWidth + "> (0))"); //return "sc_fixed<" + fmt.TotalWidth + ", " + fmt.IntWidth + "> (sc_bigint<" + fmt.TotalWidth + ">(" + value + "))"; }
public virtual string DeclareCompletedType(TypeDescriptor td) { StringBuilder sb = new StringBuilder(); sb.Append(Name); if (td.Rank > 0) { if (td.Constraints != null) { if (td.CILType.Equals(typeof(SFix)) || td.CILType.Equals(typeof(UFix))) { sb.Append("<" + td.GetFixFormat().TotalWidth + ", " + td.GetFixFormat().IntWidth + ">"); } else if (td.CILType.Name.Equals("StdLogicVector") || td.CILType.Equals(typeof(Signed)) || td.CILType.Equals(typeof(Unsigned))) { sb.Append("<" + td.Constraints[0].Size + ">"); } else if (td.CILType.Name.Equals("StdLogicVector[]")) { long dim1 = td.Constraints[0].Size; string dim2 = td.Element0Type.Index.Indices[0].ToString(); string[] aux = dim2.Split(' '); int a = Convert.ToInt32(aux[0]); int b = Convert.ToInt32(aux[2]); sb.Append("<" + (Math.Abs(a - b) + 1) + ">"); } //else // sb.Append(GetRangeSuffix(td.Constraints[0])); } else { sb.Append("(???)"); } } else if (RangeSpec == ERangeSpec.BySize && ShowDefaultRange) { sb.Append(GetRangeSuffix(DefaultRange)); } return(sb.ToString()); }
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); }
private static IEnumerable <XILSInstr> Rewrite_Sin_ScSinCos_fixpt(TypeDescriptor joker, TypeDescriptor rtype, InstructionDependency[] preds) { var iset = DefaultInstructionSet.Instance; var fmt = joker.GetFixFormat(); var rfmt = rtype.GetFixFormat(); int pifw = fmt.FracWidth; var pitype = SFix.MakeType(0, pifw); int muliw = fmt.IntWidth; var multype = SFix.MakeType(muliw, fmt.FracWidth + pifw); int fw = Math.Max(5, rfmt.FracWidth + 1); // Xilinx Cordic needs at least 8 input bits fw = Math.Min(45, fw); // Xilinx Cordic likes at most 48 input bits var cuttype = SFix.MakeType(3, fw); var modtype = SFix.MakeType(3, fw); // Actually, 1 integer bit less is required. However, Xilinx Cordic needs the additional bit. int fwr = Math.Max(6, rfmt.FracWidth); // Xilinx Cordic needs at least 8 output bits (?) fwr = Math.Min(46, fwr); // Xilinx Cordic likes at most 48 output bits (?) var sintype = SFix.MakeType(2, fwr); if (muliw <= 1) { return(new XILSInstr[] { iset.LdConst(SFix.FromDouble(1.0 / Math.PI, 0, pifw)).CreateStk(preds, 0, pitype), iset.Mul().CreateStk(2, joker, pitype, multype), iset.Convert().CreateStk(1, multype, modtype), iset.ScSinCos().CreateStk(1, modtype, sintype, sintype), iset.Swap().CreateStk(2, sintype, sintype, sintype, sintype), iset.Pop().CreateStk(1, sintype) }); } else { return(new XILSInstr[] { iset.LdConst(SFix.FromDouble(1.0 / Math.PI, 0, pifw)).CreateStk(preds, 0, pitype), iset.Mul().CreateStk(2, joker, pitype, multype), iset.Convert().CreateStk(1, multype, cuttype), iset.Mod2().CreateStk(1, cuttype, modtype), iset.ScSinCos().CreateStk(1, modtype, sintype, sintype), iset.Swap().CreateStk(2, sintype, sintype, sintype, sintype), iset.Pop().CreateStk(1, sintype) }); } }
private TypeDescriptor GetNearestType(IEnumerable <TypeDescriptor> types, TypeDescriptor type) { var candidates = types.Where(t => t.CILType.Equals(type.CILType)); if (type.CILType.Equals(typeof(SFix)) || type.CILType.Equals(typeof(UFix)) || type.CILType.Equals(typeof(Signed)) || type.CILType.Equals(typeof(Unsigned))) { var fmt = type.GetFixFormat(); candidates = candidates.OrderBy(t => Math.Abs(t.GetFixFormat().IntWidth - fmt.IntWidth)); candidates = candidates.OrderBy(t => Math.Abs(t.GetFixFormat().FracWidth - fmt.FracWidth)); } var result = candidates.FirstOrDefault(); if (result == null) { result = types.FirstOrDefault(); } return(result); }
private static IEnumerable<XILSInstr> Rewrite_Sin_ScSinCos_fixpt(TypeDescriptor joker, TypeDescriptor rtype, InstructionDependency[] preds) { var iset = DefaultInstructionSet.Instance; var fmt = joker.GetFixFormat(); var rfmt = rtype.GetFixFormat(); int pifw = fmt.FracWidth; var pitype = SFix.MakeType(0, pifw); int muliw = fmt.IntWidth; var multype = SFix.MakeType(muliw, fmt.FracWidth + pifw); int fw = Math.Max(5, rfmt.FracWidth + 1); // Xilinx Cordic needs at least 8 input bits fw = Math.Min(45, fw); // Xilinx Cordic likes at most 48 input bits var cuttype = SFix.MakeType(3, fw); var modtype = SFix.MakeType(3, fw); // Actually, 1 integer bit less is required. However, Xilinx Cordic needs the additional bit. int fwr = Math.Max(6, rfmt.FracWidth); // Xilinx Cordic needs at least 8 output bits (?) fwr = Math.Min(46, fwr); // Xilinx Cordic likes at most 48 output bits (?) var sintype = SFix.MakeType(2, fwr); if (muliw <= 1) { return new XILSInstr[] { iset.LdConst(SFix.FromDouble(1.0 / Math.PI, 0, pifw)).CreateStk(preds, 0, pitype), iset.Mul().CreateStk(2, joker, pitype, multype), iset.Convert().CreateStk(1, multype, modtype), iset.ScSinCos().CreateStk(1, modtype, sintype, sintype), iset.Swap().CreateStk(2, sintype, sintype, sintype, sintype), iset.Pop().CreateStk(1, sintype) }; } else { return new XILSInstr[] { iset.LdConst(SFix.FromDouble(1.0 / Math.PI, 0, pifw)).CreateStk(preds, 0, pitype), iset.Mul().CreateStk(2, joker, pitype, multype), iset.Convert().CreateStk(1, multype, cuttype), iset.Mod2().CreateStk(1, cuttype, modtype), iset.ScSinCos().CreateStk(1, modtype, sintype, sintype), iset.Swap().CreateStk(2, sintype, sintype, sintype, sintype), iset.Pop().CreateStk(1, sintype) }; } }
public static string Convert_UFix_SFix(string value, TypeDescriptor ttype) { var fmt = ttype.GetFixFormat(); return("sc_fixed<" + fmt.TotalWidth + ", " + fmt.IntWidth + "> (" + value + ")"); }