📄 cordic.bsv
字号:
return CosSinPair{cos: fxptSignExtend(cosV), sin: fxptSignExtend(sinV)}; endfunction // CORDICData// translate the cordic data into result vector mode// output range: (-0.5,0.5]function FixedPoint#(aisz,afsz) getVectorModeOutData(CORDICData#(vfsz,afsz) cData) provisos (Add#(xxA,1,aisz), Add#(xxA,TAdd#(1,afsz),TAdd#(aisz,afsz)), Arith#(FixedPoint#(1,afsz))); let angle = cData.beta; Tuple2#(FixedPoint#(1,afsz),FixedPoint#(1,afsz)) tempTuple = case (cData.quad) 2'b00 : tuple2(0, angle); 2'b01 : tuple2(((angle < 0) ? fromRational(-1,2) : fromRational(1,2)), negate(angle)); 2'b10 : tuple2(fromRational(1,4), negate(angle)); 2'b11 : tuple2(fromRational(-1,4), angle); endcase; FixedPoint#(1,afsz) result = tpl_1(tempTuple) + tpl_2(tempTuple); return fxptSignExtend(result);endfunction // CORDICData// translate the cordic data into resultfunction CORDICData#(vfsz,afsz) getCORDICOutData(CORDICData#(vfsz,afsz) cData) provisos (Add#(1,TAdd#(1,vfsz),TAdd#(2,vfsz)), Arith#(FixedPoint#(1,vfsz)), Arith#(FixedPoint#(1,afsz)), Literal#(FixedPoint#(2,vfsz))); CosSinPair#(1,vfsz) cosSinPair = getRotateModeOutData(cData); FixedPoint#(2,vfsz) cosV = fxptSignExtend(cosSinPair.cos); FixedPoint#(2,vfsz) sinV = fxptSignExtend(cosSinPair.sin); let atan = getVectorModeOutData(cData); return CORDICData{x:cosV, y:sinV, beta:atan, mode:cData.mode, quad:cData.quad};endfunction // CORDICData// end of auxiliary functions// input: angle (in terms of no of full circle, e.g. pi = 1/2)// steps (no of iterations executed, max 16)// output: tuple2(cos(angle), sin(angle))function CosSinPair#(ni, nf) getCosSinPair(FixedPoint#(hi, hf) angle, Integer steps) provisos (Add#(xxA,1,hi), Add#(2,hfl2,hf), Add#(3,hfl2,TAdd#(1,hf)), Add#(hi,hf,TAdd#(hi,hf)), Literal#(FixedPoint#(2,nf)), Add#(1,TAdd#(1,nf),TAdd#(2,nf)), Add#(xxB,1,ni), Add#(xxB,TAdd#(1,nf),TAdd#(ni,nf)), Arith#(FixedPoint#(1,nf)), Literal#(FixedPoint#(2,nf)), Arith#(FixedPoint#(1,hf)), Arith#(FixedPoint#(2,nf))); CORDICData#(nf,hf) inData = getRotateModeInData(angle); CORDICData#(nf,hf) outData = execute(inData, steps); CosSinPair#(ni,nf) result = getRotateModeOutData(outData); return CosSinPair{cos: result.cos, sin: result.sin};endfunction // CosSinPair// input: angle (in terms of no of full circle, e.g. pi = 1/2)// steps (no of iterations executed, max 16)// output: cos(angle)function FixedPoint#(ni, nf) cos(FixedPoint#(hi, hf) angle, Integer steps) provisos (Add#(xxA,1,hi), Add#(2,hfl2,hf), Add#(3,hfl2,TAdd#(1,hf)), Add#(hi,hf,TAdd#(hi,hf)), Literal#(FixedPoint#(2,nf)), Add#(1,TAdd#(1,nf),TAdd#(2,nf)), Add#(xxB,1,ni), Add#(xxB,TAdd#(1,nf),TAdd#(ni,nf)), Arith#(FixedPoint#(1,nf)), Literal#(FixedPoint#(2,nf)), Arith#(FixedPoint#(1,hf)), Arith#(FixedPoint#(2,nf))); let result = getCosSinPair(angle, steps); return result.cos;endfunction // FixedPoint// input: angle (in terms of no of full circle, e.g. pi = 1/2)// steps (no of iterations executed, max 16)// output: sin(angle)function FixedPoint#(ni, nf) sin(FixedPoint#(hi, hf) angle, Integer precision) provisos (Add#(xxA,1,hi), Add#(2,hfl2,hf), Add#(3,hfl2,TAdd#(1,hf)), Add#(hi,hf,TAdd#(hi,hf)), Literal#(FixedPoint#(2,nf)), Add#(1,TAdd#(1,nf),TAdd#(2,nf)), Add#(xxB,1,ni), Add#(xxB,TAdd#(1,nf),TAdd#(ni,nf)), Arith#(FixedPoint#(1,nf)), Literal#(FixedPoint#(2,nf)), Arith#(FixedPoint#(1,hf)), Arith#(FixedPoint#(2,nf))); let result = getCosSinPair(angle, precision); return result.sin;endfunction // FixedPoint// input: x, y (coord value for x, y axes)// precision (no of iterations executed, max 16)// output: atan(y/x) (in terms of no of full circle, e.g. pi = 1/2) function FixedPoint#(hi, hf) atan(FixedPoint#(ni, nf) x, FixedPoint#(ni,nf) y, Integer steps) provisos (Add#(xxA, nf, rf), Add#(xxA, TAdd#(ni,nf), TAdd#(ni,rf)), Add#(xxA, 1, ni), Add#(xxB, TAdd#(1,rf), TAdd#(ni,rf)), Add#(xxC, TAdd#(1,hf), TAdd#(hi,hf)), Add#(xxC, 1, hi), Add#(1,TAdd#(1,rf),TAdd#(2,rf)), Arith#(FixedPoint#(1,rf)), Arith#(FixedPoint#(1,hf)), Arith#(FixedPoint#(2,rf)), Literal#(FixedPoint#(1,hf))); CORDICData#(rf,hf) inData = getVectorModeInData(x,y); CORDICData#(rf,hf) outData = execute(inData, steps); FixedPoint#(1,hf) result = getVectorModeOutData(outData); return fxptSignExtend(result);endfunction // FixedPoint // End of Functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Begin of Modulesmodule [Module] mkCORDIC#(Module#(Pipeline#(CORDICData#(vfsz,afsz))) mkP) (CORDIC#(vfsz,afsz)); Pipeline#(CORDICData#(vfsz,afsz)) p <- mkP(); method Action putCORDICData(CORDICData#(vfsz,afsz) x); begin p.put(x); end endmethod // output to cyclic extend queue method method ActionValue#(CORDICData#(vfsz,afsz)) getCORDICData(); begin let result <- p.get(); return result; end endmethodendmodule// for making cordic pipelinemodule [Module] mkCORDIC_Pipe#(Integer numStages, Integer step)(CORDIC#(vfsz,afsz)) provisos (Arith#(FixedPoint#(2, vfsz)), Add#(1, afsz, TAdd#(1, afsz)), Arith#(FixedPoint#(1, vfsz)), Add#(3, afszl2, TAdd#(1, afsz)), Add#(2, afszl2, afsz), Add#(1, TAdd#(1, vfsz), TAdd#(2, vfsz))); CORDIC#(vfsz,afsz) cordic <- mkCORDIC(mkPipeline_Sync(numStages, step, executeStage)); method Action putCORDICData(CORDICData#(vfsz,afsz) x); cordic.putCORDICData(getCORDICInData(x)); endmethod method ActionValue#(CORDICData#(vfsz,afsz)) getCORDICData(); let outData <- cordic.getCORDICData(); return getCORDICOutData(outData); endmethodendmodule// for making CosAndSin pipelinemodule [Module] mkCosAndSin_Pipe#(Integer numStages, Integer step)(CosAndSin#(visz, vfsz, aisz, afsz)) provisos (Arith#(FixedPoint#(2, vfsz)), Arith#(FixedPoint#(1, afsz)), Add#(xxA, 1, aisz), Add#(2, afszl2, afsz), Add#(3, afszl2, TAdd#(1, afsz)), Add#(aisz, afsz, TAdd#(aisz, afsz)), Add#(1, TAdd#(1, vfsz), TAdd#(2, vfsz)), Add#(xxB, 1, visz), Add#(xxB, TAdd#(1, vfsz), TAdd#(visz, vfsz)), Arith#(FixedPoint#(1, vfsz))); CORDIC#(vfsz,afsz) cordic <- mkCORDIC(mkPipeline_Sync(numStages, step, executeStage)); method Action putAngle(FixedPoint#(aisz,afsz) beta); cordic.putCORDICData(getRotateModeInData(beta)); endmethod method ActionValue#(CosSinPair#(visz,vfsz)) getCosSinPair(); let outData <- cordic.getCORDICData(); return getRotateModeOutData(outData); endmethodendmodule// for making ArcTan pipelinemodule [Module] mkArcTan_Pipe#(Integer numStages, Integer step)(ArcTan#(visz,vfsz,aisz,afsz)) provisos (Add#(xxA, vfsz, rf), Add#(xxA, TAdd#(visz,vfsz), TAdd#(visz,rf)), Add#(xxA, 1, visz), Add#(xxB, TAdd#(1,rf), TAdd#(visz,rf)), Add#(xxC, TAdd#(1,afsz), TAdd#(aisz,afsz)), Add#(xxC, 1, aisz), Add#(1,TAdd#(1,rf),TAdd#(2,rf)), Arith#(FixedPoint#(1,rf)), Arith#(FixedPoint#(1,afsz)), Arith#(FixedPoint#(2,rf)), Literal#(FixedPoint#(1,afsz))); CORDIC#(rf,afsz) cordic <- mkCORDIC(mkPipeline_Sync(numStages, step, executeStage)); method Action putXY(FixedPoint#(visz,vfsz) x, FixedPoint#(visz,vfsz) y); CORDICData#(rf,afsz) inData = getVectorModeInData(x,y); cordic.putCORDICData(inData); endmethod method ActionValue#(FixedPoint#(aisz,afsz)) getArcTan(); let outData <- cordic.getCORDICData(); return getVectorModeOutData(outData); endmethodendmodule // mkArcTan_Pipe// End of Modules/////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -