Skip to content

Commit d80d443

Browse files
committed
RISC-V: Add complex implications from 'C'+'[DF]'
The 'C' extension and its subsets have complex relations, depending on the implemented floating point extensions. They are the expansions related in this context: 'C' == 'Zca' 'C' + 'F' == 'Zca' + 'Zcf' + 'F' (RV32) 'C' + 'F' == 'Zca' + 'F' (RV64) 'C' + 'F' + 'D' == 'Zca' + 'Zcf' + 'Zcd' + 'F' + 'D' (RV32) 'C' + 'F' + 'D' == 'Zca' + 'Zcd' + 'F' + 'D' (RV64) [they exclude dependencies from 'F' and 'D'] This commit implements those implications. Note that some test cases are modified to reflect new compressed instruction extensions: 1. Test cases that use ".option arch, -c" to turn off RVC (at least the 'Zca' extension must be also turned off). 2. Test cases that test RISC-V attributes and/or mapping symbols when the 'C' extension is enabled. bfd/ChangeLog: * elfxx-riscv.c (check_implicit_for_d_c): New. (check_implicit_for_f_c): New. (riscv_implicit_subsets): Add unconditional implication, 'C' -> 'Zca'. Add conditional implications, 'D' -> 'Zcd' and 'F' -> 'Zcf'. gas/ChangeLog: * testsuite/gas/riscv/march-imply-c.d: Test implied extensions from 'C' alone. * testsuite/gas/riscv/march-imply-c-d-32.d: New to test implied extensions from 'C' and 'D' on RV32. * testsuite/gas/riscv/march-imply-c-d-64.d: New to test implied extensions from 'C' and 'D' on RV64. * testsuite/gas/riscv/attribute-10.d: Reflect reorganization of compressed instruction extensions. * testsuite/gas/riscv/dis-addr-overflow-32.d: Likewise. * testsuite/gas/riscv/dis-addr-overflow-64.d: Likewise. * testsuite/gas/riscv/dis-addr-overflow.s: Likewise. * testsuite/gas/riscv/mapping-symbols.d: Likewise. * testsuite/gas/riscv/mapping.s: Likewise. * testsuite/gas/riscv/march-ok-reorder.d: Likewise. * testsuite/gas/riscv/option-arch-01.s: Likewise. * testsuite/gas/riscv/option-arch-01b.d: Likewise. * testsuite/gas/riscv/option-arch-02.d: Likewise. * testsuite/gas/riscv/option-arch-02.s: Likewise. * testsuite/gas/riscv/option-arch-03.d: Likewise. * testsuite/gas/riscv/option-arch-03.s: Likewise.
1 parent d9ff178 commit d80d443

17 files changed

+96
-50
lines changed

bfd/elfxx-riscv.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,29 @@ check_implicit_for_i (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
10991099
&& subset->minor_version < 1));
11001100
}
11011101

1102+
/* Add the IMPLICIT only when the 'C' extension is also available. */
1103+
1104+
static bool
1105+
check_implicit_for_d_c (riscv_parse_subset_t *rps,
1106+
const riscv_implicit_subset_t *implicit
1107+
ATTRIBUTE_UNUSED,
1108+
const riscv_subset_t *subset ATTRIBUTE_UNUSED)
1109+
{
1110+
return riscv_subset_supports (rps, "c");
1111+
}
1112+
1113+
/* Add the IMPLICIT only when the 'C' extension is also available
1114+
and XLEN is 32. */
1115+
1116+
static bool
1117+
check_implicit_for_f_c (riscv_parse_subset_t *rps,
1118+
const riscv_implicit_subset_t *implicit
1119+
ATTRIBUTE_UNUSED,
1120+
const riscv_subset_t *subset ATTRIBUTE_UNUSED)
1121+
{
1122+
return *rps->xlen == 32 && check_implicit_for_d_c (rps, implicit, subset);
1123+
}
1124+
11021125
/* All extension implications. */
11031126

