/// <summary> /// Constructs a new instance /// </summary> /// <param name="xIntWidth">integer width of operand</param> /// <param name="xFracWidth">fractional width of operand</param> /// <param name="yIntWidth">integer width of result</param> /// <param name="yFracWidth">fractional width of result</param> /// <param name="pipeStages">desired computation-only latency</param> public LERPUnit(int xIntWidth, int xFracWidth, int yIntWidth, int yFracWidth, int pipeStages) { Contract.Requires <ArgumentOutOfRangeException>(xIntWidth > 0, "xIntWidth must be positive."); Contract.Requires <ArgumentOutOfRangeException>(xFracWidth >= 0, "xFracWidth must be non-negative."); Contract.Requires <ArgumentOutOfRangeException>(yIntWidth + yFracWidth > 0, "total bit-width of result must be positive"); Contract.Requires <ArgumentOutOfRangeException>(pipeStages >= 0, "pipeStages must be non-negative."); Contract.Requires <ArgumentOutOfRangeException>(xFracWidth > 0 || pipeStages == 0, "xFracWidth == 0 is a degenerate case (lookup-only). No additional pipeline stages allowed."); PipeStages = pipeStages; XIntWidth = xIntWidth; XFracWidth = xFracWidth; YIntWidth = yIntWidth; YFracWidth = yFracWidth; AddrWidth = xIntWidth; _yIn = new SLVSignal(yIntWidth + yFracWidth); _yOut = new SLVSignal(yIntWidth + yFracWidth); _yPipe = new RegPipe(pipeStages, yIntWidth + yFracWidth); Bind(() => { _yPipe.Clk = Clk; _yPipe.Din = _yIn; _yPipe.Dout = _yOut; }); }
protected override void PreInitialize() { if (PipelineDepth > 0) { _rpipe = new RegPipe(PipelineDepth, TotalWidth) { Clk = Clk, Din = _pipeIn, Dout = _pipeOut }; } }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="inWidth">bit-width of operand</param> /// <param name="outWidth">bit-width of result</param> /// <param name="latency">desired latency</param> public FixedAbs(int inWidth, int outWidth, int latency) { InputWidth = inWidth; OutputWidth = outWidth; Latency = latency; if (latency > 1) { _pipeIn = new SLVSignal(outWidth); _pipeOut = new SLVSignal(outWidth); _rpipe = new RegPipe(latency, inWidth); } TASite = new TASiteImpl(this); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="dataWidth">bit-width of operand</param> /// <param name="pipelineDepth">number of pipeline stages, i.e. computation latency</param> public Shifter(int dataWidth, int pipelineDepth) { DataWidth = dataWidth; ShiftWidth = MathExt.CeilLog2(dataWidth); PipelineDepth = pipelineDepth; _y = new SLVSignal(DataWidth); _pad = StdLogicVector._0s(DataWidth); _pipe = new RegPipe(PipelineDepth, DataWidth); Bind(() => { _pipe.Clk = Clk; _pipe.Din = _y; _pipe.Dout = Y; }); TASite = new ShifterTransactor(this); }
public static void RunTest() { DesignContext.Reset(); RegPipe dut = new RegPipe(100, 32, true) { Clk = new SLSignal(), Din = new SLVSignal(32), Dout = new SLVSignal(32), En = new SLSignal() }; DesignContext.Instance.Elaborate(); var fpga = new DefaultXilinxDevice() { SpeedGrade = ESpeedGrade._2, TopLevelComponent = dut }; fpga.SetDevice(EDevice.xc5vlx110t); fpga.SetPackage(EPackage.ff1136); fpga.SpeedGrade = ESpeedGrade._2; fpga.Synthesize(@"c:\temp\RegPipeTest", "RegPipeTest", new ModelsimProject(@"c:\temp\RegPipeTest", "RegPipeTest")); }
protected override void PreInitialize() { _quotient = new SLVSignal(DividendAndQuotientWidth); _remainder = new SLVSignal(FractionWidth); _quotientOut = new SLVSignal(DividendAndQuotientWidth); _remainderOut = new SLVSignal(FractionWidth); _qpipe = new RegPipe(Latency, DividendAndQuotientWidth); Bind(() => { _qpipe.Clk = CLK; _qpipe.Din = _quotient; _qpipe.Dout = _quotientOut; }); _rpipe = new RegPipe(Latency, FractionWidth); Bind(() => { _rpipe.Clk = CLK; _rpipe.Din = _remainder; _rpipe.Dout = _remainderOut; }); }
protected override void PreInitialize() { _result = new SLVSignal(OutWidth); _rpipe = new RegPipe(Latency, OutWidth); Bind(() => { _rpipe.Clk = CLK; _rpipe.Din = _result; _rpipe.Dout = S; }); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="funcSel">which operation the ALU is supposed to carry out</param> /// <param name="arithMode">signedness of operands/result</param> /// <param name="pipelineDepth">desired latency</param> /// <param name="awidth">width of first (or sole) operand</param> /// <param name="bwidth">width of second operand</param> /// <param name="rwidth">width of result</param> /// <exception cref="ArgumentOutOfRangeException">if parameter is invalid or inconsistency between parameters was detected</exception> public ALU(EFunction funcSel, EArithMode arithMode, int pipelineDepth, int awidth, int bwidth, int rwidth) { Contract.Requires<ArgumentOutOfRangeException>(pipelineDepth >= 0, "Pipeline depth must be non-negative."); Contract.Requires<ArgumentOutOfRangeException>(awidth >= 1, "Operand width A must be positive."); Contract.Requires<ArgumentOutOfRangeException>(funcSel.IsUnary() || bwidth >= 1, "Operand width B must be positive."); Contract.Requires<ArgumentOutOfRangeException>(funcSel == EFunction.Compare || rwidth >= 1, "Result width must be positive"); Contract.Requires<ArgumentOutOfRangeException>(funcSel == EFunction.Add || funcSel == EFunction.Mul || funcSel == EFunction.Neg || funcSel == EFunction.Sub || awidth == bwidth, "Operand sizes must be equal for this kind of operation."); Contract.Requires<ArgumentOutOfRangeException>(funcSel == EFunction.Add || funcSel == EFunction.Compare || funcSel == EFunction.Mul || funcSel == EFunction.Neg || funcSel == EFunction.Sub || rwidth == awidth, "Result and operand sizes must be equal for this kind of instruction."); FuncSel = funcSel; ArithMode = arithMode; PipelineDepth = pipelineDepth; if (funcSel == EFunction.Compare) rwidth = 6; AWidth = awidth; BWidth = bwidth; RWidth = rwidth; _opResult = new SLVSignal(rwidth) { InitialValue = StdLogicVector._0s(rwidth) }; if (pipelineDepth >= 3) { // If pipeline depth > 0, the operand inputs will be registered. // Thus, the post pipeline must be reduced by one stage. _pipe = new RegPipe(Math.Max(0, pipelineDepth - 1), rwidth); if (FuncSel == EFunction.Compare) { _pipeOut = new SLVSignal(rwidth) { InitialValue = StdLogicVector._0s(rwidth) }; Bind(() => { _pipe.Clk = Clk; _pipe.Din = _opResult; _pipe.Dout = _pipeOut; }); } else { Bind(() => { _pipe.Clk = Clk; _pipe.Din = _opResult; _pipe.Dout = R; }); } } _transactor = new ALUTransactor(this); }
/// <summary> /// Constructs a new instance /// </summary> /// <param name="lutWidth">resolution of data table</param> /// <param name="xFracWidth">fractional width of operand</param> /// <param name="yFracWidth">fractional width of result</param> /// <param name="pipeStages">additional pipeline stages for interpolation computation</param> public SinCosLUTCore(int lutWidth, int xFracWidth, int yFracWidth, int pipeStages) { PipeStages = pipeStages; XIntWidth = 2; XFracWidth = xFracWidth; YIntWidth = 2; YFracWidth = yFracWidth; DIntWidth = 2; DFracWidth = yFracWidth; LUTWidth = lutWidth; _x = new Signal<UFix>() { InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1) }; _xq = new Signal<UFix>() { InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1) }; _sinRaw = new Signal<SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _cosRaw = new Signal<SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _sinIn = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _cosIn = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _sinOut = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _cosOut = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; AddrWidth = lutWidth + 1; _sinAddr = new Signal<Unsigned>() { InitialValue = Unsigned.FromUInt(0, AddrWidth) }; _cosAddr = new Signal<Unsigned>() { InitialValue = Unsigned.FromUInt(0, AddrWidth) }; _sinData = new Signal<SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _cosData = new Signal<SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _sinLUT = new VSignal<SFix>((1 << lutWidth) + 2, _ => new Signal<SFix>() { InitialValue = SFix.FromDouble(Math.Sin(Math.PI * 0.5 * _ / (double)(1 << lutWidth)), 2, yFracWidth) }); _sinFlipSignIn = new SLVSignal(1) { InitialValue = "0" }; _cosFlipSignIn = new SLVSignal(1) { InitialValue = "0" }; _sinFlipSignOut = new SLVSignal(1) { InitialValue = "0" }; _cosFlipSignOut = new SLVSignal(1) { InitialValue = "0" }; _mirror = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << (xFracWidth + 1), xFracWidth - LUTWidth); _mirror2 = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << xFracWidth, xFracWidth - LUTWidth); _sinPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth); Bind(() => { _sinPipe.Clk = Clk; _sinPipe.Din = _sinIn; _sinPipe.Dout = _sinOut; }); _cosPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth); Bind(() => { _cosPipe.Clk = Clk; _cosPipe.Din = _cosIn; _cosPipe.Dout = _cosOut; }); _sinFlipSignPipe = new RegPipe(2, 1); Bind(() => { _sinFlipSignPipe.Clk = Clk; _sinFlipSignPipe.Din = _sinFlipSignIn; _sinFlipSignPipe.Dout = _sinFlipSignOut; }); _cosFlipSignPipe = new RegPipe(2, 1); Bind(() => { _cosFlipSignPipe.Clk = Clk; _cosFlipSignPipe.Din = _cosFlipSignIn; _cosFlipSignPipe.Dout = _cosFlipSignOut; }); _sinUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0); Bind(() => { _sinUnit.Clk = Clk; _sinUnit.X = _x; _sinUnit.Y = _sinRaw; _sinUnit.Addr = _sinAddr; _sinUnit.Data = _sinData; }); _cosUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0); Bind(() => { _cosUnit.Clk = Clk; _cosUnit.X = _xq; _cosUnit.Y = _cosRaw; _cosUnit.Addr = _cosAddr; _cosUnit.Data = _cosData; }); TASite = new TransactionSite(this); }
/// <summary> /// Constructs a new instance /// </summary> /// <param name="xIntWidth">integer width of operand</param> /// <param name="xFracWidth">fractional width of operand</param> /// <param name="yIntWidth">integer width of result</param> /// <param name="yFracWidth">fractional width of result</param> /// <param name="pipeStages">desired computation-only latency</param> public LERPUnit(int xIntWidth, int xFracWidth, int yIntWidth, int yFracWidth, int pipeStages) { Contract.Requires<ArgumentOutOfRangeException>(xIntWidth > 0, "xIntWidth must be positive."); Contract.Requires<ArgumentOutOfRangeException>(xFracWidth >= 0, "xFracWidth must be non-negative."); Contract.Requires<ArgumentOutOfRangeException>(yIntWidth + yFracWidth > 0, "total bit-width of result must be positive"); Contract.Requires<ArgumentOutOfRangeException>(pipeStages >= 0, "pipeStages must be non-negative."); Contract.Requires<ArgumentOutOfRangeException>(xFracWidth > 0 || pipeStages == 0, "xFracWidth == 0 is a degenerate case (lookup-only). No additional pipeline stages allowed."); PipeStages = pipeStages; XIntWidth = xIntWidth; XFracWidth = xFracWidth; YIntWidth = yIntWidth; YFracWidth = yFracWidth; AddrWidth = xIntWidth; _yIn = new SLVSignal(yIntWidth + yFracWidth); _yOut = new SLVSignal(yIntWidth + yFracWidth); _yPipe = new RegPipe(pipeStages, yIntWidth + yFracWidth); Bind(() => { _yPipe.Clk = Clk; _yPipe.Din = _yIn; _yPipe.Dout = _yOut; }); }
protected override void PreInitialize() { _t = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; PINC = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; POFF = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; PH = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; PhaseIn = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; phase3 = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; Dat_in = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; Dat_outOff = new SLVSignal(PhaseWidth) { InitialValue = StdLogicVector._0s(PhaseWidth) }; _RegPipe = new RegPipe(Latency, PhaseWidth) { Clk = CLK, Din = Dat_in, Dout = Dat_outOff, }; }
/// <summary> /// Constructs a new instance /// </summary> /// <param name="lutWidth">resolution of data table</param> /// <param name="xFracWidth">fractional width of operand</param> /// <param name="yFracWidth">fractional width of result</param> /// <param name="pipeStages">additional pipeline stages for interpolation computation</param> public SinCosLUTCore(int lutWidth, int xFracWidth, int yFracWidth, int pipeStages) { PipeStages = pipeStages; XIntWidth = 2; XFracWidth = xFracWidth; YIntWidth = 2; YFracWidth = yFracWidth; DIntWidth = 2; DFracWidth = yFracWidth; LUTWidth = lutWidth; _x = new Signal <UFix>() { InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1) }; _xq = new Signal <UFix>() { InitialValue = UFix.FromDouble(0.0, LUTWidth + 1, XFracWidth - LUTWidth - 1) }; _sinRaw = new Signal <SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _cosRaw = new Signal <SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _sinIn = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _cosIn = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _sinOut = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; _cosOut = new SLVSignal(YIntWidth + YFracWidth) { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth).SLVValue }; AddrWidth = lutWidth + 1; _sinAddr = new Signal <Unsigned>() { InitialValue = Unsigned.FromUInt(0, AddrWidth) }; _cosAddr = new Signal <Unsigned>() { InitialValue = Unsigned.FromUInt(0, AddrWidth) }; _sinData = new Signal <SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _cosData = new Signal <SFix>() { InitialValue = SFix.FromDouble(0.0, YIntWidth, YFracWidth) }; _sinLUT = new VSignal <SFix>((1 << lutWidth) + 2, _ => new Signal <SFix>() { InitialValue = SFix.FromDouble(Math.Sin(Math.PI * 0.5 * _ / (double)(1 << lutWidth)), 2, yFracWidth) }); _sinFlipSignIn = new SLVSignal(1) { InitialValue = "0" }; _cosFlipSignIn = new SLVSignal(1) { InitialValue = "0" }; _sinFlipSignOut = new SLVSignal(1) { InitialValue = "0" }; _cosFlipSignOut = new SLVSignal(1) { InitialValue = "0" }; _mirror = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << (xFracWidth + 1), xFracWidth - LUTWidth); _mirror2 = UFix.FromUnsigned(Unsigned.One.Resize(XFracWidth + 2) << xFracWidth, xFracWidth - LUTWidth); _sinPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth); Bind(() => { _sinPipe.Clk = Clk; _sinPipe.Din = _sinIn; _sinPipe.Dout = _sinOut; }); _cosPipe = new RegPipe(pipeStages, YIntWidth + YFracWidth); Bind(() => { _cosPipe.Clk = Clk; _cosPipe.Din = _cosIn; _cosPipe.Dout = _cosOut; }); _sinFlipSignPipe = new RegPipe(2, 1); Bind(() => { _sinFlipSignPipe.Clk = Clk; _sinFlipSignPipe.Din = _sinFlipSignIn; _sinFlipSignPipe.Dout = _sinFlipSignOut; }); _cosFlipSignPipe = new RegPipe(2, 1); Bind(() => { _cosFlipSignPipe.Clk = Clk; _cosFlipSignPipe.Din = _cosFlipSignIn; _cosFlipSignPipe.Dout = _cosFlipSignOut; }); _sinUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0); Bind(() => { _sinUnit.Clk = Clk; _sinUnit.X = _x; _sinUnit.Y = _sinRaw; _sinUnit.Addr = _sinAddr; _sinUnit.Data = _sinData; }); _cosUnit = new LERPUnit(lutWidth + 1, xFracWidth - 1 - lutWidth, YIntWidth, yFracWidth, 0); Bind(() => { _cosUnit.Clk = Clk; _cosUnit.X = _xq; _cosUnit.Y = _cosRaw; _cosUnit.Addr = _cosAddr; _cosUnit.Data = _cosData; }); TASite = new TransactionSite(this); }
protected override void PreInitialize() { _rin = new SLVSignal(ResultWidth); _rout = new SLVSignal(ResultWidth); _rpipe = new RegPipe(Latency, ResultWidth); Bind(() => { _rpipe.Clk = Clk; _rpipe.Din = _rin; _rpipe.Dout = _rout; }); }
protected override void PreInitialize() { int width = OutputWidthHigh - OutputWidthLow + 1; _pipeIn = new SLVSignal(width); if (PipeStages > 0) { _outPipe = new RegPipe(PipeStages, width); Bind(() => { _outPipe.Clk = CLK; _outPipe.Din = _pipeIn; _outPipe.Dout = P; }); } else { AddProcess(DrivePIm, _pipeIn); } }