Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
XiangShan
提交
8103b7d2
X
XiangShan
项目概览
OpenXiangShan
/
XiangShan
11 个月 前同步成功
通知
1183
Star
3914
Fork
526
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
XiangShan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8103b7d2
编写于
10月 08, 2019
作者:
Z
Zihao Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
noop,Cache: use case class to pass parameters
上级
12ed0a0e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
31 deletion
+46
-31
src/main/scala/noop/Cache.scala
src/main/scala/noop/Cache.scala
+44
-29
src/main/scala/noop/NOOP.scala
src/main/scala/noop/NOOP.scala
+2
-2
未找到文件。
src/main/scala/noop/Cache.scala
浏览文件 @
8103b7d2
...
...
@@ -8,14 +8,29 @@ import bus.simplebus._
import
bus.axi4._
import
utils._
case
class
CacheConfig
(
ro
:
Boolean
=
false
,
name
:
String
=
"cache"
,
userBits
:
Int
=
0
,
totalSize
:
Int
=
32
,
// Kbytes
ways
:
Int
=
4
)
sealed
trait
HasCacheConst
{
implicit
val
cacheConfig
:
CacheConfig
val
AddrBits
:
Int
val
XLEN
:
Int
val
TotalSize
=
32
// Kbytes
val
ro
=
cacheConfig
.
ro
val
cacheName
=
cacheConfig
.
name
val
userBits
=
cacheConfig
.
userBits
val
TotalSize
=
cacheConfig
.
totalSize
val
Ways
=
cacheConfig
.
ways
val
LineSize
=
XLEN
// byte
val
LineBeats
=
LineSize
/
8
//DATA WIDTH 64
val
Ways
=
4
val
Sets
=
TotalSize
*
1024
/
LineSize
/
Ways
val
OffsetBits
=
log2Up
(
LineSize
)
val
IndexBits
=
log2Up
(
Sets
)
...
...
@@ -40,10 +55,10 @@ sealed trait HasCacheConst {
def
isSetConflict
(
a1
:
UInt
,
a2
:
UInt
)
=
(
a1
.
asTypeOf
(
addrBundle
).
index
===
a2
.
asTypeOf
(
addrBundle
).
index
)
}
sealed
abstract
class
CacheBundle
extends
Bundle
with
HasNOOPParameter
with
HasCacheConst
sealed
abstract
class
CacheModule
extends
Module
with
HasNOOPParameter
with
HasCacheConst
sealed
abstract
class
CacheBundle
(
implicit
cacheConfig
:
CacheConfig
)
extends
Bundle
with
HasNOOPParameter
with
HasCacheConst
sealed
abstract
class
CacheModule
(
implicit
cacheConfig
:
CacheConfig
)
extends
Module
with
HasNOOPParameter
with
HasCacheConst
sealed
class
MetaBundle
extends
CacheBundle
{
sealed
class
MetaBundle
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheBundle
{
val
tag
=
Output
(
UInt
(
TagBits
.
W
))
val
valid
=
Output
(
Bool
())
val
dirty
=
Output
(
Bool
())
...
...
@@ -56,7 +71,7 @@ sealed class MetaBundle extends CacheBundle {
}
}
sealed
class
DataBundle
extends
CacheBundle
{
sealed
class
DataBundle
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheBundle
{
val
data
=
Output
(
UInt
(
DataBits
.
W
))
def
apply
(
data
:
UInt
)
=
{
...
...
@@ -65,15 +80,15 @@ sealed class DataBundle extends CacheBundle {
}
}
sealed
class
Stage1IO
(
val
userBits
:
Int
=
0
)
extends
CacheBundle
{
sealed
class
Stage1IO
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheBundle
{
val
req
=
new
SimpleBusReqBundle
(
userBits
=
userBits
)
}
// meta read
sealed
class
CacheStage1
(
ro
:
Boolean
,
name
:
String
,
userBits
:
Int
=
0
)
extends
CacheModule
{
sealed
class
CacheStage1
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheModule
{
val
io
=
IO
(
new
Bundle
{
val
in
=
Flipped
(
Decoupled
(
new
SimpleBusReqBundle
(
userBits
=
userBits
)))
val
out
=
Decoupled
(
new
Stage1IO
(
userBits
)
)
val
out
=
Decoupled
(
new
Stage1IO
)
val
metaReadBus
=
CacheMetaArrayReadBus
()
val
dataReadBus
=
CacheDataArrayReadBus
()
...
...
@@ -102,7 +117,7 @@ sealed class CacheStage1(ro: Boolean, name: String, userBits: Int = 0) extends C
io
.
in
.
ready
:=
(!
io
.
in
.
valid
||
io
.
out
.
fire
())
&&
io
.
metaReadBus
.
req
.
ready
&&
io
.
dataReadBus
.
req
.
ready
}
sealed
class
Stage2IO
(
val
userBits
:
Int
=
0
)
extends
CacheBundle
{
sealed
class
Stage2IO
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheBundle
{
val
req
=
new
SimpleBusReqBundle
(
userBits
=
userBits
)
val
metas
=
Vec
(
Ways
,
new
MetaBundle
)
val
datas
=
Vec
(
Ways
,
new
DataBundle
)
...
...
@@ -111,10 +126,10 @@ sealed class Stage2IO(val userBits: Int = 0) extends CacheBundle {
}
// check
sealed
class
CacheStage2
(
ro
:
Boolean
,
name
:
String
,
userBits
:
Int
=
0
)
extends
CacheModule
{
sealed
class
CacheStage2
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheModule
{
val
io
=
IO
(
new
Bundle
{
val
in
=
Flipped
(
Decoupled
(
new
Stage1IO
(
userBits
)
))
val
out
=
Decoupled
(
new
Stage2IO
(
userBits
)
)
val
in
=
Flipped
(
Decoupled
(
new
Stage1IO
))
val
out
=
Decoupled
(
new
Stage2IO
)
val
metaReadResp
=
Flipped
(
Vec
(
Ways
,
new
MetaBundle
))
val
dataReadResp
=
Flipped
(
Vec
(
Ways
,
new
DataBundle
))
})
...
...
@@ -138,9 +153,9 @@ sealed class CacheStage2(ro: Boolean, name: String, userBits: Int = 0) extends C
}
// writeback
sealed
class
CacheStage3
(
ro
:
Boolean
,
name
:
String
,
userBits
:
Int
=
0
)
extends
CacheModule
{
sealed
class
CacheStage3
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheModule
{
val
io
=
IO
(
new
Bundle
{
val
in
=
Flipped
(
Decoupled
(
new
Stage2IO
(
userBits
)
))
val
in
=
Flipped
(
Decoupled
(
new
Stage2IO
))
val
out
=
Decoupled
(
new
SimpleBusRespBundle
(
userBits
=
userBits
))
val
isFinish
=
Output
(
Bool
())
val
addr
=
Output
(
UInt
(
AddrBits
.
W
))
...
...
@@ -280,13 +295,13 @@ sealed class CacheStage3(ro: Boolean, name: String, userBits: Int = 0) extends C
assert
(!(
metaHitWriteBus
.
req
.
valid
&&
metaRefillWriteBus
.
req
.
valid
))
assert
(!(
dataHitWriteBus
.
req
.
valid
&&
dataRefillWriteBus
.
req
.
valid
))
Debug
(
debug
)
{
printf
(
"%d: ["
+
n
ame
+
" stage3]: in.ready = %d, in.valid = %d, state = %d, addr = %x\n"
,
printf
(
"%d: ["
+
cacheN
ame
+
" stage3]: in.ready = %d, in.valid = %d, state = %d, addr = %x\n"
,
GTimer
(),
io
.
in
.
ready
,
io
.
in
.
valid
,
state
,
req
.
addr
)
}
}
// probe
sealed
class
CacheProbeStage
(
ro
:
Boolean
,
name
:
Strin
g
)
extends
CacheModule
{
sealed
class
CacheProbeStage
(
implicit
val
cacheConfig
:
CacheConfi
g
)
extends
CacheModule
{
val
io
=
IO
(
new
Bundle
{
val
in
=
Flipped
(
Decoupled
(
new
SimpleBusReqBundle
))
val
out
=
Decoupled
(
new
SimpleBusRespBundle
)
...
...
@@ -340,7 +355,7 @@ sealed class CacheProbeStage(ro: Boolean, name: String) extends CacheModule {
Mux
(
hit
,
SimpleBusCmd
.
probeHit
,
SimpleBusCmd
.
probeMiss
))
}
class
Cache
(
ro
:
Boolean
,
name
:
String
,
userBits
:
Int
=
0
)
extends
CacheModule
{
class
Cache
(
implicit
val
cacheConfig
:
CacheConfig
)
extends
CacheModule
{
val
io
=
IO
(
new
Bundle
{
val
in
=
Flipped
(
new
SimpleBusUC
(
userBits
=
userBits
))
val
addr
=
Output
(
UInt
(
AddrBits
.
W
))
...
...
@@ -349,13 +364,13 @@ class Cache(ro: Boolean, name: String, userBits: Int = 0) extends CacheModule {
})
// cpu pipeline
val
s1
=
Module
(
new
CacheStage1
(
ro
,
name
,
userBits
)
)
val
s2
=
Module
(
new
CacheStage2
(
ro
,
name
,
userBits
)
)
val
s3
=
Module
(
new
CacheStage3
(
ro
,
name
,
userBits
)
)
val
s1
=
Module
(
new
CacheStage1
)
val
s2
=
Module
(
new
CacheStage2
)
val
s3
=
Module
(
new
CacheStage3
)
val
metaArray
=
Module
(
new
SRAMTemplate
(
new
MetaBundle
,
set
=
Sets
,
way
=
Ways
,
shouldReset
=
true
,
singlePort
=
true
))
val
dataArray
=
Module
(
new
SRAMTemplate
(
new
DataBundle
,
set
=
Sets
*
LineBeats
,
way
=
Ways
,
singlePort
=
true
))
if
(
n
ame
==
"icache"
)
{
if
(
cacheN
ame
==
"icache"
)
{
// flush icache when executing fence.i
val
flushICache
=
WireInit
(
false
.
B
)
BoringUtils
.
addSink
(
flushICache
,
"MOUFlushICache"
)
...
...
@@ -378,7 +393,7 @@ class Cache(ro: Boolean, name: String, userBits: Int = 0) extends CacheModule {
s1
.
io
.
s2s3Miss
:=
s3
.
io
.
in
.
valid
&&
!
s3
.
io
.
in
.
bits
.
hit
// coherence state machine
val
coh
=
Module
(
new
CacheProbeStage
(
ro
,
name
)
)
val
coh
=
Module
(
new
CacheProbeStage
)
coh
.
io
.
in
<>
io
.
out
.
coh
.
req
io
.
out
.
coh
.
resp
<>
coh
.
io
.
out
...
...
@@ -406,15 +421,15 @@ class Cache(ro: Boolean, name: String, userBits: Int = 0) extends CacheModule {
s2
.
io
.
metaReadResp
:=
metaArray
.
io
.
r
.
resp
.
data
s2
.
io
.
dataReadResp
:=
dataArray
.
io
.
r
.
resp
.
data
BoringUtils
.
addSource
(
s3
.
io
.
in
.
valid
&&
s3
.
io
.
in
.
bits
.
hit
,
"perfCntCondM"
+
n
ame
+
"Hit"
)
BoringUtils
.
addSource
(
s3
.
io
.
in
.
valid
&&
s3
.
io
.
in
.
bits
.
hit
,
"perfCntCondM"
+
cacheN
ame
+
"Hit"
)
Debug
(
debug
)
{
io
.
in
.
dump
(
n
ame
+
".in"
)
io
.
in
.
dump
(
cacheN
ame
+
".in"
)
printf
(
"%d: s1:(%d,%d), s2:(%d,%d), s3:(%d,%d)\n"
,
GTimer
(),
s1
.
io
.
in
.
valid
,
s1
.
io
.
in
.
ready
,
s2
.
io
.
in
.
valid
,
s2
.
io
.
in
.
ready
,
s3
.
io
.
in
.
valid
,
s3
.
io
.
in
.
ready
)
when
(
s1
.
io
.
in
.
valid
)
{
printf
(
p
"[${
n
ame}.S1]: ${s1.io.in.bits}\n"
)
}
when
(
s2
.
io
.
in
.
valid
)
{
printf
(
p
"[${
n
ame}.S2]: ${s2.io.in.bits.req}\n"
)
}
when
(
s3
.
io
.
in
.
valid
)
{
printf
(
p
"[${
n
ame}.S3]: ${s3.io.in.bits.req}\n"
)
}
s3
.
io
.
mem
.
dump
(
n
ame
+
".mem"
)
when
(
s1
.
io
.
in
.
valid
)
{
printf
(
p
"[${
cacheN
ame}.S1]: ${s1.io.in.bits}\n"
)
}
when
(
s2
.
io
.
in
.
valid
)
{
printf
(
p
"[${
cacheN
ame}.S2]: ${s2.io.in.bits.req}\n"
)
}
when
(
s3
.
io
.
in
.
valid
)
{
printf
(
p
"[${
cacheN
ame}.S3]: ${s3.io.in.bits.req}\n"
)
}
s3
.
io
.
mem
.
dump
(
cacheN
ame
+
".mem"
)
}
}
src/main/scala/noop/NOOP.scala
浏览文件 @
8103b7d2
...
...
@@ -81,7 +81,7 @@ class NOOP(implicit val p: NOOPConfig) extends NOOPModule {
isu
.
io
.
forward
<>
exu
.
io
.
forward
io
.
imem
<>
(
if
(
HasIcache
)
{
val
icache
=
Module
(
new
Cache
(
ro
=
true
,
name
=
"icache"
,
userBits
=
AddrBits
))
val
icache
=
Module
(
new
Cache
(
)(
CacheConfig
(
ro
=
true
,
name
=
"icache"
,
userBits
=
AddrBits
)
))
icache
.
io
.
in
<>
ifu
.
io
.
imem
icache
.
io
.
flush
:=
Fill
(
2
,
ifu
.
io
.
flushVec
(
0
)
|
ifu
.
io
.
bpFlush
)
ifu
.
io
.
pc
:=
icache
.
io
.
addr
...
...
@@ -89,7 +89,7 @@ class NOOP(implicit val p: NOOPConfig) extends NOOPModule {
}
else
{
ifu
.
io
.
imem
})
io
.
dmem
<>
(
if
(
HasDcache
)
{
val
dcache
=
Module
(
new
Cache
(
ro
=
false
,
name
=
"dcache"
))
val
dcache
=
Module
(
new
Cache
(
)(
CacheConfig
(
ro
=
false
,
name
=
"dcache"
)
))
dcache
.
io
.
in
<>
exu
.
io
.
dmem
dcache
.
io
.
flush
:=
Fill
(
2
,
false
.
B
)
dcache
.
io
.
out
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录