Browse Source

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.
tags/v0.3.26
Shiyou Yin 1 year ago
parent
commit
1310a0931b
4 changed files with 22 additions and 25 deletions
  1. +2
    -4
      c_check
  2. +2
    -4
      c_check.pl
  3. +11
    -5
      cpuid_loongarch64.c
  4. +7
    -12
      driver/others/dynamic_loongarch64.c

+ 2
- 4
c_check View File

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

tmplasx="$tmpd/lasx.c"
codelasx='"xvadd.b $xr0, $xr0, $xr0"'
lasx_flags='-march=loongarch64 -mlasx'
printf "#include <lasxintrin.h>\n\n" >> "$tmplasx"
lasx_flags='-march=loongarch64'
printf "void main(void){ __asm__ volatile(%s);}\n" "$codelasx" >> "$tmplasx"
args="$lasx_flags -o $tmplasx.o $tmplasx"
{


+ 2
- 4
c_check.pl View File

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

$args = "$lsx_flags -o $tmplsx.o $tmplsx";
@@ -257,8 +256,7 @@ if (($architecture eq "loongarch64")) {

$tmplasx = new File::Temp( SUFFIX => '.c' , UNLINK => 1 );
$codelasx = '"xvadd.b $xr0, $xr0, $xr0"';
$lasx_flags = "-march=loongarch64 -mlasx";
print $tmplasx "#include <lasxintrin.h>\n\n";
$lasx_flags = "-march=loongarch64";
print $tmplasx "void main(void){ __asm__ volatile($codelasx); }\n";

$args = "$lasx_flags -o $tmplasx.o $tmplasx";


+ 11
- 5
cpuid_loongarch64.c 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_LOONGSON2K1000 2

#define LA_HWCAP_LSX (1<<4)
#define LA_HWCAP_LASX (1<<5)
#define LA_HWCAP_LSX (1U << 4)
#define LA_HWCAP_LASX (1U << 5)

static char *cpuname[] = {
"LOONGSONGENERIC",
@@ -64,11 +64,11 @@ static char *cpuname_lower[] = {

int detect(void) {
#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;
else if (flag & LA_HWCAP_LSX)
else if (hwcap & LA_HWCAP_LSX)
return CPU_LOONGSON2K1000;
else
return CPU_GENERIC;
@@ -94,7 +94,9 @@ void get_subdirname(void) {
}

void get_cpuconfig(void) {
uint32_t hwcaps = 0;
int d = detect();

switch (d) {
case CPU_LOONGSON3R5:
printf("#define LOONGSON3R5\n");
@@ -129,6 +131,10 @@ void get_cpuconfig(void) {
printf("#define L2_ASSOCIATIVE 16\n");
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){


+ 7
- 12
driver/others/dynamic_loongarch64.c 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.
*******************************************************************************/

#include <sys/auxv.h>
#include "common.h"

extern gotoblas_t gotoblas_LOONGSON3R5;
@@ -74,21 +75,15 @@ static gotoblas_t *force_coretype(char *coretype) {
return NULL;
}

#define LASX_MASK 1<<7
#define LSX_MASK 1<<6
#define LOONGARCH_CFG2 0x02
#define LA_HWCAP_LSX (1U << 4)
#define LA_HWCAP_LASX (1U << 5)

static gotoblas_t *get_coretype(void) {
int ret = 0;
__asm__ volatile (
"cpucfg %0, %1 \n\t"
: "+&r"(ret)
: "r"(LOONGARCH_CFG2)
);

if (ret & LASX_MASK)
int hwcap = (int)getauxval(AT_HWCAP);

if (hwcap & LA_HWCAP_LASX)
return &gotoblas_LOONGSON3R5;
else if (ret & LSX_MASK)
else if (hwcap & LA_HWCAP_LSX)
return &gotoblas_LOONGSON2K1000;
else
return &gotoblas_LOONGSONGENERIC;


Loading…
Cancel
Save