Skip to content

Commit 3573306

Browse files
gxwXiWeiGu
authored andcommitted
LoongArch64: Add core LOONGSON2K1000 and LOONGSONGENERIC
1 parent c43ec53 commit 3573306

File tree

5 files changed

+182
-49
lines changed

5 files changed

+182
-49
lines changed

Makefile.system

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,9 @@ BINARY_DEFINED = 1
891891
endif
892892

893893
ifeq ($(ARCH), loongarch64)
894-
ifeq ($(CORE), LOONGSON3R5)
895894
CCOMMON_OPT += -march=loongarch64 -mabi=lp64
896895
FCOMMON_OPT += -march=loongarch64 -mabi=lp64
897896
endif
898-
endif
899897

900898
endif
901899

TargetList.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ RISCV64_GENERIC
121121
C910V
122122

123123
11.LOONGARCH64:
124+
LOONGSONGENERIC
124125
LOONGSON3R5
126+
LOONGSON2K1000
125127

126128
12. Elbrus E2000:
127129
E2K

cpuid_loongarch64.c

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,53 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333

3434
#include <stdint.h>
3535

36-
#define CPU_UNKNOWN 0
37-
#define CPU_LOONGSON3R5 1
36+
/* If LASX extension instructions supported,
37+
* using core LOONGSON3R5
38+
* If only LSX extension instructions supported,
39+
* using core LOONGSON2K1000
40+
* If neither LASX nor LSX extension instructions supported,
41+
* using core LOONGSONGENERIC (As far as I know, there is no such
42+
* CPU yet)
43+
*/
44+
45+
#define CPU_GENERIC 0
46+
#define CPU_LOONGSON3R5 1
47+
#define CPU_LOONGSON2K1000 2
3848

3949
#define LOONGARCH_CFG2 0x02
4050
#define LOONGARCH_LASX 1<<7
51+
#define LOONGARCH_LSX 1<<6
4152

4253
static char *cpuname[] = {
43-
"UNKNOWN",
44-
"LOONGSON3R5"
54+
"LOONGSONGENERIC",
55+
"LOONGSON3R5",
56+
"LOONGSON2K1000"
57+
};
58+
59+
static char *cpuname_lower[] = {
60+
"loongsongeneric",
61+
"loongson3r5",
62+
"loongson2k1000"
4563
};
4664

4765
int detect(void) {
48-
uint32_t reg = 0;
49-
50-
__asm__ volatile (
51-
"cpucfg %0, %1 \n\t"
52-
: "+&r"(reg)
53-
: "r"(LOONGARCH_CFG2)
54-
);
55-
56-
if (reg & LOONGARCH_LASX)
57-
return CPU_LOONGSON3R5;
58-
else
59-
return CPU_UNKNOWN;
66+
#ifdef __linux
67+
uint32_t reg = 0;
68+
69+
__asm__ volatile (
70+
"cpucfg %0, %1 \n\t"
71+
: "+&r"(reg)
72+
: "r"(LOONGARCH_CFG2)
73+
);
74+
75+
if (reg & LOONGARCH_LASX)
76+
return CPU_LOONGSON3R5;
77+
else if (reg & LOONGARCH_LSX)
78+
return CPU_LOONGSON2K1000;
79+
else
80+
return CPU_GENERIC;
81+
#endif
82+
return CPU_GENERIC;
6083
}
6184