11041127
static riscv_implicit_subset_t riscv_implicit_subsets[] =
@@ -1188,6 +1211,7 @@ static riscv_implicit_subset_t riscv_implicit_subsets[] =
11881211
{"zvksg", "zvkg", check_implicit_always},
11891212
{"zvksc", "zvks", check_implicit_always},
11901213
{"zvksc", "zvbc", check_implicit_always},
1214+
{"c", "zca", check_implicit_always},
11911215
{"zcf", "zca", check_implicit_always},
11921216
{"zcd", "zca", check_implicit_always},
11931217
{"zcb", "zca", check_implicit_always},
@@ -1198,6 +1222,10 @@ static riscv_implicit_subset_t riscv_implicit_subsets[] =
11981222
{"sscofpmf", "zicsr", check_implicit_always},
11991223
{"ssstateen", "zicsr", check_implicit_always},
12001224
{"sstc", "zicsr", check_implicit_always},
1225+
/* Complex implications (that should be checked after others). */
1226+
{"d", "zcd", check_implicit_for_d_c},
1227+
{"f", "zcf", check_implicit_for_f_c},
1228+
/* Tail of the list. */
12011229
{NULL, NULL, NULL}
12021230
};
12031231

gas/testsuite/gas/riscv/attribute-10.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#source: empty.s
44
Attribute Section: riscv
55
File Attributes
6-
Tag_RISCV_arch: "rv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zmmul1p0"
6+
Tag_RISCV_arch: "rv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0_zifencei2p0_zmmul1p0_zca1p0_zcd1p0_zcf1p0"

gas/testsuite/gas/riscv/dis-addr-overflow-32.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#as: -march=rv32ic
1+
#as: -march=rv32i_zca
22
#source: dis-addr-overflow.s
33
#objdump: -d
44

gas/testsuite/gas/riscv/dis-addr-overflow-64.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#as: -march=rv64ic -defsym rv64=1
1+
#as: -march=rv64i_zca -defsym rv64=1
22
#source: dis-addr-overflow.s
33
#objdump: -d
44

gas/testsuite/gas/riscv/dis-addr-overflow.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ topbase = 0
2424

2525
target:
2626
.option push
27-
.option arch, -c
27+
.option arch, -zca
2828
## Use hi_addr
2929
# Load
3030
lui t0, 0xfffff
@@ -50,7 +50,7 @@ target:
5050
c.addi t6, -20
5151
.ifdef rv64
5252
.option push
53-
.option arch, -c
53+
.option arch, -zca
5454
# ADDIW (not compressed)
5555
lui s6, 0xffff8
5656
addiw s7, s6, -24

gas/testsuite/gas/riscv/mapping-symbols.d

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,44 @@ SYMBOL TABLE:
99
0+00 l d .data 0+00 .data
1010
0+00 l d .bss 0+00 .bss
1111
0+00 l d .text.cross.section.A 0+00 .text.cross.section.A
12-
0+00 l .text.cross.section.A 0+00 \$xrv32i2p1_c2p0
12+
0+00 l .text.cross.section.A 0+00 \$xrv32i2p1_zca1p0
1313
0+00 l d .text.corss.section.B 0+00 .text.corss.section.B
14-
0+00 l .text.corss.section.B 0+00 \$xrv32i2p1_c2p0
14+
0+00 l .text.corss.section.B 0+00 \$xrv32i2p1_zca1p0
1515
0+02 l .text.corss.section.B 0+00 \$xrv32i2p1
1616
0+00 l d .text.data 0+00 .text.data
1717
0+00 l .text.data 0+00 \$d
18-
0+08 l .text.data 0+00 \$xrv32i2p1_c2p0
18+
0+08 l .text.data 0+00 \$xrv32i2p1_zca1p0
1919
0+0c l .text.data 0+00 \$d
2020
0+00 l d .text.odd.align.start.insn 0+00 .text.odd.align.start.insn
21-
0+00 l .text.odd.align.start.insn 0+00 \$xrv32i2p1_c2p0
21+
0+00 l .text.odd.align.start.insn 0+00 \$xrv32i2p1_zca1p0
2222
0+02 l .text.odd.align.start.insn 0+00 \$d
2323
0+08 l .text.odd.align.start.insn 0+00 \$xrv32i2p1
2424
0+00 l d .text.odd.align.start.data 0+00 .text.odd.align.start.data
2525
0+00 l .text.odd.align.start.data 0+00 \$d
2626
0+00 l d .text.zero.fill.first 0+00 .text.zero.fill.first
27-
0+00 l .text.zero.fill.first 0+00 \$xrv32i2p1_c2p0
27+
0+00 l .text.zero.fill.first 0+00 \$xrv32i2p1_zca1p0
2828
0+00 l d .text.zero.fill.last 0+00 .text.zero.fill.last
29-
0+00 l .text.zero.fill.last 0+00 \$xrv32i2p1_c2p0
29+
0+00 l .text.zero.fill.last 0+00 \$xrv32i2p1_zca1p0
3030
0+02 l .text.zero.fill.last 0+00 \$x
3131
0+00 l d .text.zero.fill.align.A 0+00 .text.zero.fill.align.A
32-
0+00 l .text.zero.fill.align.A 0+00 \$xrv32i2p1_c2p0
32+
0+00 l .text.zero.fill.align.A 0+00 \$xrv32i2p1_zca1p0
3333
0+00 l d .text.zero.fill.align.B 0+00 .text.zero.fill.align.B
3434
0+00 l .text.zero.fill.align.B 0+00 \$xrv32i2p1
3535
0+00 l d .text.last.section 0+00 .text.last.section
3636
0+00 l .text.last.section 0+00 \$xrv32i2p1
3737
0+04 l .text.last.section 0+00 \$d
3838
0+00 l d .text.section.padding 0+00 .text.section.padding
39-
0+00 l .text.section.padding 0+00 \$xrv32i2p1_c2p0
40-
0+04 l .text.section.padding 0+00 \$xrv32i2p1_a2p1_c2p0
39+
0+00 l .text.section.padding 0+00 \$xrv32i2p1_zca1p0
40+
0+04 l .text.section.padding 0+00 \$xrv32i2p1_a2p1_zca1p0
4141
0+06 l .text.section.padding 0+00 \$d
4242
0+00 l d .text.relax.align 0+00 .text.relax.align
43-
0+00 l .text.relax.align 0+00 \$xrv32i2p1_c2p0
43+
0+00 l .text.relax.align 0+00 \$xrv32i2p1_zca1p0
4444
0+08 l .text.relax.align 0+00 \$xrv32i2p1
4545
0+0a l .text.section.padding 0+00 \$x
4646
0+03 l .text.odd.align.start.insn 0+00 \$d
4747
0+04 l .text.odd.align.start.insn 0+00 \$x
4848
0+01 l .text.odd.align.start.data 0+00 \$d
49-
0+02 l .text.odd.align.start.data 0+00 \$xrv32i2p1_c2p0
49+
0+02 l .text.odd.align.start.data 0+00 \$xrv32i2p1_zca1p0
5050
0+00 l d .riscv.attributes 0+00 .riscv.attributes
5151
0+00 g .text.cross.section.A 0+00 funcA
5252
0+00 g .text.corss.section.B 0+00 funcB

