File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1448,6 +1448,20 @@ StringRef sys::getHostCPUName() {
1448
1448
return " generic" ;
1449
1449
}
1450
1450
}
1451
+ #elif defined(__loongarch__)
1452
+ StringRef sys::getHostCPUName () {
1453
+ // Use processor id to detect cpu name.
1454
+ uint32_t processor_id;
1455
+ __asm__ (" cpucfg %[prid], $zero\n\t " : [prid] " =r" (processor_id));
1456
+ switch (processor_id & 0xff00 ) {
1457
+ case 0xc000 : // Loongson 64bit, 4-issue
1458
+ return " la464" ;
1459
+ // TODO: Others.
1460
+ default :
1461
+ break ;
1462
+ }
1463
+ return " generic" ;
1464
+ }
1451
1465
#elif defined(__riscv)
1452
1466
StringRef sys::getHostCPUName () {
1453
1467
#if defined(__linux__)
@@ -1842,6 +1856,23 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
1842
1856
1843
1857
return true ;
1844
1858
}
1859
+ #elif defined(__linux__) && defined(__loongarch__)
1860
+ #include < sys/auxv.h>
1861
+ bool sys::getHostCPUFeatures (StringMap<bool > &Features) {
1862
+ unsigned long hwcap = getauxval (AT_HWCAP);
1863
+ bool HasFPU = hwcap & (1UL << 3 ); // HWCAP_LOONGARCH_FPU
1864
+ uint32_t cpucfg2 = 0x2 ;
1865
+ __asm__ (" cpucfg %[cpucfg2], %[cpucfg2]\n\t " : [cpucfg2] " +r" (cpucfg2));
1866
+
1867
+ Features[" f" ] = HasFPU && (cpucfg2 & (1U << 1 )); // CPUCFG.2.FP_SP
1868
+ Features[" d" ] = HasFPU && (cpucfg2 & (1U << 2 )); // CPUCFG.2.FP_DP
1869
+
1870
+ Features[" lsx" ] = hwcap & (1UL << 4 ); // HWCAP_LOONGARCH_LSX
1871
+ Features[" lasx" ] = hwcap & (1UL << 5 ); // HWCAP_LOONGARCH_LASX
1872
+ Features[" lvz" ] = hwcap & (1UL << 9 ); // HWCAP_LOONGARCH_LVZ
1873
+
1874
+ return true ;
1875
+ }
1845
1876
#else
1846
1877
bool sys::getHostCPUFeatures (StringMap<bool > &Features) { return false ; }
1847
1878
#endif
You can’t perform that action at this time.
0 commit comments