@@ -21,6 +21,7 @@ package vta.core
2121
2222import chisel3 ._
2323import chisel3 .util ._
24+ import scala .collection .mutable .HashMap
2425
2526/** ISAConstants.
2627 *
@@ -70,45 +71,78 @@ trait ISAConstants {
7071
7172/** ISA.
7273 *
73- * This is the VTA ISA, here we specify the cares and dont-cares that makes
74- * decoding easier. Since instructions are quite long 128-bit, we could generate
75- * these based on ISAConstants.
74+ * This is the VTA task ISA
7675 *
77- * FIXME: VSHX should be replaced by VSHR and VSHL once we modify the compiler
7876 * TODO: Add VXOR to clear accumulator
77+ * TODO: Use ISA object for decoding as well
78+ * TODO: Eventually deprecate ISAConstants
7979 */
8080object ISA {
81- def LUOP =
82- BitPat (
83- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_???????0_0????000" )
84- def LWGT =
85- BitPat (
86- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_???????0_1????000" )
87- def LINP =
88- BitPat (
89- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_???????1_0????000" )
90- def LACC =
91- BitPat (
92- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_???????1_1????000" )
93- def SOUT =
94- BitPat (
95- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????001" )
96- def GEMM =
97- BitPat (
98- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????010" )
99- def VMIN =
100- BitPat (
101- " b_????????_????????_??00????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????100" )
102- def VMAX =
103- BitPat (
104- " b_????????_????????_??01????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????100" )
105- def VADD =
106- BitPat (
107- " b_????????_????????_??10????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????100" )
108- def VSHX =
109- BitPat (
110- " b_????????_????????_??11????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????100" )
111- def FNSH =
112- BitPat (
113- " b_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_????????_?????011" )
81+ private val xLen = 128
82+ private val depBits = 4
83+
84+ private val idBits : HashMap [String , Int ] =
85+ HashMap ((" task" , 3 ), (" mem" , 2 ), (" alu" , 2 ))
86+
87+ private val taskId : HashMap [String , String ] =
88+ HashMap ((" load" , " 000" ),
89+ (" store" , " 001" ),
90+ (" gemm" , " 010" ),
91+ (" finish" , " 011" ),
92+ (" alu" , " 100" ))
93+
94+ private val memId : HashMap [String , String ] =
95+ HashMap ((" uop" , " 00" ), (" wgt" , " 01" ), (" inp" , " 10" ), (" acc" , " 11" ))
96+
97+ private val aluId : HashMap [String , String ] =
98+ HashMap ((" minpool" , " 00" ),
99+ (" maxpool" , " 01" ),
100+ (" add" , " 10" ),
101+ (" shift" , " 11" ))
102+
103+ private def dontCare (bits : Int ): String = " ?" * bits
104+
105+ private def instPat (bin : String ): BitPat = BitPat (" b" + bin)
106+
107+ private def load (id : String ): BitPat = {
108+ val rem = xLen - idBits(" mem" ) - depBits - idBits(" task" )
109+ val inst = dontCare(rem) + memId(id) + dontCare(depBits) + taskId(" load" )
110+ instPat(inst)
111+ }
112+
113+ private def store : BitPat = {
114+ val rem = xLen - idBits(" task" )
115+ val inst = dontCare(rem) + taskId(" store" )
116+ instPat(inst)
117+ }
118+
119+ private def gemm : BitPat = {
120+ val rem = xLen - idBits(" task" )
121+ val inst = dontCare(rem) + taskId(" gemm" )
122+ instPat(inst)
123+ }
124+
125+ private def alu (id : String ): BitPat = {
126+ // TODO: move alu id next to task id
127+ val inst = dontCare(18 ) + aluId(id) + dontCare(105 ) + taskId(" alu" )
128+ instPat(inst)
129+ }
130+
131+ private def finish : BitPat = {
132+ val rem = xLen - idBits(" task" )
133+ val inst = dontCare(rem) + taskId(" finish" )
134+ instPat(inst)
135+ }
136+
137+ def LUOP = load(" uop" )
138+ def LWGT = load(" wgt" )
139+ def LINP = load(" inp" )
140+ def LACC = load(" acc" )
141+ def SOUT = store
142+ def GEMM = gemm
143+ def VMIN = alu(" minpool" )
144+ def VMAX = alu(" maxpool" )
145+ def VADD = alu(" add" )
146+ def VSHX = alu(" shift" )
147+ def FNSH = finish
114148}
0 commit comments