Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
XiangShan
提交
8dc20ae0
X
XiangShan
项目概览
OpenXiangShan
/
XiangShan
10 个月 前同步成功
通知
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 搜索 >>
提交
8dc20ae0
编写于
7月 31, 2020
作者:
J
jinyue110
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
uBTB: add uBTB but still has a lot of TODOs
上级
6f5888f7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
176 addition
and
0 deletion
+176
-0
src/main/scala/xiangshan/frontend/uBTB.scala
src/main/scala/xiangshan/frontend/uBTB.scala
+176
-0
未找到文件。
src/main/scala/xiangshan/frontend/uBTB.scala
0 → 100644
浏览文件 @
8dc20ae0
package
xiangshan.frontend
import
chisel3._
import
chisel3.util._
import
xiangshan._
import
xiangshan.backend.ALUOpType
import
utils._
trait
MicroBTBPatameter
{
val
nWays
=
16
val
offsetSize
=
13
val
tagSize
=
VAddrBits
-
log2Ceil
(
PredictWidth
)
-
1
}
class
MicroBTB
extends
BasePredictor
with
MicroBTBPatameter
{
class
MicroBTBResp
extends
resp
{
val
targets
=
Vec
(
PredictWidth
,
ValidUndirectioned
(
UInt
(
VaddrBits
.
W
)))
val
takens
=
Vec
(
PredictWidth
,
Bool
())
val
isRVC
=
Vec
(
PredictWidth
,
Bool
())
val
isBr
=
Vec
(
PredictWidth
,
Bool
())
}
class
MicroBTBPredictMeta
extends
meta
{
val
writeWay
=
UInt
(
log2Ceil
(
nWays
).
W
)
val
hits
=
Vec
(
PredictWidth
,
Bool
())
}
val
out_meta
=
Wire
(
new
MicroBTBMeta
)
override
val
metaLen
=
out_meta
.
asUInt
.
getWidth
class
MicroBTBIO
extends
defaultBasePredictorIO
{
val
out
=
Output
(
new
MicroBTBResp
)
//
val
meta
=
Output
(
new
MicroBTBPredictMeta
)
}
val
io
=
IO
(
new
MicroBTBIO
)
def
getTag
(
pc
:
UInt
)
=
pc
>>
(
log2Ceil
(
PredictWidth
)
+
1
).
U
def
getBank
(
pc
:
UInt
)
=
pc
(
log2Ceil
(
PredictWidth
)
,
1
)
def
satUpdate
(
old
:
UInt
,
len
:
Int
,
taken
:
Bool
)
:
UInt
=
{
val
oldSatTaken
=
old
===
((
1
<<
len
)-
1
).
U
val
oldSatNotTaken
=
old
===
0.
U
Mux
(
oldSatTaken
&&
taken
,
((
1
<<
len
)-
1
).
U
,
Mux
(
oldSatNotTaken
&&
!
taken
,
0.
U
,
Mux
(
taken
,
old
+
1.
U
,
old
-
1.
U
)))
}
class
MicroBTBMeta
extends
XSBundle
{
val
is_Br
=
Bool
()
val
is_RVC
=
Bool
()
val
valid
=
Bool
()
val
pred
=
UInt
(
2.
W
)
val
tag
=
UInt
(
tagSize
.
W
)
}
class
MicroBTBEntry
extends
XSBundle
{
val
offset
=
SInt
(
offsetSize
.
W
)
}
val
uBTBMeta
=
RegInit
(
0.
U
).
asTypeOf
(
Vec
(
PredictWidth
,
Vec
(
nWays
,
new
MicroBTBMeta
)))
val
uBTB
=
Reg
(
Vec
(
PredictWidth
,
Vec
(
nWays
,
new
MicroBTBEntry
)))
//uBTB read
//tag is bank align
val
read_req_tag
=
getTag
(
io
.
pc
)
val
read_req_basebank
=
getBank
(
io
.
pc
)
val
read_mask
=
io
.
inMask
class
ReadRespEntry
extends
XSBundle
{
val
is_Br
=
Bool
()
val
is_RVC
=
Bool
()
val
target
=
UInt
(
VAddrBits
.
W
))
val
valid
=
Bool
()
val
taken
=
Bool
()
}
val
read_resp
=
Wire
(
Vec
(
PredictWidth
,
new
ReadRespEntry
))
val
read_hit_ohs
=
VecInit
((
0
until
PredictWidth
)
map
{
b
=>
VecInit
((
0
until
nWays
)
map
{
w
=>
uBTBMeta
(
b
)(
w
).
tag
===
read_req_tag
&&
uBTBMeta
(
b
)(
w
).
valid
})
})
val
read_hit_vec
=
read_hit_ohs
.
map
{
oh
=>
ParallelOR
(
oh
)}
val
read_hit_ways
=
read_hit_ohs
.
map
{
oh
=>
PriorityEncoder
(
oh
)}
val
read_hit
=
ParallelOR
(
read_hit_vec
)
val
read_hit_way
=
PriorityEncoder
(
ParallelOR
(
read_hit_vec
.
map
(
_
.
asUInt
)))
for
(
i
<-
0
until
PredictWidth
){
val
meta_resp
=
uBTBMeta
(
i
)(
read_hit_ways
(
i
))
val
btb_resp
=
uBTB
(
i
)(
read_hit_ways
(
i
))
read_resp
(
i
).
valid
:=
meta_resp
.
valid
&&
read_hit_vec
(
i
)
&&
read_mask
(
i
)
read_resp
(
i
).
taken
:=
read_resp
(
i
).
valid
&&
meta_resp
.
pred
(
1
)
read_resp
(
i
).
target
:=
((
io
.
in
.
pc
).
asSInt
+
(
w
<<
1
).
S
+
btb_resp
.
offset
out_meta
.
hits
(
i
)
:=
read_hit_vec
(
i
)
}
//TODO: way alloc algorithm
val
alloc_way
=
{
val
r_metas
=
Cat
(
VecInit
(
meta
.
map
(
e
=>
VecInit
(
e
.
map
(
_
.
tag
)))).
asUInt
,
s1_idx
(
tagSz
-
1
,
0
))
val
l
=
log2Ceil
(
nWays
)
val
nChunks
=
(
r_metas
.
getWidth
+
l
-
1
)
/
l
val
chunks
=
(
0
until
nChunks
)
map
{
i
=>
r_metas
(
min
((
i
+
1
)*
l
,
r_metas
.
getWidth
)-
1
,
i
*
l
)
}
chunks
.
reduce
(
_
^
_
)
}
val
out_meta
.
writeWay
=
Mux
(
read_hit
,
read_hit_way
,
alloc_way
)
//response
//only when hit and instruction valid and entry valid can output data
for
(
i
<-
0
until
PredictWidth
)
{
when
(
read_resp
(
i
).
valid
)
{
io
.
out
.
targets
(
i
)
:=
read_resp
(
i
).
target
io
.
out
.
taken
(
i
)
:=
read_resp
(
i
).
taken
io
.
out
.
isRVC
(
i
)
:=
read_resp
(
i
).
is_RVC
io
.
out
.
isBr
(
i
)
;
=
read_resp
(
i
).
is_Br
}
.
otherwise
{
io
.
out
:=
(
0.
U
).
asTypeOf
(
new
MicroBTBResp
)
}
}
//uBTB update
//backend should send fetch pc to update
val
update_fetch_pc
=
Wire
(
UInt
(
VAddrBits
.
W
))
//TODO: io.update.bitspc
val
update_idx
=
io
.
update
.
bitsfetchIdx
val
update_br_offset
=
update_idx
<<
1.
U
val
update_br_pc
=
update_fetch_pc
+
update_br_offset
val
update_write_way
=
io
.
update
.
bits
.
brInfo
.
ubtbWriteWay
val
update_hits
=
io
.
update
.
bits
.
brInfo
.
ubtbHits
val
update_taken
=
io
.
update
.
bits
.
taken
val
update_bank
=
getBank
(
update_br_pc
)
val
update_tag
=
getTag
(
update_br_pc
)
val
update_taget_offset
=
io
.
update
.
bits
.
target
.
asSInt
-
update_br_pc
.
asSInt
val
update_is_BR_or_JAL
=
(
io
.
update
.
bits
.
pd
.
brType
===
BrType
.
branch
)
||
(
io
.
update
.
bits
.
pd
.
brType
===
BrType
.
jal
)
val
uBTB_write_valid
=
io
.
update
.
valid
&&
io
.
update
.
bits
.
isMisPred
val
uBTB_Meta_write_valid
=
io
.
update
.
valid
&&
update_is_BR_or_JAL
//write btb target when miss prediction
when
(
uBTB_write_valid
)
{
uBTB
(
update_bank
)(
update_write_way
).
offset
:=
update_taget_offset
}
//write the meta
when
(
uBTB_Meta_write_valid
)
{
//commit update
uBTBMeta
(
update_bank
)(
update_write_way
).
is_Br
:=
io
.
update
.
bits
.
pd
.
brType
===
BrType
.
branch
uBTBMeta
(
update_bank
)(
update_write_way
).
is_RVC
:=
io
.
update
.
bits
.
pd
.
isRVC
uBTBMeta
(
update_bank
)(
update_write_way
).
valid
:=
true
.
B
uBTBMeta
(
update_bank
)(
update_write_way
).
tag
:=
update_tag
uBTBMeta
(
update_bank
)(
update_write_way
).
pred
:=
Mux
(!
update_hits
(
update_bank
),
Mux
(
update_taken
,
3.0
,
0.
U
)
satUpdate
(
uBTBMeta
(
update_bank
)(
update_write_way
).
pred
,
2
,
update_taken
)
)
}
//bypass:read-after-write
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录