loongarch: Refine build control for loongarch64.

1. Use getauxval instead of cpucfg to test hardware capability.
2. Remove unnecessary code and option for compiler check in c_check.
This commit is contained in:
Shiyou Yin 2023-11-15 16:54:06 +08:00
parent f745f02f35
commit 1310a0931b
4 changed files with 21 additions and 24 deletions

View File

@ -199,8 +199,7 @@ if [ "$architecture" = "loongarch64" ]; then
tmpd="$(mktemp -d)" tmpd="$(mktemp -d)"
tmplsx="$tmpd/lsx.c" tmplsx="$tmpd/lsx.c"
codelsx='"vadd.b $vr0, $vr0, $vr0"' codelsx='"vadd.b $vr0, $vr0, $vr0"'
lsx_flags='-march=loongarch64 -mlsx' lsx_flags='-march=loongarch64'
printf "#include <lsxintrin.h>\n\n" >> "$tmplsx"
printf "void main(void){ __asm__ volatile(%s);}\n" "$codelsx" >> "$tmplsx" printf "void main(void){ __asm__ volatile(%s);}\n" "$codelsx" >> "$tmplsx"
args="$lsx_flags -o $tmplsx.o $tmplsx" args="$lsx_flags -o $tmplsx.o $tmplsx"
{ {
@ -211,8 +210,7 @@ if [ "$architecture" = "loongarch64" ]; then
tmplasx="$tmpd/lasx.c" tmplasx="$tmpd/lasx.c"
codelasx='"xvadd.b $xr0, $xr0, $xr0"' codelasx='"xvadd.b $xr0, $xr0, $xr0"'
lasx_flags='-march=loongarch64 -mlasx' lasx_flags='-march=loongarch64'
printf "#include <lasxintrin.h>\n\n" >> "$tmplasx"
printf "void main(void){ __asm__ volatile(%s);}\n" "$codelasx" >> "$tmplasx" printf "void main(void){ __asm__ volatile(%s);}\n" "$codelasx" >> "$tmplasx"
args="$lasx_flags -o $tmplasx.o $tmplasx" args="$lasx_flags -o $tmplasx.o $tmplasx"
{ {

View File

@ -241,8 +241,7 @@ if (($architecture eq "loongarch64")) {
} else { } else {
$tmplsx = new File::Temp( SUFFIX => '.c' , UNLINK => 1 ); $tmplsx = new File::Temp( SUFFIX => '.c' , UNLINK => 1 );
$codelsx = '"vadd.b $vr0, $vr0, $vr0"'; $codelsx = '"vadd.b $vr0, $vr0, $vr0"';
$lsx_flags = "-march=loongarch64 -mlsx"; $lsx_flags = "-march=loongarch64";
print $tmplsx "#include <lsxintrin.h>\n\n";
print $tmplsx "void main(void){ __asm__ volatile($codelsx); }\n"; print $tmplsx "void main(void){ __asm__ volatile($codelsx); }\n";
$args = "$lsx_flags -o $tmplsx.o $tmplsx"; $args = "$lsx_flags -o $tmplsx.o $tmplsx";
@ -257,8 +256,7 @@ if (($architecture eq "loongarch64")) {
$tmplasx = new File::Temp( SUFFIX => '.c' , UNLINK => 1 ); $tmplasx = new File::Temp( SUFFIX => '.c' , UNLINK => 1 );
$codelasx = '"xvadd.b $xr0, $xr0, $xr0"'; $codelasx = '"xvadd.b $xr0, $xr0, $xr0"';
$lasx_flags = "-march=loongarch64 -mlasx"; $lasx_flags = "-march=loongarch64";
print $tmplasx "#include <lasxintrin.h>\n\n";
print $tmplasx "void main(void){ __asm__ volatile($codelasx); }\n"; print $tmplasx "void main(void){ __asm__ volatile($codelasx); }\n";
$args = "$lasx_flags -o $tmplasx.o $tmplasx"; $args = "$lasx_flags -o $tmplasx.o $tmplasx";

View File

@ -47,8 +47,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CPU_LOONGSON3R5 1 #define CPU_LOONGSON3R5 1
#define CPU_LOONGSON2K1000 2 #define CPU_LOONGSON2K1000 2
#define LA_HWCAP_LSX (1<<4) #define LA_HWCAP_LSX (1U << 4)
#define LA_HWCAP_LASX (1<<5) #define LA_HWCAP_LASX (1U << 5)
static char *cpuname[] = { static char *cpuname[] = {
"LOONGSONGENERIC", "LOONGSONGENERIC",
@ -64,11 +64,11 @@ static char *cpuname_lower[] = {
int detect(void) { int detect(void) {
#ifdef __linux #ifdef __linux
int flag = (int)getauxval(AT_HWCAP); int hwcap = (int)getauxval(AT_HWCAP);
if (flag & LA_HWCAP_LASX) if (hwcap & LA_HWCAP_LASX)
return CPU_LOONGSON3R5; return CPU_LOONGSON3R5;
else if (flag & LA_HWCAP_LSX) else if (hwcap & LA_HWCAP_LSX)
return CPU_LOONGSON2K1000; return CPU_LOONGSON2K1000;
else else
return CPU_GENERIC; return CPU_GENERIC;
@ -94,7 +94,9 @@ void get_subdirname(void) {
} }
void get_cpuconfig(void) { void get_cpuconfig(void) {
uint32_t hwcaps = 0;
int d = detect(); int d = detect();
switch (d) { switch (d) {
case CPU_LOONGSON3R5: case CPU_LOONGSON3R5:
printf("#define LOONGSON3R5\n"); printf("#define LOONGSON3R5\n");
@ -129,6 +131,10 @@ void get_cpuconfig(void) {
printf("#define L2_ASSOCIATIVE 16\n"); printf("#define L2_ASSOCIATIVE 16\n");
break; break;
} }
hwcaps = (uint32_t)getauxval( AT_HWCAP );
if (hwcaps & LA_HWCAP_LSX) printf("#define HAVE_LSX\n");
if (hwcaps & LA_HWCAP_LASX) printf("#define HAVE_LASX\n");
} }
void get_libname(void){ void get_libname(void){

View File

@ -25,6 +25,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/ *******************************************************************************/
#include <sys/auxv.h>
#include "common.h" #include "common.h"
extern gotoblas_t gotoblas_LOONGSON3R5; extern gotoblas_t gotoblas_LOONGSON3R5;
@ -74,21 +75,15 @@ static gotoblas_t *force_coretype(char *coretype) {
return NULL; return NULL;
} }
#define LASX_MASK 1<<7 #define LA_HWCAP_LSX (1U << 4)
#define LSX_MASK 1<<6 #define LA_HWCAP_LASX (1U << 5)
#define LOONGARCH_CFG2 0x02
static gotoblas_t *get_coretype(void) { static gotoblas_t *get_coretype(void) {
int ret = 0; int hwcap = (int)getauxval(AT_HWCAP);
__asm__ volatile (
"cpucfg %0, %1 \n\t"
: "+&r"(ret)
: "r"(LOONGARCH_CFG2)
);
if (ret & LASX_MASK) if (hwcap & LA_HWCAP_LASX)
return &gotoblas_LOONGSON3R5; return &gotoblas_LOONGSON3R5;
else if (ret & LSX_MASK) else if (hwcap & LA_HWCAP_LSX)
return &gotoblas_LOONGSON2K1000; return &gotoblas_LOONGSON2K1000;
else else
return &gotoblas_LOONGSONGENERIC; return &gotoblas_LOONGSONGENERIC;