gas/testsuite/gas/riscv/mapping.s

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.attribute arch, "rv32ic"
1+
.attribute arch, "rv32i_zca"
22
.option norelax # FIXME: assembler fill the paddings after parsing everything,
33
# so we probably won't fill anything for the norelax region when
44
# the riscv_opts.relax is enabled at somewhere.
@@ -8,21 +8,21 @@
88
.global funcA
99
funcA:
1010
addi a0, zero, 1 # rv32i
11-
.option arch, +c
12-
j funcA # rv32ic
11+
.option arch, +zca
12+
j funcA # rv32i_zca
1313
.section .text.corss.section.B, "ax"
1414
.globl funcB
1515
funcB:
16-
addi a0, zero, 2 # rv32ic, need to be added since start of section
17-
.option arch, -c
16+
addi a0, zero, 2 # rv32i_zca, need to be added since start of section
17+
.option arch, -zca
1818
j funcB # rv32i
1919
.option pop
2020

2121
.section .text.data, "ax"
2222
.option push
2323
.word 0 # $d
2424
.long 1
25-
addi a0, zero, 1 # rv32ic
25+
addi a0, zero, 1 # rv32i_zca
2626
.data
2727
.word 2 # don't add mapping symbols for non-text section
2828
.section .text.data
@@ -35,34 +35,34 @@ addi a0, zero, 2 # $x, but same as previous addi, so removed
3535
.section .text.odd.align.start.insn, "ax"
3636
.option push
3737
.option norelax
38-
.option arch, +c
39-
addi a0, zero, 1 # $xrv32ic
38+
.option arch, +zca
39+
addi a0, zero, 1 # $xrv32i_zca
4040
.byte 1 # $d
41-
.option arch, -c
41+
.option arch, -zca
4242
.align 3 # odd alignment, $x replaced by $d + $x
4343
addi a0, zero, 2 # $xrv32i
4444
.option pop
4545

4646
.section .text.odd.align.start.data, "ax"
4747
.option push
4848
.option norelax
49-
.option arch, +c
49+
.option arch, +zca
5050
.byte 1 # $d
51-
.align 2 # odd alignment, $xrv32ic replaced by $d + $xrv32ic
51+
.align 2 # odd alignment, $xrv32i_zca replaced by $d + $xrv32i_zca
5252
addi a0, zero, 1
5353
.option pop
5454

