add libraries
[shakti-core.git] / src / lib / Stack.bsv
1 /*
2 Copyright (c) 2013, IIT Madras
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the name of IIT Madras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 */
14 package Stack;
15 import defined_types::*;
16 import RegFile::*;
17 `include "defined_parameters.bsv"
18 interface Ifc_Stack;
19 method Action push(Bit#(`VADDR) addr);
20 method ActionValue#(Bit#(`VADDR)) top;
21 method Bool empty;
22 method Action flush;
23 endinterface
24
25 // (*synthesize*)
26 module mkStack(Ifc_Stack);
27 Reg#(Bit#(TLog#(`RAS_DEPTH))) top_index[2] <-mkCReg(2,0);
28 RegFile#(Bit#(TLog#(`RAS_DEPTH)),Bit#(`VADDR)) array_reg <-mkRegFileWCF(0,fromInteger(`RAS_DEPTH-1));
29 method ActionValue#(Bit#(`VADDR)) top;
30 top_index[0]<=top_index[0]-1;
31 return array_reg.sub(top_index[0]-1);
32 endmethod
33 method Action push(Bit#(`VADDR) addr);
34 array_reg.upd(top_index[1],addr);
35 top_index[1]<=top_index[1]+1;
36 endmethod
37 method Bool empty;
38 return (top_index[0]==0);
39 endmethod
40 endmodule
41 endpackage