6285
char *get_corename(void) {
@@ -68,43 +91,53 @@ void get_architecture(void) {
6891
}
6992

7093
void get_subarchitecture(void) {
71-
if (detect() == CPU_LOONGSON3R5) {
72-
printf("LOONGSON3R5");
73-
} else {
74-
printf("UNKNOWN");
75-
}
94+
int d = detect();
95+
printf("%s", cpuname[d]);
7696
}
7797

7898
void get_subdirname(void) {
7999
printf("loongarch64");
80100
}
81101

82102
void get_cpuconfig(void) {
83-
if (detect() == CPU_LOONGSON3R5) {
84-
printf("#define LOONGSON3R5\n");
85-
printf("#define L1_DATA_SIZE 65536\n");
86-
printf("#define L1_DATA_LINESIZE 64\n");
87-
printf("#define L2_SIZE 1048576\n");
88-
printf("#define L2_LINESIZE 64\n");
89-
printf("#define DTB_DEFAULT_ENTRIES 64\n");
90-
printf("#define DTB_SIZE 4096\n");
91-
printf("#define L2_ASSOCIATIVE 16\n");
92-
} else {
93-
printf("#define LOONGSON3R5\n");
94-
printf("#define L1_DATA_SIZE 65536\n");
95-
printf("#define L1_DATA_LINESIZE 64\n");
96-
printf("#define L2_SIZE 1048576\n");
97-
printf("#define L2_LINESIZE 64\n");
98-
printf("#define DTB_DEFAULT_ENTRIES 64\n");
99-
printf("#define DTB_SIZE 4096\n");
100-
printf("#define L2_ASSOCIATIVE 16\n");
103+
int d = detect();
104+
switch (d) {
105+
case CPU_LOONGSON3R5:
106+
printf("#define LOONGSON3R5\n");
107+
printf("#define L1_DATA_SIZE 65536\n");
108+
printf("#define L1_DATA_LINESIZE 64\n");
109+
printf("#define L2_SIZE 1048576\n");
110+
printf("#define L2_LINESIZE 64\n");
111+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
112+
printf("#define DTB_SIZE 4096\n");
113+
printf("#define L2_ASSOCIATIVE 16\n");
114+
break;
115+
116+
case CPU_LOONGSON2K1000:
117+
printf("#define LOONGSON2K1000\n");
118+
printf("#define L1_DATA_SIZE 65536\n");
119+
printf("#define L1_DATA_LINESIZE 64\n");
120+
printf("#define L2_SIZE 262144\n");
121+
printf("#define L2_LINESIZE 64\n");
122+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
123+
printf("#define DTB_SIZE 4096\n");
124+
printf("#define L2_ASSOCIATIVE 16\n");
125+
break;
126+
127+
default:
128+
printf("#define LOONGSONGENERIC\n");
129+
printf("#define L1_DATA_SIZE 65536\n");
130+
printf("#define L1_DATA_LINESIZE 64\n");
131+
printf("#define L2_SIZE 262144\n");
132+
printf("#define L2_LINESIZE 64\n");
133+
printf("#define DTB_DEFAULT_ENTRIES 64\n");
134+
printf("#define DTB_SIZE 4096\n");
135+
printf("#define L2_ASSOCIATIVE 16\n");
136+
break;
101137
}
102138
}
103139

104140
void get_libname(void){
105-
if (detect() == CPU_LOONGSON3R5) {
106-
printf("loongson3r5\n");
107-
} else {
108-
printf("loongarch64\n");
109-
}
141+
int d = detect();
142+
printf("%s", cpuname_lower[d]);
110143
}

getarch.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132132
/* #define FORCE_PPC440FP2 */
133133
/* #define FORCE_CELL */
134134
/* #define FORCE_SICORTEX */
135-
/* #define FORCE_LOONGSON3R3 */
136-
/* #define FORCE_LOONGSON3R4 */
137-
/* #define FORCE_LOONGSON3R5 */
135+
/* #define FORCE_LOONGSON3R3 */
136+
/* #define FORCE_LOONGSON3R4 */
137+
/* #define FORCE_LOONGSON3R5 */
138+
/* #define FORCE_LOONGSON2K1000 */
139+
/* #define FORCE_LOONGSONGENERIC */
138140
/* #define FORCE_I6400 */
139141
/* #define FORCE_P6600 */
140142
/* #define FORCE_P5600 */
@@ -969,6 +971,34 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
969971
#else
970972
#endif
971973

974+
#ifdef FORCE_LOONGSON2K1000
975+
#define FORCE
976+
#define ARCHITECTURE "LOONGARCH"
977+
#define SUBARCHITECTURE "LOONGSON2K1000"
978+
#define SUBDIRNAME "loongarch64"
979+
#define ARCHCONFIG "-DLOONGSON2K1000 " \
980+
"-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
981+
"-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
982+
"-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
983+
#define LIBNAME "loongson2k1000"
984+
#define CORENAME "LOONGSON2K1000"
985+
#else
986+
#endif
987+
988+
#ifdef FORCE_LOONGSONGENERIC
989+
#define FORCE
990+
#define ARCHITECTURE "LOONGARCH"
991+
#define SUBARCHITECTURE "LOONGSONGENERIC"
992+
#define SUBDIRNAME "loongarch64"
993+
#define ARCHCONFIG "-DLOONGSONGENERIC " \
994+
"-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=64 " \
995+
"-DL2_SIZE=262144 -DL2_LINESIZE=64 " \
996+
"-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=16 "
997+
#define LIBNAME "loongsongeneric"
998+
#define CORENAME "LOONGSONGENERIC"
999+
#else
1000+
#endif
1001+
9721002
#ifdef FORCE_I6400
9731003
#define FORCE
9741004
#define ARCHITECTURE "MIPS"

param.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,76 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28812881
#define SYMV_P 16
28822882
#endif
28832883

2884+
#ifdef LOONGSON2K1000
2885+
#define GEMM_DEFAULT_OFFSET_A 0
2886+
#define GEMM_DEFAULT_OFFSET_B 0
2887+
#define GEMM_DEFAULT_ALIGN (BLASLONG)0x03fffUL
2888+
2889+
#define SGEMM_DEFAULT_UNROLL_M 2
2890+
#define SGEMM_DEFAULT_UNROLL_N 8
2891+
2892+
#define DGEMM_DEFAULT_UNROLL_M 2
2893+
#define DGEMM_DEFAULT_UNROLL_N 8
2894+
2895+
#define CGEMM_DEFAULT_UNROLL_M 1
2896+
#define CGEMM_DEFAULT_UNROLL_N 4
2897+
2898+
#define ZGEMM_DEFAULT_UNROLL_M 1
2899+
#define ZGEMM_DEFAULT_UNROLL_N 4
2900+
2901+
#define SGEMM_DEFAULT_P 128
2902+
#define DGEMM_DEFAULT_P 128
2903+
#define CGEMM_DEFAULT_P 96
2904+
#define ZGEMM_DEFAULT_P 64
2905+
2906+
#define SGEMM_DEFAULT_Q 240
2907+
#define DGEMM_DEFAULT_Q 120
2908+
#define CGEMM_DEFAULT_Q 120
2909+
#define ZGEMM_DEFAULT_Q 120
2910+
2911+
#define SGEMM_DEFAULT_R 12288
2912+
#define DGEMM_DEFAULT_R 8192
2913+
#define CGEMM_DEFAULT_R 4096
2914+
#define ZGEMM_DEFAULT_R 4096
2915+
2916+
#define SYMV_P 16
2917+
#endif
2918+
2919+
#ifdef LOONGSONGENERIC
2920+
#define GEMM_DEFAULT_OFFSET_A 0
2921+
#define GEMM_DEFAULT_OFFSET_B 0
2922+
#define GEMM_DEFAULT_ALIGN (BLASLONG)0x03fffUL
2923+
2924+
#define SGEMM_DEFAULT_UNROLL_M 2
2925+
#define SGEMM_DEFAULT_UNROLL_N 8
2926+
2927+
#define DGEMM_DEFAULT_UNROLL_M 2
2928+
#define DGEMM_DEFAULT_UNROLL_N 8
2929+
2930+
#define CGEMM_DEFAULT_UNROLL_M 1
2931+
#define CGEMM_DEFAULT_UNROLL_N 4
2932+
2933+
#define ZGEMM_DEFAULT_UNROLL_M 1
2934+
#define ZGEMM_DEFAULT_UNROLL_N 4
2935+
2936+
#define SGEMM_DEFAULT_P 128
2937+
#define DGEMM_DEFAULT_P 128
2938+
#define CGEMM_DEFAULT_P 96
2939+
#define ZGEMM_DEFAULT_P 64
2940+
2941+
#define SGEMM_DEFAULT_Q 240
2942+
#define DGEMM_DEFAULT_Q 120
2943+
#define CGEMM_DEFAULT_Q 120
2944+
#define ZGEMM_DEFAULT_Q 120
2945+
2946+
#define SGEMM_DEFAULT_R 12288
2947+
#define DGEMM_DEFAULT_R 8192
2948+
#define CGEMM_DEFAULT_R 4096
2949+
#define ZGEMM_DEFAULT_R 4096
2950+
2951+
#define SYMV_P 16
2952+
#endif
2953+
28842954
#if defined(P5600) || defined(MIPS1004K) || defined(MIPS24K) || defined(I6400) || defined(P6600) || defined(I6500)
28852955
#define SNUMOPT 2
28862956
#define DNUMOPT 2

0 commit comments

Comments
 (0)