diff modules/bluespec/Pygar/lab4/oSFIFO.bsv @ 8:74716e9a81cc pygar svn.9

[svn r9] Pygar now has the proper directory structure to play nicely with awb. Also, the apm file for audio-core willcompile successfully.
author rlm
date Fri, 23 Apr 2010 02:32:05 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/bluespec/Pygar/lab4/oSFIFO.bsv	Fri Apr 23 02:32:05 2010 -0400
     1.3 @@ -0,0 +1,234 @@
     1.4 +
     1.5 +import FIFO::*;
     1.6 +import ConfigReg::*;
     1.7 +import RWire::*;
     1.8 +
     1.9 +import List::*;
    1.10 +import Monad::*;
    1.11 +
    1.12 +interface SFIFO#(type alpha_T, type search_T);
    1.13 +   method Action enq(alpha_T x);
    1.14 +   method Action deq();
    1.15 +   method alpha_T first();
    1.16 +   method Action clear();
    1.17 +   method Bool find(search_T x);   
    1.18 +   method Bool find2(search_T x);
    1.19 +   method Bool notEmpty();
    1.20 +   method Bool notFull();
    1.21 +endinterface
    1.22 +
    1.23 +module mkSFIFO#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
    1.24 +    provisos
    1.25 +      (Bits#(alpha_T,asz));
    1.26 +
    1.27 +    Reg#(alpha_T) f0 <- mkConfigRegU;
    1.28 +    Reg#(alpha_T) f1 <- mkConfigRegU;
    1.29 +
    1.30 +    Reg#(Bool)   vf0 <- mkConfigReg(False);
    1.31 +    Reg#(Bool)   vf1 <- mkConfigReg(False);
    1.32 +
    1.33 +    PulseWire edge1      <- mkPulseWire();
    1.34 +      
    1.35 +    method Action enq(alpha_T x) if (!(vf0 && vf1));
    1.36 +      if (edge1 || !vf0)//empty or we're dequeueing
    1.37 +	begin
    1.38 +          vf0 <= True; //True
    1.39 +	  vf1 <= False;
    1.40 +	   f0 <= x;
    1.41 +  	end
    1.42 +      else // !vf1 
    1.43 +        begin
    1.44 +          vf1 <= True;
    1.45 +           f1 <= x;
    1.46 + 	end
    1.47 +    endmethod
    1.48 +										
    1.49 +    method Action deq() if (vf0);
    1.50 +      edge1.send();
    1.51 +      vf0 <= vf1;
    1.52 +       f0 <= f1;
    1.53 +      vf1 <= False;
    1.54 +    endmethod  
    1.55 +
    1.56 +    method alpha_T first() if(vf0);
    1.57 +      return (f0);
    1.58 +    endmethod  
    1.59 +
    1.60 +    method Action clear();
    1.61 +      vf0 <= False;
    1.62 +      vf1 <= False;
    1.63 +    endmethod
    1.64 +
    1.65 +    method Bool find(search_T sv);
    1.66 +      Bool nvf0 = edge1 ? False: vf0;
    1.67 +      Bool nvf1 = vf1;
    1.68 +
    1.69 +      return (nvf0 && searchfunc(sv, f0) || 
    1.70 +              nvf1 && searchfunc(sv, f1));
    1.71 +    endmethod
    1.72 +
    1.73 +    method Bool find2(search_T sv);
    1.74 +      Bool nvf0 = edge1 ? False: vf0;
    1.75 +      Bool nvf1 = vf1;
    1.76 +      
    1.77 +      return (nvf0 && searchfunc(sv, f0) || 
    1.78 +              nvf1 && searchfunc(sv, f1));
    1.79 +    endmethod
    1.80 +
    1.81 +    method notEmpty() = vf0._read;
    1.82 +
    1.83 +    method Bool notFull();
    1.84 +      return !(vf0 && vf1);
    1.85 +    endmethod
    1.86 +
    1.87 +endmodule
    1.88 +
    1.89 +module mkSFIFO1#(function Bool searchfunc(search_T s, alpha_T x)) (SFIFO#(alpha_T, search_T))
    1.90 +    provisos
    1.91 +      (Bits#(alpha_T,asz), Eq#(alpha_T));
    1.92 +
    1.93 +    Reg#(alpha_T) f0 <- mkConfigRegU;
    1.94 +
    1.95 +    Reg#(Bool)   vf0 <- mkConfigReg(False);
    1.96 +
    1.97 +    PulseWire edge1      <- mkPulseWire();
    1.98 +      
    1.99 +    method Action enq(alpha_T x) if (!vf0);
   1.100 +      vf0 <= True; //True
   1.101 +      f0 <= x;
   1.102 +    endmethod
   1.103 +										
   1.104 +    method Action deq() if (vf0);
   1.105 +      edge1.send();
   1.106 +      vf0 <= False;
   1.107 +    endmethod  
   1.108 +
   1.109 +    method alpha_T first() if(vf0);
   1.110 +      return (f0);
   1.111 +    endmethod  
   1.112 +
   1.113 +    method Action clear();
   1.114 +      vf0 <= False;
   1.115 +    endmethod
   1.116 +
   1.117 +    method Bool find(search_T sv);
   1.118 +      Bool nvf0 = edge1 ? False: vf0;
   1.119 +
   1.120 +      return (nvf0 && searchfunc(sv, f0));
   1.121 +    endmethod
   1.122 +
   1.123 +    method Bool find2(search_T sv);
   1.124 +      Bool nvf0 = edge1 ? False: vf0;
   1.125 +      return (nvf0 && searchfunc(sv, f0));
   1.126 +    endmethod
   1.127 +
   1.128 +    method notEmpty() = vf0._read;
   1.129 +
   1.130 +    method Bool notFull();
   1.131 +      return !vf0;
   1.132 +    endmethod
   1.133 +
   1.134 +endmodule
   1.135 +
   1.136 +module mkSizedSFIFOInternal#(Integer n, 
   1.137 +			     function Bool searchfunc1(search_T s, alpha_T x), 
   1.138 +			     function Bool searchfunc2(search_T s, alpha_T x))  (SFIFO#(alpha_T, search_T))
   1.139 +				
   1.140 +   provisos ( Bits#(alpha_T,alpha_SZ) );
   1.141 +
   1.142 +  List#(Reg#(alpha_T)) registers <- replicateM(n, mkRegU);
   1.143 +  List#(Reg#(Bool))   valids <- replicateM(n, mkReg(False));
   1.144 +
   1.145 +  function Nat getNextFree (List#(Reg#(Bool)) vs);
   1.146 +
   1.147 +    Nat res = fromInteger(n - 1);
   1.148 +
   1.149 +    for (Integer x = n - 1; x > -1; x = x - 1)
   1.150 +      res = !vs[x]._read() ? fromInteger(x) : res;
   1.151 +
   1.152 +    return res;
   1.153 +  
   1.154 +  endfunction
   1.155 +
   1.156 +  function Bool notFullHelper();
   1.157 +  
   1.158 +    Bool full = True;
   1.159 +
   1.160 +    for (Integer x = 0; x < n; x = x + 1)
   1.161 +      full = full && valids[x]._read();
   1.162 +
   1.163 +    return !full;
   1.164 +  
   1.165 +  endfunction
   1.166 +
   1.167 +  method Action enq( alpha_T item ) if ( notFullHelper() );
   1.168 +    
   1.169 +    Nat k = getNextFree(valids);
   1.170 +    select(valids, k)._write(True);
   1.171 +    select(registers, k)._write(item);
   1.172 +    
   1.173 +  endmethod
   1.174 +
   1.175 +  method Action deq() if ( valids[0]._read() );
   1.176 +    
   1.177 +    for (Integer x = 0; x < (n-1); x = x + 1)
   1.178 +    begin
   1.179 +    
   1.180 +      (registers[x]) <= registers[x + 1]._read();
   1.181 +      (valids[x]) <= valids[x + 1]._read();
   1.182 +    
   1.183 +    end
   1.184 +    (valids[n-1]) <= False;
   1.185 +  endmethod  
   1.186 +
   1.187 +  method alpha_T first() if ( valids[0]._read() );
   1.188 +    return registers[0]._read();  
   1.189 +  endmethod
   1.190 +
   1.191 +  method Bool find(search_T sv);
   1.192 +    Bool res = False;
   1.193 +    
   1.194 +    for (Integer x = 0; x < n; x = x + 1)
   1.195 +       if ( valids[x]._read() && searchfunc1(sv, registers[x]._read()) )
   1.196 +          res = True;
   1.197 +    
   1.198 +    return res;
   1.199 +    
   1.200 +  endmethod
   1.201 +
   1.202 +  method Bool find2(search_T sv);
   1.203 +    Bool res = False;
   1.204 +    
   1.205 +     for (Integer x = 0; x < n; x = x + 1)
   1.206 +        if ( valids[x]._read() && searchfunc2(sv, registers[x]._read()) )
   1.207 +           res = True;
   1.208 +    
   1.209 +    return res;
   1.210 +    
   1.211 +  endmethod
   1.212 +
   1.213 +  method Action clear();
   1.214 +  
   1.215 +    for (Integer x = 0; x < n; x = x + 1)
   1.216 +      (valids[x]) <= False;
   1.217 +    
   1.218 +  endmethod
   1.219 +
   1.220 +  method Bool notEmpty();
   1.221 +    return valids[0]._read(); 
   1.222 +  endmethod
   1.223 +
   1.224 +  method Bool notFull();
   1.225 +    return notFullHelper();
   1.226 +  endmethod
   1.227 +
   1.228 +endmodule
   1.229 +
   1.230 +module mkSizedSFIFO#(Integer n, function Bool searchfunc(search_T s, alpha_T x))  (SFIFO#(alpha_T, search_T))
   1.231 +    provisos
   1.232 +      (Bits#(alpha_T,asz));
   1.233 +   
   1.234 +   let foo <- mkSizedSFIFOInternal(n, searchfunc, searchfunc);
   1.235 +   return foo;
   1.236 +
   1.237 +endmodule
   1.238 \ No newline at end of file