URL
https://opencores.org/ocsvn/cryptosorter/cryptosorter/trunk
Subversion Repositories cryptosorter
[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [PLBMaster/] [PLBMasterMagic.bsv] - Rev 6
Compare with Previous | Blame | View Log
/*Copyright (c) 2007 MITPermission is hereby granted, free of charge, to any personobtaining a copy of this software and associated documentationfiles (the "Software"), to deal in the Software withoutrestriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the followingconditions:The above copyright notice and this permission notice shall beincluded 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 WARRANTIESOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Author: Kermin Fleming*/// Global Importsimport GetPut::*;import FIFO::*;import RegFile::*;// Project Imports`include "Common.bsv"import PLBMasterWires::*;typedef enum{Test,Sleep,Finish} TestStatederiving(Bits, Eq);(* synthesize *)module mkPLBMasterMagic (PLBMaster);// state for the actual magic memory hardwareFIFO#(ComplexWord) wordInfifo <- mkFIFO();FIFO#(ComplexWord) wordOutfifo <- mkFIFO();FIFO#(PLBMasterCommand) plbMasterCommandInfifo <- mkFIFO();RegFile#(Bit#(20), ComplexWord) matrixA <- mkRegFileFullLoad("matrixA.hex");RegFile#(Bit#(20), ComplexWord) matrixB <- mkRegFileFullLoad("matrixB.hex");RegFile#(Bit#(20), ComplexWord) matrixC <- mkRegFileFull();RegFile#(Bit#(20), ComplexWord) scratch <- mkRegFileFull();Reg#(Bit#(LogBlockElements)) elementCounter <- mkReg(0);Reg#(Bit#(LogBlockSize)) rowCounter <- mkReg(0); // 0 -> blocksizeReg#(Bit#(LogRowSize)) rowOffset <- mkReg(0);Reg#(BlockAddr) addressOffset <- mkReg(0);// State for running the golden test loopRegFile#(Bit#(20), ComplexWord) golden <- mkRegFileFullLoad("golden.hex");Reg#(Bit#(32)) goldenElementCounter <- mkReg(0);Reg#(Bit#(64)) totalTicks <- mkReg(0);rule tick(True);totalTicks <= totalTicks +1;endrulerule rowSize(plbMasterCommandInfifo.first() matches tagged RowSize .rs);debug(plbMasterDebug, $display("PLBMaster: processing RowSize command %d", rs));rowOffset <= rs;plbMasterCommandInfifo.deq();endrulerule loadPage(plbMasterCommandInfifo.first() matches tagged LoadPage .ba);elementCounter <= elementCounter + 1;if(elementCounter == 0)begindebug(plbMasterDebug, $display("PLBMaster: processing LoadPage command"));endif(elementCounter + 1 == 0)begindebug(plbMasterDebug, $display("PLBMaster: finished LoadPage command"));addressOffset <= 0;rowCounter <= 0;plbMasterCommandInfifo.deq();endelse if(rowCounter + 1 == 0)begin //When we get to the end of a row, we need to reset by//shifting the Address Offset to 1 row higher =rowCounter <= 0;addressOffset <= addressOffset + 1 - unpack(fromInteger(1*valueof(BlockSize))) + (1 << rowOffset);endelsebeginaddressOffset <= addressOffset + 1;rowCounter <= rowCounter + 1;endBlockAddr addr = ba + addressOffset;// Now that we're done with calculating the address,// we can case out our memory space//case (addr[23:22])// 2'b00: begin $display("PLB: reading matA[%h] => %h" ,addr[21:2], matrixA.sub(addr[21:2])); end// 2'b01: begin $display("PLB: reading matB[%h] => %h" ,addr[21:2], matrixB.sub(addr[21:2])); end// 2'b10: begin $display("PLB: reading matC[%h] => %h" ,addr[21:2], matrixC.sub(addr[21:2])); end// 2'b11: begin $display("PLB: reading scratch[%h] => %h",addr[21:2], scratch.sub(addr[21:2])); end//endcasecase (addr[21:20])2'b00: wordOutfifo.enq(matrixA.sub(addr[19:0]));2'b01: wordOutfifo.enq(matrixB.sub(addr[19:0]));2'b10: wordOutfifo.enq(matrixC.sub(addr[19:0]));2'b11: wordOutfifo.enq(scratch.sub(addr[19:0]));endcaseendrulerule storePage(plbMasterCommandInfifo.first() matches tagged StorePage .ba);elementCounter <= elementCounter + 1;if(elementCounter == 0)begindebug(plbMasterDebug, $display("PLBMaster: processing StorePage command"));endif(elementCounter + 1 == 0)begindebug(plbMasterDebug, $display("PLBMaster: finished StorePage command"));addressOffset <= 0;rowCounter <= 0;plbMasterCommandInfifo.deq();endelse if(rowCounter + 1 == 0)beginaddressOffset <= addressOffset + 1 - unpack(fromInteger(valueof(BlockSize))) + (1 << rowOffset);rowCounter <= 0;endelsebeginaddressOffset <= addressOffset + 1;rowCounter <= rowCounter + 1;endBlockAddr addr = ba + addressOffset;// Now that we're done with calculating the address,// we can case out our memory spacecase (addr[21:20])2'b00: begindebug(plbMasterDebug,$display("PLB: writing to matA %h",addr[19:0]));matrixA.upd(addr[19:0],wordInfifo.first());end2'b01: begindebug(plbMasterDebug,$display("PLB: writing to matB %h",addr[19:0]));matrixB.upd(addr[19:0],wordInfifo.first());end2'b10: begindebug(plbMasterDebug,$display("PLB: writing to matC %h",addr[19:0]));matrixC.upd(addr[19:0],wordInfifo.first());let oldval = matrixC.sub(addr[19:0]);let goldenval = golden.sub(addr[19:0]);if ((goldenval != oldval) && (goldenval == wordInfifo.first())) // a new correct valbegingoldenElementCounter <= goldenElementCounter +1;if (truncate(goldenElementCounter) == 16'hFFFF) // time to announce$display("Correct Value Count: %d @ %d", goldenElementCounter+1,totalTicks);if (goldenElementCounter + 1 == (1 << (rowOffset<<1)))begin$display("PASSED @ %d", totalTicks);$finish;endendend2'b11: begindebug(plbMasterDebug,$display("PLB: writing to scratch %h",addr[19:0]));scratch.upd(addr[19:0],wordInfifo.first());endendcasewordInfifo.deq();endrulerule debugRule (True);case (plbMasterCommandInfifo.first()) matchestagged LoadPage .i: noAction;tagged StorePage .i: noAction;tagged RowSize .sz: noAction;default:$display("PLBMaster: illegal command: %h", plbMasterCommandInfifo.first());endcaseendruleinterface Put wordInput = interface Put;method Action put(x);wordInfifo.enq(x);//$display("PLB: got val %h", x);endmethodendinterface;interface Get wordOutput = interface Get;method get();actionvalue//$display("PLB: sending val %h", wordOutfifo.first());wordOutfifo.deq();return wordOutfifo.first();endactionvalueendmethodendinterface;interface Put plbMasterCommandInput = fifoToPut(plbMasterCommandInfifo);interface PLBMasterWires plbMasterWires = ?;endmodule
