Mercurial > pygar
view modules/bluespec/Pygar/lab4/oSFIFO.bsv @ 53:2991344775f8 pygar svn.54
[svn r54] mixer integrated
author | punk |
---|---|
date | Sun, 09 May 2010 10:58:40 -0400 |
parents | 74716e9a81cc |
children |
line wrap: on
line source
2 import FIFO::*;3 import ConfigReg::*;4 import RWire::*;6 import List::*;7 import Monad::*;9 interface SFIFO#(type alpha_T, type search_T);10 method Action enq(alpha_T x);11 method Action deq();12 method alpha_T first();13 method Action clear();14 method Bool find(search_T x);15 method Bool find2(search_T x);16 method Bool notEmpty();17 method Bool notFull();18 endinterface20 module mkSFIFO#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))21 provisos22 (Bits#(alpha_T,asz));24 Reg#(alpha_T) f0 <- mkConfigRegU;25 Reg#(alpha_T) f1 <- mkConfigRegU;27 Reg#(Bool) vf0 <- mkConfigReg(False);28 Reg#(Bool) vf1 <- mkConfigReg(False);30 PulseWire edge1 <- mkPulseWire();32 method Action enq(alpha_T x) if (!(vf0 && vf1));33 if (edge1 || !vf0)//empty or we're dequeueing34 begin35 vf0 <= True; //True36 vf1 <= False;37 f0 <= x;38 end39 else // !vf140 begin41 vf1 <= True;42 f1 <= x;43 end44 endmethod46 method Action deq() if (vf0);47 edge1.send();48 vf0 <= vf1;49 f0 <= f1;50 vf1 <= False;51 endmethod53 method alpha_T first() if(vf0);54 return (f0);55 endmethod57 method Action clear();58 vf0 <= False;59 vf1 <= False;60 endmethod62 method Bool find(search_T sv);63 Bool nvf0 = edge1 ? False: vf0;64 Bool nvf1 = vf1;66 return (nvf0 && searchfunc(sv, f0) ||67 nvf1 && searchfunc(sv, f1));68 endmethod70 method Bool find2(search_T sv);71 Bool nvf0 = edge1 ? False: vf0;72 Bool nvf1 = vf1;74 return (nvf0 && searchfunc(sv, f0) ||75 nvf1 && searchfunc(sv, f1));76 endmethod78 method notEmpty() = vf0._read;80 method Bool notFull();81 return !(vf0 && vf1);82 endmethod84 endmodule86 module mkSFIFO1#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))87 provisos88 (Bits#(alpha_T,asz), Eq#(alpha_T));90 Reg#(alpha_T) f0 <- mkConfigRegU;92 Reg#(Bool) vf0 <- mkConfigReg(False);94 PulseWire edge1 <- mkPulseWire();96 method Action enq(alpha_T x) if (!vf0);97 vf0 <= True; //True98 f0 <= x;99 endmethod101 method Action deq() if (vf0);102 edge1.send();103 vf0 <= False;104 endmethod106 method alpha_T first() if(vf0);107 return (f0);108 endmethod110 method Action clear();111 vf0 <= False;112 endmethod114 method Bool find(search_T sv);115 Bool nvf0 = edge1 ? False: vf0;117 return (nvf0 && searchfunc(sv, f0));118 endmethod120 method Bool find2(search_T sv);121 Bool nvf0 = edge1 ? False: vf0;122 return (nvf0 && searchfunc(sv, f0));123 endmethod125 method notEmpty() = vf0._read;127 method Bool notFull();128 return !vf0;129 endmethod131 endmodule133 module mkSizedSFIFOInternal#(Integer n,134 function Bool searchfunc1(search_T s, alpha_T x),135 function Bool searchfunc2(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))137 provisos ( Bits#(alpha_T,alpha_SZ) );139 List#(Reg#(alpha_T)) registers <- replicateM(n, mkRegU);140 List#(Reg#(Bool)) valids <- replicateM(n, mkReg(False));142 function Nat getNextFree (List#(Reg#(Bool)) vs);144 Nat res = fromInteger(n - 1);146 for (Integer x = n - 1; x > -1; x = x - 1)147 res = !vs[x]._read() ? fromInteger(x) : res;149 return res;151 endfunction153 function Bool notFullHelper();155 Bool full = True;157 for (Integer x = 0; x < n; x = x + 1)158 full = full && valids[x]._read();160 return !full;162 endfunction164 method Action enq( alpha_T item ) if ( notFullHelper() );166 Nat k = getNextFree(valids);167 select(valids, k)._write(True);168 select(registers, k)._write(item);170 endmethod172 method Action deq() if ( valids[0]._read() );174 for (Integer x = 0; x < (n-1); x = x + 1)175 begin177 (registers[x]) <= registers[x + 1]._read();178 (valids[x]) <= valids[x + 1]._read();180 end181 (valids[n-1]) <= False;182 endmethod184 method alpha_T first() if ( valids[0]._read() );185 return registers[0]._read();186 endmethod188 method Bool find(search_T sv);189 Bool res = False;191 for (Integer x = 0; x < n; x = x + 1)192 if ( valids[x]._read() && searchfunc1(sv, registers[x]._read()) )193 res = True;195 return res;197 endmethod199 method Bool find2(search_T sv);200 Bool res = False;202 for (Integer x = 0; x < n; x = x + 1)203 if ( valids[x]._read() && searchfunc2(sv, registers[x]._read()) )204 res = True;206 return res;208 endmethod210 method Action clear();212 for (Integer x = 0; x < n; x = x + 1)213 (valids[x]) <= False;215 endmethod217 method Bool notEmpty();218 return valids[0]._read();219 endmethod221 method Bool notFull();222 return notFullHelper();223 endmethod225 endmodule227 module mkSizedSFIFO#(Integer n, function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))228 provisos229 (Bits#(alpha_T,asz));231 let foo <- mkSizedSFIFOInternal(n, searchfunc, searchfunc);232 return foo;234 endmodule