Skip to content

Commit e8a7ae1

Browse files
committed
Use mapping for sp reg name
1 parent 3ac4309 commit e8a7ae1

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

model/riscv_insts_zca.sail

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ function clause execute (C_LWSP(uimm, rd)) = {
418418
}
419419

420420
mapping clause assembly = C_LWSP(uimm, rd)
421-
<-> "c.lwsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
421+
<-> "c.lwsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
422422
when rd != zreg
423423

424424
/* ****************************************************************** */
@@ -434,7 +434,7 @@ function clause execute (C_LDSP(uimm, rd)) = {
434434
}
435435

436436
mapping clause assembly = C_LDSP(uimm, rd)
437-
<-> "c.ldsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
437+
<-> "c.ldsp" ^ spc() ^ reg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
438438
when rd != zreg & xlen == 64
439439

440440
/* ****************************************************************** */
@@ -450,7 +450,7 @@ function clause execute (C_SWSP(uimm, rs2)) = {
450450
}
451451

452452
mapping clause assembly = C_SWSP(uimm, rs2)
453-
<-> "c.swsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
453+
<-> "c.swsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
454454

455455
/* ****************************************************************** */
456456
union clause ast = C_SDSP : (bits(6), regidx)
@@ -465,7 +465,7 @@ function clause execute (C_SDSP(uimm, rs2)) = {
465465
}
466466

467467
mapping clause assembly = C_SDSP(uimm, rs2)
468-
<-> "c.sdsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
468+
<-> "c.sdsp" ^ spc() ^ reg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
469469
when xlen == 64
470470

471471
/* ****************************************************************** */

model/riscv_insts_zcd.sail

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function clause execute (C_FLDSP(uimm, rd)) = {
2121

2222
mapping clause assembly = C_FLDSP(uimm, rd)
2323
if (xlen == 32 | xlen == 64)
24-
<-> "c.fldsp" ^ spc() ^ freg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
24+
<-> "c.fldsp" ^ spc() ^ freg_name(rd) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
2525
if (xlen == 32 | xlen == 64)
2626

2727
/* ****************************************************************** */
@@ -38,7 +38,7 @@ function clause execute (C_FSDSP(uimm, rs2)) = {
3838

3939
mapping clause assembly = C_FSDSP(uimm, rs2)
4040
if (xlen == 32 | xlen == 64)
41-
<-> "c.fsdsp" ^ spc() ^ freg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
41+
<-> "c.fsdsp" ^ spc() ^ freg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
4242
if (xlen == 32 | xlen == 64)
4343

4444
/* ****************************************************************** */

model/riscv_insts_zcf.sail

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function clause execute (C_FLWSP(imm, rd)) = {
2020
}
2121

2222
mapping clause assembly = C_FLWSP(imm, rd)
23-
<-> "c.flwsp" ^ spc() ^ freg_name(rd) ^ sep() ^ hex_bits_6(imm) ^ "(" ^ reg_name_func(sp) ^ ")"
23+
<-> "c.flwsp" ^ spc() ^ freg_name(rd) ^ sep() ^ hex_bits_6(imm) ^ "(" ^ sp_reg_name() ^ ")"
2424
when xlen == 32
2525

2626
/* ****************************************************************** */
@@ -36,7 +36,7 @@ function clause execute (C_FSWSP(uimm, rs2)) = {
3636
}
3737

3838
mapping clause assembly = C_FSWSP(uimm, rs2)
39-
<-> "c.fswsp" ^ spc() ^ freg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ reg_name_func(sp) ^ ")"
39+
<-> "c.fswsp" ^ spc() ^ freg_name(rs2) ^ sep() ^ hex_bits_6(uimm) ^ "(" ^ sp_reg_name() ^ ")"
4040
when xlen == 32
4141

4242
/* ****************************************************************** */

model/riscv_regs.sail

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ mapping reg_name : regidx <-> string = {
8888
Regidx(i) if not(get_config_use_abi_names()) <-> reg_arch_name_raw(i),
8989
}
9090

91-
function reg_name_func(reg: regidx) -> string = reg_name(reg)
91+
// Special mapping for the sp register for use in assembly for sp-relative
92+
// instructions where the argument *must* be `sp` (or `x2`).
93+
mapping sp_reg_name : unit <-> string = {
94+
() if get_config_use_abi_names() <-> "sp" ,
95+
() if not(get_config_use_abi_names()) <-> "x2" ,
96+
}
9297

9398
mapping creg_name_raw : bits(3) <-> string = {
9499
0b000 <-> "s0",

0 commit comments

Comments
 (0)