OpenCores
URL https://opencores.org/ocsvn/cryptosorter/cryptosorter/trunk

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [xup/] [PLBMaster/] [PLBMaster_backupPPC.bsv] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
/*
2
Copyright (c) 2007 MIT
3
 
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
11
conditions:
12
 
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
 
25
Author: Kermin Fleming
26
*/
27
 
28
// Global Imports
29
import GetPut::*;
30
import FIFO::*;
31
import RegFile::*;
32
import BRAMInitiatorWires::*;
33
import RegFile::*;
34
import FIFOF::*;
35
 
36
import BRAM::*;
37
// Project Imports
38
import Types::*;
39
import Interfaces::*;
40
import Parameters::*;
41
import DebugFlags::*;
42
 
43
import BRAMInitiator::*;
44
import PLBMasterWires::*;
45
import StmtFSM::*;
46
 
47
(* synthesize *)
48
module mkPLB_backupPPC(BRAMInitiatorWires#(Bit#(14)));
49
 
50
  RegFile#(Bit#(20), Bit#(32))  matrixA <- mkRegFileFullLoad("matrixA.hex");
51
  RegFile#(Bit#(20), Bit#(32))  matrixB <- mkRegFileFullLoad("matrixB.hex");
52
  RegFile#(Bit#(20), Bit#(32))  matrixC <- mkRegFileFull();
53
  RegFile#(Bit#(20), Bit#(32))  scratch <- mkRegFileFull();
54
  RegFile#(Bit#(20), Bit#(32))  golden  <- mkRegFileFullLoad("golden.hex");
55
 
56
  Reg#(Bit#(32))      goldenElementCounter <- mkReg(0);
57
 
58
  RegFile#(Bit#(16), Bit#(64))     prog <- mkRegFileFullLoad("program.hex");
59
  Reg#(Bit#(16))               prog_idx <- mkReg(0);
60
 
61
 
62
  //State
63
 
64
  BRAMInitiator#(Bit#(14)) bramInit <- mkBRAMInitiator;
65
  let bram = bramInit.bram;
66
 
67
  //BRAM#(Bit#(14), Bit#(32))   bram <- mkBRAM_Full();
68
 
69
  FIFOF#(Bit#(32))             outQ <- mkFIFOF();
70
  FIFO#(Bit#(32))               inQ <- mkFIFO();
71
  FIFO#(Bit#(64))          commandQ <- mkFIFO();
72
  Reg#(Bit#(30))           baseAddr <- mkRegU;
73
 
74
  let minWritePtr  =   0;
75
  let maxWritePtr  =  129*2-1;
76
 
77
  let minReadPtr   =  129*2;
78
  let maxReadPtr   =  129*4-1;
79
 
80
  let burstSize    =  128;
81
 
82
  Reg#(Bit#(14))    readPtr <- mkReg(minReadPtr);
83
  Reg#(Bit#(14))   writePtr <- mkReg(minWritePtr);
84
 
85
 
86
 
87
 
88
  let incWritePtr  = (writePtr == maxWritePtr) ? minWritePtr : (writePtr + 1);
89
  let incReadPtr   = (readPtr == maxReadPtr) ? minReadPtr : (readPtr + 1);
90
 
91
  let ready = True;
92
  let debugF = debug(False);
93
 
94
 
95
 
96
  Reg#(Bit#(10))      count <- mkReg(0);
97
 
98
  Reg#(Bit#(32))      value <- mkReg(0);
99
 
100
  Reg#(Bit#(64)) totalTicks <- mkReg(0);
101
  Reg#(Bit#(32))  rowOffset <- mkReg(0);  // stored in terms of words
102
 
103
 
104
  function Action readAddr(addr);
105
    case (addr[21:20])
106
      2'b00:  return (matrixA.sub(addr[19:0]));
107
      2'b01:  return (matrixB.sub(addr[19:0]));
108
      2'b10:  return (matrixC.sub(addr[19:0]));
109
      2'b11:  return (scratch.sub(addr[19:0]));
110
    endcase
111
  endfunction
112
 
113
  function Action writeAddr(addr,val);
114
    action
115
      case (addr[21:20])
116
        2'b00:  begin
117
                  debugF($display("PLB: writing to matA %h",addr[19:0]));
118
                  matrixA.upd(addr[19:0],val);
119
                end
120
        2'b01:  begin
121
                  debugF($display("PLB: writing to matB %h",addr[19:0]));
122
                  matrixB.upd(addr[19:0],val);
123
                end
124
        2'b10:  begin
125
                  debugF($display("PLB: writing to matC %h",addr[19:0]));
126
                  matrixC.upd(addr[19:0],val);
127
                  let oldval    = matrixC.sub(addr[19:0]);
128
                  let goldenval = golden.sub(addr[19:0]);
129
 
130
                if ((goldenval != oldval) && (goldenval == val)) // a new correct val
131
                  begin
132
                    goldenElementCounter <= goldenElementCounter +1;
133
                    if (truncate(goldenElementCounter) == 16'hFFFF) // time to announce
134
                      $display("Correct Value Count: %d @ %d", goldenElementCounter+1,totalTicks);
135
                    if (goldenElementCounter + 1 ==   (rowOffset * rowOffset))
136
                      begin
137
                        $display("PASSED @ %d", totalTicks);
138
                        $finish;
139
                      end
140
                  end
141
              end
142
      2'b11:  begin
143
                debugF($display("PLB: writing to scratch %h",addr[19:0]));
144
                scratch.upd(addr[19:0],val);
145
              end
146
      endcase
147
    endaction
148
  endfunction
149
 
150
 
151
  ///////////////////////////////////////////////////////////
152
  // In goes to MEM, Out goes back to FPGA
153
  ///////////////////////////////////////////////////////////
154
 
155
  Stmt doReadStmt =
156
    seq
157
      bram.read_req(readPtr);
158
      action
159
        let v <- bram.read_resp();
160
        value <= v;
161
        count <= 0;
162
      endaction
163
      if (value != 0)
164
        seq
165
          while(count < burstSize)
166
            seq
167
              action
168
                readPtr <= incReadPtr;
169
                count <= count + 1;
170
                let v <- bram.read_resp();
171
                writeAddr(baseAddr+zeroExtend(count), v);
172
                if (count 
173
                  bram.read_req(readPtr+1); //
174
                if (count == burstSize)
175
                  bram.write(readPtr - burstSize, 0); // take
176
              endaction
177
            endseq
178
        endseq
179
  endseq;
180
 
181
  FSM doRead <- mkFSM(doReadStmt);
182
 
183
  Stmt doWriteStmt =
184
    seq
185
      bram.read_req(writePtr);
186
      action
187
        let v <- bram.read_resp();
188
        value <= v;
189
        count <= 0;
190
      endaction
191
      if (value == 0)
192
        seq
193
          while(count < burstSize)
194
            seq
195
              action
196
                writePtr <= incWritePtr;
197
                count <= count + 1;
198
                if (count 
199
                  begin
200
                    let val = readAddr(baseAddr+zeroExtend(count));
201
                    bram.write(writePtr+1, val); //
202
                  end
203
                if (count == burstSize)
204
                  bram.write(writePtr - burstSize, 32'hFFFFFFFF); // take
205
              endaction
206
            endseq
207
        endseq
208
      commandQ.deq();
209
    endseq;
210
 
211
  FSM doWrite <- mkFSM(doWriteStmt);
212
 
213
  rule doStuff(doRead.done && doWrite.done);
214
    let inst = unpack(truncate(commandQ.first));
215
 
216
    let mload  = translateLoad(inst);
217
    let mstore = translateStore(inst);
218
    let mrow   = translateRowSize(inst);
219
 
220
    commandQ.deq();
221
 
222
    if (isJust(mload))
223
      begin
224
        baseAddr <= unJust(mload);
225
        doRead.start();
226
      end
227
    else if (isJust(mstore))
228
      begin
229
        baseAddr <= unJust(mstore);
230
        doWrite.start();
231
      end
232
    else if (isJust(mrow))
233
      begin
234
        rowOffset <= zeroExtend(unJust(mrow));
235
      end
236
  endrule
237
 
238
  rule tick(True);
239
    totalTicks <= totalTicks +1;
240
  endrule
241
 
242
  rule doProgRead(prog.sub(prog_idx) != 64'hAAAA_AAAA_AAAA_AAAA);
243
    let x = prog.sub(prog_idx);
244
    commandQ.enq(x);
245
    prog_idx <= prog_idx + 1;
246
  endrule
247
 
248
  return (bramInit.bramInitiatorWires);
249
endmodule
250
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.