Skip to content

Commit 7d6c0ae

Browse files
authored
Merge pull request #3618 from martin-frbg/issue3606
Automatically downgrade C910V to RISCV64_GENERIC if the compiler lacks vector support
2 parents 06d1dd6 + 18427f3 commit 7d6c0ae

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Makefile.prebuild

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ endif
7272

7373
getarch : getarch.c cpuid.S dummy $(CPUIDEMU)
7474
avx512=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_AVX512); \
75-
$(HOSTCC) $(HOST_CFLAGS) $(EXFLAGS) $${avx512:+-D$${avx512}} -o $(@F) getarch.c cpuid.S $(CPUIDEMU)
75+
rv64gv=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_RV64GV); \
76+
$(HOSTCC) $(HOST_CFLAGS) $(EXFLAGS) $${avx512:+-D$${avx512}} $${rv64gv:+-D$${rv64gv}} -o $(@F) getarch.c cpuid.S $(CPUIDEMU)
7677

7778
getarch_2nd : getarch_2nd.c $(TARGET_CONF) dummy
7879
ifndef TARGET_CORE

c_check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) {
270270
}
271271
}
272272

273+
$no_rv64gv= 0;
274+
if (($architecture eq "riscv64")) {
275+
eval "use File::Temp qw(tempfile)";
276+
if ($@){
277+
warn "could not load PERL module File::Temp, so could not check compiler compatibility with the RISCV vector extension";
278+
$no_rv64gv = 0;
279+
} else {
280+
# $tmpf = new File::Temp( UNLINK => 1 );
281+
($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
282+
$code = '"vsetvli zero, zero, e8, m1\n"';
283+
print $fh "int main(void){ __asm__ volatile($code); }\n";
284+
$args = " -march=rv64gv -c -o $tmpf.o $tmpf";
285+
my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
286+
system(@cmd) == 0;
287+
if ($? != 0) {
288+
$no_rv64gv = 1;
289+
} else {
290+
$no_rv64gv = 0;
291+
}
292+
unlink("$tmpf.o");
293+
}
294+
}
295+
273296
$c11_atomics = 0;
274297
if ($data =~ /HAVE_C11/) {
275298
eval "use File::Temp qw(tempfile)";
@@ -392,6 +415,7 @@ print MAKEFILE "CROSS=1\n" if $cross != 0;
392415
print MAKEFILE "CEXTRALIB=$linker_L $linker_l $linker_a\n";
393416
print MAKEFILE "HAVE_MSA=1\n" if $have_msa eq 1;
394417
print MAKEFILE "MSA_FLAGS=$msa_flags\n" if $have_msa eq 1;
418+
print MAKEFILE "NO_RV64GV=1\n" if $no_rv64gv eq 1;
395419
print MAKEFILE "NO_AVX512=1\n" if $no_avx512 eq 1;
396420
print MAKEFILE "NO_AVX2=1\n" if $no_avx2 eq 1;
397421
print MAKEFILE "OLDGCC=1\n" if $oldgcc eq 1;

getarch.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,16 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15741574
#ifdef FORCE_C910V
15751575
#define FORCE
15761576
#define ARCHITECTURE "RISCV64"
1577+
#ifdef NO_RV64GV
1578+
#define SUBARCHITECTURE "RISCV64_GENERIC"
1579+
#define SUBDIRNAME "riscv64"
1580+
#define ARCHCONFIG "-DRISCV64_GENERIC " \
1581+
"-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \
1582+
"-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \
1583+
"-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
1584+
#define LIBNAME "riscv64_generic"
1585+
#define CORENAME "RISCV64_GENERIC"
1586+
#else
15771587
#define SUBARCHITECTURE "C910V"
15781588
#define SUBDIRNAME "riscv64"
15791589
#define ARCHCONFIG "-DC910V " \
@@ -1582,6 +1592,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15821592
"-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 "
15831593
#define LIBNAME "c910v"
15841594
#define CORENAME "C910V"
1595+
#endif
15851596
#else
15861597
#endif
15871598

0 commit comments

Comments
 (0)