From d328636e5895cc9575aef0304f71c9786ac645aa Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Tue, 3 May 2022 23:27:50 +0200 Subject: [PATCH 1/2] Add compiler check for RISCV vector support --- c_check | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/c_check b/c_check index f9d3f2ca2..a3afea838 100644 --- a/c_check +++ b/c_check @@ -270,6 +270,29 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) { } } +$no_rv64gv= 0; +if (($architecture eq "riscv64")) { + eval "use File::Temp qw(tempfile)"; + if ($@){ + warn "could not load PERL module File::Temp, so could not check compiler compatibility with the RISCV vector extension"; + $no_rv64gv = 0; + } else { +# $tmpf = new File::Temp( UNLINK => 1 ); + ($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 ); + $code = '"vsetvli zero, zero, e8, m1\n"'; + print $fh "int main(void){ __asm__ volatile($code); }\n"; + $args = " -march=rv64gv -c -o $tmpf.o $tmpf"; + my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null"); + system(@cmd) == 0; + if ($? != 0) { + $no_rv64gv = 1; + } else { + $no_rv64gv = 0; + } + unlink("$tmpf.o"); + } +} + $c11_atomics = 0; if ($data =~ /HAVE_C11/) { eval "use File::Temp qw(tempfile)"; @@ -392,6 +415,7 @@ print MAKEFILE "CROSS=1\n" if $cross != 0; print MAKEFILE "CEXTRALIB=$linker_L $linker_l $linker_a\n"; print MAKEFILE "HAVE_MSA=1\n" if $have_msa eq 1; print MAKEFILE "MSA_FLAGS=$msa_flags\n" if $have_msa eq 1; +print MAKEFILE "NO_RV64GV=1\n" if $no_rv64gv eq 1; print MAKEFILE "NO_AVX512=1\n" if $no_avx512 eq 1; print MAKEFILE "NO_AVX2=1\n" if $no_avx2 eq 1; print MAKEFILE "OLDGCC=1\n" if $oldgcc eq 1; From 18427f375988d39f9d9f322bcdd882f7849421fc Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Tue, 3 May 2022 23:29:55 +0200 Subject: [PATCH 2/2] Have getarch downgrade the RISCV C910V target to GENERIC if compiler lacks vector support --- Makefile.prebuild | 3 ++- getarch.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile.prebuild b/Makefile.prebuild index fe35832e3..e6d07c013 100644 --- a/Makefile.prebuild +++ b/Makefile.prebuild @@ -72,7 +72,8 @@ endif getarch : getarch.c cpuid.S dummy $(CPUIDEMU) avx512=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_AVX512); \ - $(HOSTCC) $(HOST_CFLAGS) $(EXFLAGS) $${avx512:+-D$${avx512}} -o $(@F) getarch.c cpuid.S $(CPUIDEMU) + rv64gv=$$(perl c_check - - $(CC) $(TARGET_FLAGS) $(CFLAGS) | grep NO_RV64GV); \ + $(HOSTCC) $(HOST_CFLAGS) $(EXFLAGS) $${avx512:+-D$${avx512}} $${rv64gv:+-D$${rv64gv}} -o $(@F) getarch.c cpuid.S $(CPUIDEMU) getarch_2nd : getarch_2nd.c $(TARGET_CONF) dummy ifndef TARGET_CORE diff --git a/getarch.c b/getarch.c index 4af986fb3..1cd3e152d 100644 --- a/getarch.c +++ b/getarch.c @@ -1574,6 +1574,16 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef FORCE_C910V #define FORCE #define ARCHITECTURE "RISCV64" +#ifdef NO_RV64GV +#define SUBARCHITECTURE "RISCV64_GENERIC" +#define SUBDIRNAME "riscv64" +#define ARCHCONFIG "-DRISCV64_GENERIC " \ + "-DL1_DATA_SIZE=32768 -DL1_DATA_LINESIZE=32 " \ + "-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \ + "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " +#define LIBNAME "riscv64_generic" +#define CORENAME "RISCV64_GENERIC" +#else #define SUBARCHITECTURE "C910V" #define SUBDIRNAME "riscv64" #define ARCHCONFIG "-DC910V " \ @@ -1582,6 +1592,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. "-DDTB_DEFAULT_ENTRIES=128 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=4 " #define LIBNAME "c910v" #define CORENAME "C910V" +#endif #else #endif