Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
NEMU
提交
9a677dac
N
NEMU
项目概览
OpenXiangShan
/
NEMU
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
9a677dac
编写于
4月 20, 2020
作者:
Z
Zihao Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
engine,rv64: remove unused code
上级
b51f5e5a
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
18 addition
and
123 deletion
+18
-123
src/engine/rv64/init.c
src/engine/rv64/init.c
+2
-0
src/engine/rv64/isa/mips32.c
src/engine/rv64/isa/mips32.c
+1
-8
src/engine/rv64/rv64-backend/exec.c
src/engine/rv64/rv64-backend/exec.c
+0
-5
src/engine/rv64/rv64-backend/rtl-basic.c
src/engine/rv64/rv64-backend/rtl-basic.c
+10
-54
src/engine/rv64/spill.c
src/engine/rv64/spill.c
+3
-44
src/engine/rv64/spill.h
src/engine/rv64/spill.h
+0
-5
src/engine/rv64/tran.c
src/engine/rv64/tran.c
+2
-7
未找到文件。
src/engine/rv64/init.c
浏览文件 @
9a677dac
...
...
@@ -12,6 +12,7 @@ void (*backend_exec)(uint64_t n) = NULL;
void
backend_exec_code
(
uint64_t
pc
,
int
nr_instr
);
void
guest_setregs
(
const
CPU_state
*
cpu
);
void
spill_init
();
static
void
init_rv64_interpreter
()
{
char
so_file
[
256
];
...
...
@@ -86,4 +87,5 @@ void init_engine() {
backend_exec_code
(
riscv64_PMEM_BASE
,
100
);
guest_setregs
(
&
cpu
);
init_rv64_reg
();
spill_init
();
}
src/engine/rv64/isa/mips32.c
浏览文件 @
9a677dac
...
...
@@ -41,14 +41,7 @@ int rtlreg_is_spm(DecodeExecState *s, const rtlreg_t* dest) {
uint32_t
rtlreg2rvidx
(
DecodeExecState
*
s
,
const
rtlreg_t
*
dest
)
{
uint32_t
varidx
=
rtlreg2varidx
(
s
,
dest
);
if
(
!
(
varidx
&
SPMIDX_MASK
))
return
varidx
;
uint32_t
spmidx
=
varidx
;
uint32_t
rvidx
=
spmidx2rvidx
(
spmidx
);
// if `dest` is already mapped, just return the corresponding rvidx
if
(
rvidx
)
return
rvidx
;
// if `dest` is not mapped, spill out one tmp_reg and remap
return
spill_out_and_remap
(
s
,
spmidx
);
assert
(
0
);
}
void
guest_getregs
(
CPU_state
*
mips32
)
{
...
...
src/engine/rv64/rv64-backend/exec.c
浏览文件 @
9a677dac
#include <isa/riscv64.h>
#include "../tran.h"
#include "../spill.h"
#define RV64_EXEC_PC (riscv64_PMEM_BASE + BBL_MAX_SIZE) // skip bbl
...
...
@@ -38,9 +37,5 @@ vaddr_t rv64_exec_trans_buffer(void *buf, int nr_instr, int npc_type) {
backend_getregs
(
&
r
);
}
#ifdef REG_SPILLING
tmp_regs_reset
();
#endif
return
r
.
gpr
[
tmp0
].
_64
;
}
src/engine/rv64/rv64-backend/rtl-basic.c
浏览文件 @
9a677dac
...
...
@@ -7,9 +7,6 @@ void rv64_relop(uint32_t relop, uint32_t idx_dest, uint32_t idx_src1, uint32_t i
uint32_t
rtlreg2rvidx
(
DecodeExecState
*
s
,
const
rtlreg_t
*
dest
);
uint32_t
dest2rvidx
(
DecodeExecState
*
s
,
const
rtlreg_t
*
dest
);
uint32_t
src2rvidx
(
DecodeExecState
*
s
,
const
rtlreg_t
*
src
);
#ifdef REG_SPILLING
uint32_t
rtlreg2varidx
(
DecodeExecState
*
s
,
const
rtlreg_t
*
dest
);
#endif
static
inline
void
rv64_zextw
(
uint32_t
rd
,
uint32_t
rs
)
{
// mask32 is set during initialization
...
...
@@ -59,7 +56,6 @@ static inline void load_imm_no_opt(uint32_t r, const sword_t imm) {
/* RTL basic instructions */
#ifdef REG_SPILLING
#define make_rtl_compute_reg(rtl_name, rv64_name) \
make_rtl(rtl_name, rtlreg_t* dest, const rtlreg_t* src1, const rtlreg_t* src2) { \
uint32_t ret = rtlreg2rvidx_pair(s, src1, true, src2, true); \
...
...
@@ -68,15 +64,6 @@ static inline void load_imm_no_opt(uint32_t r, const sword_t imm) {
uint32_t dest_rvidx = dest2rvidx(s, dest); \
concat(rv64_, rv64_name) (dest_rvidx, src1_rvidx, src2_rvidx); \
}
#else
#define make_rtl_compute_reg(rtl_name, rv64_name) \
make_rtl(rtl_name, rtlreg_t* dest, const rtlreg_t* src1, const rtlreg_t* src2) { \
uint32_t dest_rvidx = rtlreg2rvidx(s, dest); \
uint32_t src1_rvidx = rtlreg2rvidx(s, src1); \
uint32_t src2_rvidx = rtlreg2rvidx(s, src2); \
concat(rv64_, rv64_name) (dest_rvidx, src1_rvidx, src2_rvidx); \
}
#endif
#define make_rtl_compute_imm(rtl_name, rv64_name) \
make_rtl(rtl_name, rtlreg_t* dest, const rtlreg_t* src1, const sword_t imm) { \
...
...
@@ -131,7 +118,6 @@ make_rtl_compute_imm(shri, srliw)
make_rtl_compute_imm
(
sari
,
sraiw
)
#endif
#ifdef REG_SPILLING
make_rtl
(
setrelop
,
uint32_t
relop
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
rtlreg_t
*
src2
)
{
uint32_t
ret
=
rtlreg2rvidx_pair
(
s
,
src1
,
true
,
src2
,
true
);
uint32_t
src1_rvidx
=
ret
>>
16
;
...
...
@@ -139,14 +125,6 @@ make_rtl(setrelop, uint32_t relop, rtlreg_t *dest, const rtlreg_t *src1, const r
uint32_t
dest_rvidx
=
dest2rvidx
(
s
,
dest
);
rv64_relop
(
relop
,
dest_rvidx
,
src1_rvidx
,
src2_rvidx
);
}
#else
make_rtl
(
setrelop
,
uint32_t
relop
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
rtlreg_t
*
src2
)
{
uint32_t
dest_rvidx
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
src1_rvidx
=
rtlreg2rvidx
(
s
,
src1
);
uint32_t
src2_rvidx
=
rtlreg2rvidx
(
s
,
src2
);
rv64_relop
(
relop
,
dest_rvidx
,
src1_rvidx
,
src2_rvidx
);
}
#endif
make_rtl
(
setrelopi
,
uint32_t
relop
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
sword_t
imm
)
{
int
big_imm
=
load_imm_big
(
tmp0
,
imm
);
...
...
@@ -181,7 +159,6 @@ make_rtl_compute_reg(idiv_r, remw)
# define rv64_imul_hi(c, a, b) TODO()
#else
#ifdef REG_SPILLING
make_rtl
(
mul_hi
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
rtlreg_t
*
src2
)
{
uint32_t
ret
=
rtlreg2rvidx_pair
(
s
,
src1
,
true
,
src2
,
true
);
uint32_t
src1_rvidx
=
ret
>>
16
;
...
...
@@ -203,33 +180,12 @@ make_rtl(imul_hi, rtlreg_t* dest, const rtlreg_t* src1, const rtlreg_t* src2) {
rv64_mul
(
dest_rvidx
,
src1_rvidx
,
src2_rvidx
);
rv64_srai
(
dest_rvidx
,
dest_rvidx
,
32
);
}
#else
make_rtl
(
mul_hi
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
rtlreg_t
*
src2
)
{
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1
=
rtlreg2rvidx
(
s
,
src1
);
uint32_t
idx_src2
=
rtlreg2rvidx
(
s
,
src2
);
rv64_zextw
(
idx_src1
,
idx_src1
);
rv64_zextw
(
idx_src2
,
idx_src2
);
rv64_mul
(
idx_dest
,
idx_src1
,
idx_src2
);
rv64_srai
(
idx_dest
,
idx_dest
,
32
);
}
make_rtl
(
imul_hi
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1
,
const
rtlreg_t
*
src2
)
{
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1
=
rtlreg2rvidx
(
s
,
src1
);
uint32_t
idx_src2
=
rtlreg2rvidx
(
s
,
src2
);
rv64_sextw
(
idx_src1
,
idx_src1
);
rv64_sextw
(
idx_src2
,
idx_src2
);
rv64_mul
(
idx_dest
,
idx_src1
,
idx_src2
);
rv64_srai
(
idx_dest
,
idx_dest
,
32
);
}
#endif
#endif
make_rtl
(
div64_q
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1_hi
,
const
rtlreg_t
*
src1_lo
,
const
rtlreg_t
*
src2
)
{
#if
def REG_SPILLING
panic
(
"
If reg-spilling enabled, you should not use div64 rtl!
\n
"
);
#if
ndef __ISA_x86__
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1_hi
=
rtlreg2rvidx
(
s
,
src1_hi
);
...
...
@@ -245,8 +201,8 @@ make_rtl(div64_q, rtlreg_t* dest,
make_rtl
(
div64_r
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1_hi
,
const
rtlreg_t
*
src1_lo
,
const
rtlreg_t
*
src2
)
{
#if
def REG_SPILLING
panic
(
"
If reg-spilling enabled, you should not use div64 rtl!
\n
"
);
#if
ndef __ISA_x86__
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1_hi
=
rtlreg2rvidx
(
s
,
src1_hi
);
...
...
@@ -262,8 +218,8 @@ make_rtl(div64_r, rtlreg_t* dest,
make_rtl
(
idiv64_q
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1_hi
,
const
rtlreg_t
*
src1_lo
,
const
rtlreg_t
*
src2
)
{
#if
def REG_SPILLING
panic
(
"
If reg-spilling enabled, you should not use div64 rtl!
\n
"
);
#if
ndef __ISA_x86__
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1_hi
=
rtlreg2rvidx
(
s
,
src1_hi
);
...
...
@@ -279,8 +235,8 @@ make_rtl(idiv64_q, rtlreg_t* dest,
make_rtl
(
idiv64_r
,
rtlreg_t
*
dest
,
const
rtlreg_t
*
src1_hi
,
const
rtlreg_t
*
src1_lo
,
const
rtlreg_t
*
src2
)
{
#if
def REG_SPILLING
panic
(
"
If reg-spilling enabled, you should not use div64 rtl!
\n
"
);
#if
ndef __ISA_x86__
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
uint32_t
idx_src1_hi
=
rtlreg2rvidx
(
s
,
src1_hi
);
...
...
@@ -348,7 +304,7 @@ make_rtl(sm, const rtlreg_t* addr, const sword_t imm, const rtlreg_t* src1, int
make_rtl
(
host_lm
,
rtlreg_t
*
dest
,
const
void
*
addr
,
int
len
)
{
#ifndef __ISA_x86__
panic
(
"
should not reach here
"
);
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_dest
=
rtlreg2rvidx
(
s
,
dest
);
...
...
@@ -375,7 +331,7 @@ make_rtl(host_lm, rtlreg_t* dest, const void *addr, int len) {
make_rtl
(
host_sm
,
void
*
addr
,
const
rtlreg_t
*
src1
,
int
len
)
{
#ifndef __ISA_x86__
panic
(
"
should not reach here
"
);
panic
(
"
only used in x86
\n
"
);
#endif
uint32_t
idx_src1
=
rtlreg2rvidx
(
s
,
src1
);
...
...
src/engine/rv64/spill.c
浏览文件 @
9a677dac
...
...
@@ -6,22 +6,20 @@
typedef
struct
{
uint32_t
rvidx
;
uint32_t
spmidx
;
bool
used
,
dirty
;
bool
dirty
;
}
Tmp_reg
;
static
Tmp_reg
tmp_regs
[
TMP_REG_NUM
];
void
tmp_regs
_init
()
{
void
spill
_init
()
{
assert
(
TMP_REG_NUM
==
2
);
tmp_regs
[
0
].
rvidx
=
TMP_REG_1
;
tmp_regs
[
1
].
rvidx
=
TMP_REG_2
;
}
void
tmp_regs
_reset
()
{
void
spill
_reset
()
{
tmp_regs
[
0
].
spmidx
=
0
;
tmp_regs
[
0
].
used
=
0
;
tmp_regs
[
0
].
dirty
=
0
;
tmp_regs
[
1
].
spmidx
=
0
;
tmp_regs
[
1
].
used
=
0
;
tmp_regs
[
1
].
dirty
=
0
;
}
...
...
@@ -42,7 +40,6 @@ int rvidx2tmpidx(uint32_t rvidx) {
uint32_t
spmidx2rvidx
(
uint32_t
spmidx
)
{
int
tmpidx
=
spmidx2tmpidx
(
spmidx
);
if
(
tmpidx
==
-
1
)
return
0
;
tmp_regs
[
tmpidx
].
used
=
1
;
return
tmp_regs
[
tmpidx
].
rvidx
;
}
...
...
@@ -66,28 +63,12 @@ void spill_writeback_all() { // can be 0/1/2 inst
}
}
void
spill_flush
(
uint32_t
spmidx
)
{
for
(
int
i
=
0
;
i
<
TMP_REG_NUM
;
i
++
)
{
if
(
tmp_regs
[
i
].
spmidx
==
spmidx
)
{
tmp_regs
[
i
].
used
=
0
;
return
;
}
}
}
void
spill_flush_all
()
{
for
(
int
i
=
0
;
i
<
TMP_REG_NUM
;
i
++
)
{
tmp_regs
[
i
].
used
=
0
;
}
}
// replace tmp_regs[tmpidx] with spmidx
void
spill_replace
(
uint32_t
tmpidx
,
uint32_t
spmidx
,
int
load_val
)
{
spill_writeback
(
tmpidx
);
if
(
load_val
)
spm
(
lw
,
tmp_regs
[
tmpidx
].
rvidx
,
4
*
(
spmidx
&
~
SPMIDX_MASK
));
tmp_regs
[
tmpidx
].
spmidx
=
spmidx
;
tmp_regs
[
tmpidx
].
used
=
1
;
tmp_regs
[
tmpidx
].
dirty
=
false
;
}
...
...
@@ -157,28 +138,6 @@ uint32_t rtlreg2rvidx_pair(DecodeExecState *s,
return
(
src1_varidx
<<
16
)
|
src2_varidx
;
}
uint32_t
spill_out_and_remap
(
DecodeExecState
*
s
,
uint32_t
spmidx
)
{
int
tmpidx
;
for
(
tmpidx
=
0
;
tmpidx
<
TMP_REG_NUM
;
tmpidx
++
)
{
if
(
tmp_regs
[
tmpidx
].
used
==
0
)
break
;
}
Assert
(
tmpidx
<
TMP_REG_NUM
,
"no clean tmp_regs!
\n
already used:%u %u, req: %u
\n
"
,
tmp_regs
[
0
].
spmidx
,
tmp_regs
[
1
].
spmidx
,
spmidx
);
spill_writeback
(
tmpidx
);
spm
(
lw
,
tmp_regs
[
tmpidx
].
rvidx
,
4
*
(
spmidx
&
~
SPMIDX_MASK
));
tmp_regs
[
tmpidx
].
spmidx
=
spmidx
;
tmp_regs
[
tmpidx
].
used
=
1
;
tmp_regs
[
tmpidx
].
dirty
=
false
;
return
tmp_regs
[
tmpidx
].
rvidx
;
}
void
spill_set_spmidx
(
uint32_t
tmpidx
,
uint32_t
new_spmidx
)
{
tmp_regs
[
tmpidx
].
spmidx
=
new_spmidx
;
}
void
spill_set_dirty
(
uint32_t
tmpidx
)
{
tmp_regs
[
tmpidx
].
dirty
=
true
;
}
...
...
src/engine/rv64/spill.h
浏览文件 @
9a677dac
...
...
@@ -8,13 +8,8 @@
// default is $26, $27, which has low perf loss
#define TMP_REG_1 26
#define TMP_REG_2 27
#define TMP_REG_NUM 2
#define TMPIDX_CNT 9
#define TMP_REG_MAX 233
void
tmp_regs_init
();
void
tmp_regs_reset
();
uint32_t
spmidx2rvidx
(
uint32_t
);
uint32_t
spill_out_and_remap
(
DecodeExecState
*
,
uint32_t
);
void
spill_flush
(
uint32_t
);
...
...
src/engine/rv64/tran.c
浏览文件 @
9a677dac
...
...
@@ -4,7 +4,6 @@
#include <isa.h>
#include <monitor/difftest.h>
#include "tran.h"
#include "spill.h"
#define TOP_N 10
//#define DUMP_RV64
...
...
@@ -18,6 +17,7 @@ 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
,
int
npc_type
);
void
guest_getregs
(
CPU_state
*
cpu
);
void
spill_reset
();
typedef
struct
TB
{
vaddr_t
pc
;
...
...
@@ -88,9 +88,6 @@ void write_ins(uint32_t ins) {
}
void
mainloop
()
{
#ifdef REG_SPILLING
tmp_regs_init
();
#endif
nemu_state
.
state
=
NEMU_RUNNING
;
uint64_t
total_instr
=
0
;
while
(
1
)
{
...
...
@@ -98,15 +95,13 @@ void mainloop() {
TB
*
tb
=
find_tb
(
tb_start
);
if
(
tb
==
NULL
)
{
clear_trans_buffer
();
spill_reset
();
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
++
;
#ifdef REG_SPILLING
spill_flush_all
();
#endif
if
(
nemu_state
.
state
!=
NEMU_RUNNING
)
tran_next_pc
=
NEXT_PC_END
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录