5555
.section .text.zero.fill.first, "ax"
5656
.option push
5757
.option norelax
5858
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol
59-
addi a0, zero, 1 # $xrv32ic
59+
addi a0, zero, 1 # $xrv32i_zca
6060
.option pop
6161

6262
.section .text.zero.fill.last, "ax"
6363
.option push
6464
.option norelax
65-
addi a0, zero, 1 # $xrv32ic
65+
addi a0, zero, 1 # $xrv32i_zca
6666
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol
6767
addi a0, zero, 2 # $x, FIXME: need find a way to remove?
6868
.option pop
@@ -71,8 +71,8 @@ addi a0, zero, 2 # $x, FIXME: need find a way to remove?
7171
.section .text.zero.fill.align.A, "ax"
7272
.option push
7373
.option norelax
74-
.align 2 # $xrv32ic, .align and .fill are in the different frag, so neither be removed
75-
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol when adding $xrv32ic
74+
.align 2 # $xrv32i_zca, .align and .fill are in the different frag, so neither be removed
75+
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol when adding $xrv32i_zca
7676
addi a0, zero, 1 # $x, should be removed in riscv_check_mapping_symbols
7777
addi a0, zero, 2
7878
.option pop
@@ -81,18 +81,18 @@ addi a0, zero, 2
8181
.section .text.zero.fill.align.B, "ax"
8282
.option push
8383
.option norelax
84-
.align 2 # $xrv32ic, .align and .fill are in the different frag, so neither be removed,
84+
.align 2 # $xrv32i_zca, .align and .fill are in the different frag, so neither be removed,
8585
# but will be removed in riscv_check_mapping_symbols
86-
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol when adding $xrv32ic
87-
.option arch, -c
86+
.fill 1, 0, 0 # $d with zero size, removed in make_mapping_symbol when adding $xrv32i_zca
87+
.option arch, -zca
8888
addi a0, zero, 1 # $xrv32i
8989
addi a0, zero, 2
9090
.option pop
9191

9292
.section .text.last.section, "ax"
9393
.option push
9494
.option norelax
95-
.option arch, -c
95+
.option arch, -zca
9696
addi a0, zero, 1 # $xrv32i
9797
.word 1 # $d
9898
.align 2 # zero section padding, $x at the end of section, removed in riscv_check_mapping_symbols
@@ -102,20 +102,20 @@ addi a0, zero, 1 # $xrv32i
102102
.option push
103103
.option norelax
104104
.align 2
105-
addi a0, zero, 1 # $rv32ic
105+
addi a0, zero, 1 # $rv32i_zca
106106
.option arch, +a
107107
.align 2 # 2-byte padding, $x, removed
108-
addi a0, zero, 2 # $xrv32iac
108+
addi a0, zero, 2 # $xrv32ia_zca
109109
.word 1 # $d
110110
.option pop # 2-byte padding, $x
111111

112112
.section .text.relax.align, "ax"
113113
.option push
114114
.option relax
115-
.option arch, rv32ic
116-
.balign 4 # $xrv32ic, add at the start of section
115+
.option arch, rv32i_zca
116+
.balign 4 # $xrv32i_zca, add at the start of section
117117
addi a0, zero, 1 # $x, won't added
118-
.option arch, -c
118+
.option arch, -zca
119119
.align 3 # $x, won't added
120120
addi a0, zero, 2 # $xrv32i
121121
.option pop
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#as: -march=rv32idc -march-attr -misa-spec=20191213
2+
#readelf: -A
3+
#source: empty.s
4+
Attribute Section: riscv
5+
File Attributes
6+
Tag_RISCV_arch: "rv32i2p1_f2p2_d2p2_c2p0_zicsr2p0_zca1p0_zcd1p0_zcf1p0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#as: -march=rv64idc -march-attr -misa-spec=20191213
2+
#readelf: -A
3+
#source: empty.s
4+
Attribute Section: riscv
5+
File Attributes
6+
Tag_RISCV_arch: "rv64i2p1_f2p2_d2p2_c2p0_zicsr2p0_zca1p0_zcd1p0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#as: -march=rv32ic -march-attr -misa-spec=20191213
2+
#readelf: -A
3+
#source: empty.s
4+
Attribute Section: riscv
5+
File Attributes
6+
Tag_RISCV_arch: "rv32i2p1_c2p0_zca1p0"

0 commit comments

Comments
 (0)