// The MIT License // Copyright (c) 2006-2007 Massachusetts Institute of Technology // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. //********************************************************************** // nC Calculator implementation //---------------------------------------------------------------------- // // package mkCalc_nC; import H264Types::*; import ICalc_nC::*; import FIFO::*; import Connectable::*; import GetPut::*; import ClientServer::*; (* synthesize *) module mkCalc_nC( Calc_nC ); Reg#(Bit#(PicWidthSz)) picWidth <- mkReg(maxPicWidthInMB); Reg#(Bit#(PicAreaSz)) firstMb <- mkReg(0); Reg#(Bit#(PicAreaSz)) currMb <- mkReg(0); Reg#(Bit#(PicAreaSz)) currMbHor <- mkReg(0);//horizontal position of currMb Reg#(Bit#(1)) waiting <- mkReg(0); Reg#(Bit#(1)) reqCount <- mkReg(0); Reg#(Bit#(2)) respCount <- mkReg(0); Reg#(Bit#(1)) ipcmCount <- mkReg(0); Reg#(Bit#(PicAreaSz)) pskipCount <- mkReg(0); Reg#(Bit#(20)) leftVal <- mkReg(0); Reg#(Bit#(20)) topVal <- mkReg(0); Reg#(Bit#(10)) leftValChroma0 <- mkReg(0); Reg#(Bit#(10)) topValChroma0 <- mkReg(0); Reg#(Bit#(10)) leftValChroma1 <- mkReg(0); Reg#(Bit#(10)) topValChroma1 <- mkReg(0); FIFO#(MemReq#(TAdd#(PicWidthSz,1),20)) memReqQ <- mkFIFO; FIFO#(MemResp#(20)) memRespQ <- mkFIFO; Bit#(1) bit1 = 1; Bit#(1) bit0 = 0; rule currMbHorUpdate( !(currMbHor> 3) >= temp) currMbHor <= currMbHor - (temp << 3); else currMbHor <= currMbHor - temp; endrule rule sendReq ( waiting == 1 && reqCount > 0 ); Bit#(PicWidthSz) temp2 = truncate(currMbHor); Bit#(TAdd#(PicWidthSz,1)) temp = {bit1,temp2}; memReqQ.enq(tagged LoadReq temp ); reqCount <= reqCount-1; endrule rule receiveResp ( waiting == 1 &&& respCount > 0 &&& memRespQ.first() matches tagged LoadResp .data ); if( respCount == 2 ) topVal <= data; else begin topValChroma0 <= data[9:0]; topValChroma1 <= data[19:10]; waiting <= 0; end memRespQ.deq(); respCount <= respCount - 1; endrule rule ipcmReq ( waiting == 1 && ipcmCount > 0 ); currMb <= currMb+1; currMbHor <= currMbHor+1; Bit#(PicWidthSz) temp2 = truncate(currMbHor); Bit#(TAdd#(PicWidthSz,1)) temp = {bit1,temp2}; memReqQ.enq(tagged StoreReq {addr:temp,data:20'b10000100001000010000} ); ipcmCount <= 0; waiting <= 0; endrule rule pskipReq ( waiting == 1 && pskipCount > 0 && currMbHor> 1); else if(templeft!=6'b011111) return truncate(templeft); else if(temptop!=6'b011111) return truncate(temptop); else return 0; endmethod method Bit#(5) nCcalc_chroma( Bit#(3) microBlockNum ) if( waiting == 0 && currMbHor> 1); else if(templeft!=6'b011111) return truncate(templeft); else if(temptop!=6'b011111) return truncate(temptop); else return 0; endmethod method Action nNupdate_luma( Bit#(4) microBlockNum, Bit#(5) totalCoeff ) if( waiting == 0 && currMbHor 0) begin waiting <= 1; pskipCount <= (inmb_skip_run << 1)-1; Bit#(PicWidthSz) temp2 = truncate(currMbHor); Bit#(TAdd#(PicWidthSz,1)) temp = {bit0,temp2}; memReqQ.enq(tagged StoreReq {addr:temp,data:20'b00000000000000000000} ); leftVal <= 0; leftValChroma0 <= 10'b0000000000; leftValChroma1 <= 10'b0000000000; end endmethod method Action nNupdate_ipcm() if( waiting == 0 && currMbHor