Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
XiangShan
提交
52e83310
X
XiangShan
项目概览
OpenXiangShan
/
XiangShan
9 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
52e83310
编写于
12月 24, 2020
作者:
Y
Yinan Xu
提交者:
GitHub
12月 24, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #351 from RISCVERS/opt-lsq
lsq: use reg to keep track of the number of valid entries
上级
d1a879d1
640b1737
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
40 deletion
+82
-40
src/main/scala/xiangshan/mem/lsqueue/LoadQueue.scala
src/main/scala/xiangshan/mem/lsqueue/LoadQueue.scala
+35
-16
src/main/scala/xiangshan/mem/lsqueue/StoreQueue.scala
src/main/scala/xiangshan/mem/lsqueue/StoreQueue.scala
+47
-24
未找到文件。
src/main/scala/xiangshan/mem/lsqueue/LoadQueue.scala
浏览文件 @
52e83310
...
...
@@ -62,6 +62,9 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
val
enqPtrExt
=
RegInit
(
VecInit
((
0
until
RenameWidth
).
map
(
_
.
U
.
asTypeOf
(
new
LqPtr
))))
val
deqPtrExt
=
RegInit
(
0.
U
.
asTypeOf
(
new
LqPtr
))
val
validCounter
=
RegInit
(
0.
U
(
log2Ceil
(
LoadQueueSize
).
W
))
val
allowEnqueue
=
RegInit
(
true
.
B
)
val
enqPtr
=
enqPtrExt
(
0
).
value
val
deqPtr
=
deqPtrExt
.
value
val
sameFlag
=
enqPtrExt
(
0
).
flag
===
deqPtrExt
.
flag
...
...
@@ -80,10 +83,8 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
*
* Currently, LoadQueue only allows enqueue when #emptyEntries > RenameWidth(EnqWidth)
*/
val
validEntries
=
distanceBetween
(
enqPtrExt
(
0
),
deqPtrExt
)
val
firedDispatch
=
io
.
enq
.
req
.
map
(
_
.
valid
)
io
.
enq
.
canAccept
:=
validEntries
<=
(
LoadQueueSize
-
RenameWidth
).
U
XSDebug
(
p
"(ready, valid): ${io.enq.canAccept}, ${Binary(Cat(firedDispatch))}\n"
)
io
.
enq
.
canAccept
:=
allowEnqueue
for
(
i
<-
0
until
RenameWidth
)
{
val
offset
=
if
(
i
==
0
)
0.
U
else
PopCount
(
io
.
enq
.
needAlloc
.
take
(
i
))
val
lqIdx
=
enqPtrExt
(
offset
)
...
...
@@ -100,13 +101,7 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
}
io
.
enq
.
resp
(
i
)
:=
lqIdx
}
// when io.brqRedirect.valid, we don't allow eneuque even though it may fire.
when
(
Cat
(
firedDispatch
).
orR
&&
io
.
enq
.
canAccept
&&
io
.
enq
.
sqCanAccept
&&
!
io
.
brqRedirect
.
valid
)
{
val
enqNumber
=
PopCount
(
firedDispatch
)
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
+
enqNumber
))
XSInfo
(
"dispatched %d insts to lq\n"
,
enqNumber
)
}
XSDebug
(
p
"(ready, valid): ${io.enq.canAccept}, ${Binary(Cat(io.enq.req.map(_.valid)))}\n"
)
/**
* Writeback load from load units
...
...
@@ -335,7 +330,6 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
XSDebug
(
"load commit %d: idx %d %x\n"
,
i
.
U
,
mcommitIdx
(
i
),
uop
(
mcommitIdx
(
i
)).
cf
.
pc
)
}
})
deqPtrExt
:=
deqPtrExt
+
PopCount
(
loadCommit
)
def
getFirstOne
(
mask
:
Vec
[
Bool
],
startMask
:
UInt
)
=
{
val
length
=
mask
.
length
...
...
@@ -549,13 +543,38 @@ class LoadQueue extends XSModule with HasDCacheParameters with HasCircularQueueP
allocated
(
i
)
:=
false
.
B
}
}
// we recover the pointers in the next cycle after redirect
val
needCancelReg
=
RegNext
(
needCancel
)
/**
* update pointers
*/
val
lastCycleCancelCount
=
PopCount
(
RegNext
(
needCancel
))
// when io.brqRedirect.valid, we don't allow eneuque even though it may fire.
val
enqNumber
=
Mux
(
io
.
enq
.
canAccept
&&
io
.
enq
.
sqCanAccept
&&
!
io
.
brqRedirect
.
valid
,
PopCount
(
io
.
enq
.
req
.
map
(
_
.
valid
)),
0.
U
)
when
(
lastCycleRedirect
.
valid
)
{
val
cancelCount
=
PopCount
(
needCancelReg
)
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
-
cancelCount
))
// we recover the pointers in the next cycle after redirect
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
-
lastCycleCancelCount
))
}.
otherwise
{
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
+
enqNumber
))
}
val
commitCount
=
PopCount
(
loadCommit
)
deqPtrExt
:=
deqPtrExt
+
commitCount
val
lastLastCycleRedirect
=
RegNext
(
lastCycleRedirect
.
valid
)
val
trueValidCounter
=
distanceBetween
(
enqPtrExt
(
0
),
deqPtrExt
)
validCounter
:=
Mux
(
lastLastCycleRedirect
,
trueValidCounter
,
validCounter
+
enqNumber
-
commitCount
)
allowEnqueue
:=
Mux
(
io
.
brqRedirect
.
valid
,
false
.
B
,
Mux
(
lastLastCycleRedirect
,
trueValidCounter
<=
(
LoadQueueSize
-
RenameWidth
).
U
,
validCounter
+
enqNumber
<=
(
LoadQueueSize
-
RenameWidth
).
U
)
)
// debug info
XSDebug
(
"enqPtrExt %d:%d deqPtrExt %d:%d\n"
,
enqPtrExt
(
0
).
flag
,
enqPtr
,
deqPtrExt
.
flag
,
deqPtr
)
...
...
src/main/scala/xiangshan/mem/lsqueue/StoreQueue.scala
浏览文件 @
52e83310
...
...
@@ -58,6 +58,9 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
require
(
StoreQueueSize
>
RenameWidth
)
val
enqPtrExt
=
RegInit
(
VecInit
((
0
until
RenameWidth
).
map
(
_
.
U
.
asTypeOf
(
new
SqPtr
))))
val
deqPtrExt
=
RegInit
(
VecInit
((
0
until
StorePipelineWidth
).
map
(
_
.
U
.
asTypeOf
(
new
SqPtr
))))
val
validCounter
=
RegInit
(
0.
U
(
log2Ceil
(
LoadQueueSize
).
W
))
val
allowEnqueue
=
RegInit
(
true
.
B
)
val
enqPtr
=
enqPtrExt
(
0
).
value
val
deqPtr
=
deqPtrExt
(
0
).
value
...
...
@@ -69,10 +72,7 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
*
* Currently, StoreQueue only allows enqueue when #emptyEntries > RenameWidth(EnqWidth)
*/
val
validEntries
=
distanceBetween
(
enqPtrExt
(
0
),
deqPtrExt
(
0
))
val
firedDispatch
=
io
.
enq
.
req
.
map
(
_
.
valid
)
io
.
enq
.
canAccept
:=
validEntries
<=
(
StoreQueueSize
-
RenameWidth
).
U
XSDebug
(
p
"(ready, valid): ${io.enq.canAccept}, ${Binary(Cat(firedDispatch))}\n"
)
io
.
enq
.
canAccept
:=
allowEnqueue
for
(
i
<-
0
until
RenameWidth
)
{
val
offset
=
if
(
i
==
0
)
0.
U
else
PopCount
(
io
.
enq
.
needAlloc
.
take
(
i
))
val
sqIdx
=
enqPtrExt
(
offset
)
...
...
@@ -87,12 +87,7 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
}
io
.
enq
.
resp
(
i
)
:=
sqIdx
}
when
(
Cat
(
firedDispatch
).
orR
&&
io
.
enq
.
canAccept
&&
io
.
enq
.
lqCanAccept
&&
!
io
.
brqRedirect
.
valid
)
{
val
enqNumber
=
PopCount
(
firedDispatch
)
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
+
enqNumber
))
XSInfo
(
"dispatched %d insts to sq\n"
,
enqNumber
)
}
XSDebug
(
p
"(ready, valid): ${io.enq.canAccept}, ${Binary(Cat(io.enq.req.map(_.valid)))}\n"
)
/**
* Writeback store from store units
...
...
@@ -104,7 +99,7 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
* instead of pending to avoid sending them to lower level.
* (2) For an mmio instruction without exceptions, we mark it as pending.
* When the instruction reaches ROB's head, StoreQueue sends it to uncache channel.
* Upon receiving the response, StoreQueue writes back the instruction
* Upon receiving the response, StoreQueue writes back the instruction
* through arbiter with store units. It will later commit as normal.
*/
for
(
i
<-
0
until
StorePipelineWidth
)
{
...
...
@@ -246,7 +241,7 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
when
(
io
.
mmioStout
.
fire
())
{
writebacked
(
deqPtr
)
:=
true
.
B
allocated
(
deqPtr
)
:=
false
.
B
deqPtrExt
:=
VecInit
(
deqPtrExt
.
map
(
_
+
1.
U
))
}
/**
...
...
@@ -284,14 +279,10 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
XSDebug
(
"sbuffer "
+
i
+
" fire: ptr %d\n"
,
ptr
)
}
}
// note that sbuffer will not accept req(1) if req(0) is not accepted.
when
(
Cat
(
io
.
sbuffer
.
map
(
_
.
fire
())).
orR
)
{
val
stepForward
=
Mux
(
io
.
sbuffer
(
1
).
fire
(),
2.
U
,
1.
U
)
deqPtrExt
:=
VecInit
(
deqPtrExt
.
map
(
_
+
stepForward
))
when
(
io
.
sbuffer
(
1
).
fire
())
{
assert
(
io
.
sbuffer
(
0
).
fire
())
}
when
(
io
.
sbuffer
(
1
).
fire
())
{
assert
(
io
.
sbuffer
(
0
).
fire
())
}
if
(!
env
.
FPGAPlatform
)
{
val
storeCommit
=
PopCount
(
io
.
sbuffer
.
map
(
_
.
fire
()))
val
waddr
=
VecInit
(
io
.
sbuffer
.
map
(
req
=>
SignExt
(
req
.
bits
.
addr
,
64
)))
...
...
@@ -316,13 +307,45 @@ class StoreQueue extends XSModule with HasDCacheParameters with HasCircularQueue
allocated
(
i
)
:=
false
.
B
}
}
// we recover the pointers in the next cycle after redirect
val
lastCycleRedirectValid
=
RegNext
(
io
.
brqRedirect
.
valid
)
val
needCancelCount
=
PopCount
(
RegNext
(
needCancel
))
when
(
lastCycleRedirectValid
)
{
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
-
needCancelCount
))
/**
* update pointers
*/
val
lastCycleRedirect
=
RegNext
(
io
.
brqRedirect
.
valid
)
val
lastCycleCancelCount
=
PopCount
(
RegNext
(
needCancel
))
// when io.brqRedirect.valid, we don't allow eneuque even though it may fire.
val
enqNumber
=
Mux
(
io
.
enq
.
canAccept
&&
io
.
enq
.
lqCanAccept
&&
!
io
.
brqRedirect
.
valid
,
PopCount
(
io
.
enq
.
req
.
map
(
_
.
valid
)),
0.
U
)
when
(
lastCycleRedirect
)
{
// we recover the pointers in the next cycle after redirect
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
-
lastCycleCancelCount
))
}.
otherwise
{
enqPtrExt
:=
VecInit
(
enqPtrExt
.
map
(
_
+
enqNumber
))
}
deqPtrExt
:=
Mux
(
io
.
sbuffer
(
1
).
fire
(),
VecInit
(
deqPtrExt
.
map
(
_
+
2.
U
)),
Mux
(
io
.
sbuffer
(
0
).
fire
()
||
io
.
mmioStout
.
fire
(),
VecInit
(
deqPtrExt
.
map
(
_
+
1.
U
)),
deqPtrExt
)
)
val
lastLastCycleRedirect
=
RegNext
(
lastCycleRedirect
)
val
dequeueCount
=
Mux
(
io
.
sbuffer
(
1
).
fire
(),
2.
U
,
Mux
(
io
.
sbuffer
(
0
).
fire
()
||
io
.
mmioStout
.
fire
(),
1.
U
,
0.
U
))
val
trueValidCounter
=
distanceBetween
(
enqPtrExt
(
0
),
deqPtrExt
(
0
))
validCounter
:=
Mux
(
lastLastCycleRedirect
,
trueValidCounter
-
dequeueCount
,
validCounter
+
enqNumber
-
dequeueCount
)
allowEnqueue
:=
Mux
(
io
.
brqRedirect
.
valid
,
false
.
B
,
Mux
(
lastLastCycleRedirect
,
trueValidCounter
<=
(
StoreQueueSize
-
RenameWidth
).
U
,
validCounter
+
enqNumber
<=
(
StoreQueueSize
-
RenameWidth
).
U
)
)
// debug info
XSDebug
(
"enqPtrExt %d:%d deqPtrExt %d:%d\n"
,
enqPtrExt
(
0
).
flag
,
enqPtr
,
deqPtrExt
(
0
).
flag
,
deqPtr
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录