Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
NEMU
提交
2270af0b
N
NEMU
项目概览
OpenXiangShan
/
NEMU
11 个月 前同步成功
通知
7
Star
171
Fork
67
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NEMU
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2270af0b
编写于
3月 31, 2020
作者:
Z
Zihao Yu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'rv64-tb' into 'master'
Rv64 tb See merge request projectn/nemu!47
上级
ce129b6b
3366b609
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
123 addition
and
26 deletion
+123
-26
src/engine/rv64/rv64-backend/exec.c
src/engine/rv64/rv64-backend/exec.c
+3
-3
src/engine/rv64/tran.c
src/engine/rv64/tran.c
+120
-23
未找到文件。
src/engine/rv64/rv64-backend/exec.c
浏览文件 @
2270af0b
...
...
@@ -12,14 +12,14 @@ void backend_exec_code(uint64_t pc, int nr_instr) {
backend_exec
(
nr_instr
);
}
vaddr_t
rv64_exec_trans_buffer
(
void
*
buf
,
int
nr_instr
)
{
vaddr_t
rv64_exec_trans_buffer
(
void
*
buf
,
int
nr_instr
,
int
npc_type
)
{
// copy code to rv64 interpreter to execute it
backend_memcpy_from_frontend
(
RV64_EXEC_PC
-
riscv64_PMEM_BASE
,
buf
,
sizeof
(
uint32_t
)
*
nr_instr
);
// if the basic block is end with a branch instruction,
// execute until the branch instruction
// see rtl_jrelop() at rtl-basic.c
int
nr_exec
=
(
tran_next_pc
==
NEXT_PC_BRANCH
?
nr_instr
-
5
:
nr_instr
);
int
nr_exec
=
(
npc_type
==
NEXT_PC_BRANCH
?
nr_instr
-
5
:
nr_instr
);
backend_exec_code
(
RV64_EXEC_PC
,
nr_exec
);
riscv64_CPU_state
r
;
...
...
@@ -31,7 +31,7 @@ vaddr_t rv64_exec_trans_buffer(void *buf, int nr_instr) {
backend_getregs
(
&
r
);
}
if
(
tran_next_pc
==
NEXT_PC_BRANCH
)
{
if
(
npc_type
==
NEXT_PC_BRANCH
)
{
// execute the branch instruction and load x86.pc to x30
backend_exec
(
3
);
backend_getregs
(
&
r
);
...
...
src/engine/rv64/tran.c
浏览文件 @
2270af0b
...
...
@@ -13,9 +13,72 @@ int tran_next_pc = NEXT_PC_SEQ;
static
void
clear_trans_buffer
()
{
trans_buffer_index
=
0
;
}
void
asm_print
(
vaddr_t
ori_pc
,
int
instr_len
,
bool
print_flag
);
vaddr_t
rv64_exec_trans_buffer
(
void
*
buf
,
int
nr_instr
);
vaddr_t
rv64_exec_trans_buffer
(
void
*
buf
,
int
nr_instr
,
int
npc_type
);
void
guest_getregs
(
CPU_state
*
cpu
);
typedef
struct
TB
{
vaddr_t
pc
;
int
npc_type
;
vaddr_t
npc
;
void
*
code
;
uint32_t
nr_instr
;
uint32_t
guest_nr_instr
;
uint32_t
hit_time
;
struct
TB
*
next
;
}
TB
;
static
TB
head
=
{
.
next
=
NULL
};
static
TB
*
find_tb
(
vaddr_t
pc
)
{
TB
*
tb
;
for
(
tb
=
head
.
next
;
tb
!=
NULL
;
tb
=
tb
->
next
)
{
if
(
tb
->
pc
==
pc
)
return
tb
;
}
return
NULL
;
}
static
int
find_top10_min
(
TB
**
top
,
int
n
)
{
int
i
;
int
min
=
0
;
for
(
i
=
1
;
i
<
n
;
i
++
)
{
if
(
top
[
i
]
->
hit_time
<
top
[
min
]
->
hit_time
)
min
=
i
;
}
return
min
;
}
static
TB
**
find_top10_tb
()
{
static
TB
*
top
[
10
];
TB
*
p
=
head
.
next
;;
int
i
;
for
(
i
=
0
;
i
<
10
;
i
++
)
{
assert
(
p
!=
NULL
);
top
[
i
]
=
p
;
p
=
p
->
next
;
}
int
min
=
find_top10_min
(
top
,
10
);
for
(;
p
!=
NULL
;
p
=
p
->
next
)
{
if
(
p
->
hit_time
>
top
[
min
]
->
hit_time
)
{
top
[
min
]
=
p
;
min
=
find_top10_min
(
top
,
10
);
}
}
for
(
i
=
0
;
i
<
10
;
i
++
)
{
int
max
=
i
;
int
j
;
for
(
j
=
i
+
1
;
j
<
10
;
j
++
)
{
if
(
top
[
max
]
->
hit_time
<
top
[
j
]
->
hit_time
)
max
=
j
;
}
if
(
max
!=
i
)
{
TB
*
tmp
=
top
[
i
];
top
[
i
]
=
top
[
max
];
top
[
max
]
=
tmp
;
}
}
return
top
;
}
void
write_ins
(
uint32_t
ins
)
{
assert
(
trans_buffer_index
<
BUF_SIZE
);
trans_buffer
[
trans_buffer_index
++
]
=
ins
;
...
...
@@ -25,44 +88,78 @@ void mainloop() {
nemu_state
.
state
=
NEMU_RUNNING
;
uint64_t
total_instr
=
0
;
while
(
1
)
{
__attribute__
((
unused
))
vaddr_t
ori_pc
=
cpu
.
pc
;
__attribute__
((
unused
))
vaddr_t
seq_pc
=
isa_exec_once
();
vaddr_t
tb_start
=
cpu
.
pc
;
TB
*
tb
=
find_tb
(
tb_start
);
if
(
tb
==
NULL
)
{
clear_trans_buffer
();
tran_next_pc
=
NEXT_PC_SEQ
;
int
guest_nr_instr
=
0
;
while
(
1
)
{
__attribute__
((
unused
))
vaddr_t
ori_pc
=
cpu
.
pc
;
__attribute__
((
unused
))
vaddr_t
seq_pc
=
isa_exec_once
();
guest_nr_instr
++
;
if
(
nemu_state
.
state
!=
NEMU_RUNNING
)
tran_next_pc
=
NEXT_PC_END
;
if
(
nemu_state
.
state
!=
NEMU_RUNNING
)
tran_next_pc
=
NEXT_PC_END
;
#ifdef DEBUG
asm_print
(
ori_pc
,
seq_pc
-
ori_pc
,
true
);
asm_print
(
ori_pc
,
seq_pc
-
ori_pc
,
true
);
#endif
#ifndef DIFF_TEST
if
(
tran_next_pc
!=
NEXT_PC_SEQ
)
{
#ifdef DIFF_TEST
if
(
true
)
#else
if
(
tran_next_pc
!=
NEXT_PC_SEQ
)
#endif
vaddr_t
next_pc
=
rv64_exec_trans_buffer
(
trans_buffer
,
trans_buffer_index
);
total_instr
+=
trans_buffer_index
;
{
tb
=
malloc
(
sizeof
(
TB
));
tb
->
pc
=
tb_start
;
tb
->
nr_instr
=
trans_buffer_index
;
tb
->
guest_nr_instr
=
guest_nr_instr
;
tb
->
code
=
malloc
(
tb
->
nr_instr
*
4
);
memcpy
(
tb
->
code
,
trans_buffer
,
tb
->
nr_instr
*
4
);
tb
->
npc_type
=
tran_next_pc
;
tb
->
npc
=
cpu
.
pc
;
tb
->
hit_time
=
0
;
tb
->
next
=
head
.
next
;
head
.
next
=
tb
;
break
;
}
}
}
if
(
tran_next_pc
==
NEXT_PC_END
)
{
// get cpu.eax and interpret `nemu_trap` again
guest_getregs
(
&
cpu
);
cpu
.
pc
=
ori_pc
;
//Log("enter tb with pc = %x, nr_instr = %d", tb->pc, tb->nr_instr);
vaddr_t
next_pc
=
rv64_exec_trans_buffer
(
tb
->
code
,
tb
->
nr_instr
,
tb
->
npc_type
);
total_instr
+=
tb
->
nr_instr
;
tb
->
hit_time
++
;
if
(
tb
->
npc_type
==
NEXT_PC_END
)
{
// get cpu.eax and interpret `nemu_trap` again
guest_getregs
(
&
cpu
);
cpu
.
pc
=
tb_start
;
nemu_state
.
state
=
NEMU_RUNNING
;
while
(
nemu_state
.
state
==
NEMU_RUNNING
)
{
isa_exec_once
();
break
;
}
if
(
tran_next_pc
!=
NEXT_PC_SEQ
)
cpu
.
pc
=
next_pc
;
// Log("new basic block pc = %x", cpu.pc);
clear_trans_buffer
();
tran_next_pc
=
NEXT_PC_SEQ
;
#ifndef DIFF_TEST
break
;
}
#endif
if
(
tb
->
npc_type
!=
NEXT_PC_SEQ
)
cpu
.
pc
=
next_pc
;
else
cpu
.
pc
=
tb
->
npc
;
#ifdef DIFF_TEST
guest_getregs
(
&
cpu
);
difftest_step
(
ori_pc
,
cpu
.
pc
);
difftest_step
(
tb_start
,
cpu
.
pc
);
if
(
nemu_state
.
state
==
NEMU_ABORT
)
break
;
#endif
}
// display the top-10 hot basic block
TB
**
top
=
find_top10_tb
();
int
i
;
for
(
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%2d: pc = "
FMT_WORD
"(instr: %d -> %d),
\t
hit time = %d
\n
"
,
i
+
1
,
top
[
i
]
->
pc
,
top
[
i
]
->
guest_nr_instr
,
top
[
i
]
->
nr_instr
,
top
[
i
]
->
hit_time
);
}
switch
(
nemu_state
.
state
)
{
case
NEMU_RUNNING
:
nemu_state
.
state
=
NEMU_STOP
;
break
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录