Skip to content

Commit bd30120

Browse files
authored
Merge pull request #3720 from FlyGoat/mips64
Make it work on general MIPS64 processors
2 parents 2ef7a58 + 4197c35 commit bd30120

File tree

8 files changed

+136
-102
lines changed

8 files changed

+136
-102
lines changed

Makefile.system

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,12 @@ endif
677677
endif
678678

679679
ifeq ($(ARCH), mips64)
680-
DYNAMIC_CORE = LOONGSON3R3 LOONGSON3R4
680+
DYNAMIC_CORE = LOONGSON3R3 LOONGSON3R4 MIPS64_GENERIC
681+
ifdef DYNAMIC_LIST
682+
override DYNAMIC_CORE = MIPS64_GENERIC $(DYNAMIC_LIST)
683+
XCCOMMON_OPT = -DDYNAMIC_LIST -DDYN_MIPS64_GENERIC
684+
XCCOMMON_OPT += $(foreach dcore,$(DYNAMIC_LIST),-DDYN_$(dcore))
685+
endif
681686
endif
682687

683688
ifeq ($(ARCH), loongarch64)
@@ -856,6 +861,11 @@ CCOMMON_OPT += -mabi=32
856861
BINARY_DEFINED = 1
857862
endif
858863

864+
ifneq (, $(filter $(CORE), MIPS64_GENERIC))
865+
CCOMMON_OPT += -DNO_MSA
866+
FCOMMON_OPT += -DNO_MSA
867+
endif
868+
859869
ifneq (, $(filter $(CORE),LOONGSON3R3 LOONGSON3R4))
860870
CCOMMON_OPT += -march=loongson3a
861871
FCOMMON_OPT += -march=loongson3a

TargetList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ MIPS1004K
6565
MIPS24K
6666

6767
4.MIPS64 CPU:
68+
MIPS64_GENERIC
6869
SICORTEX
6970
LOONGSON3A
7071
LOONGSON3B

common_mips64.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ static inline unsigned int rpcc(void){
8686
//__asm__ __volatile__("dmfc0 %0, $25, 1": "=r"(tmp):: "memory");
8787
//ret=tmp;
8888
__asm__ __volatile__(".set push \n"
89+
#if !defined(__mips_isa_rev) || __mips_isa_rev < 2
8990
".set mips32r2\n"
91+
#endif
9092
"rdhwr %0, $2\n"
9193
".set pop": "=r"(ret):: "memory");
9294

@@ -99,7 +101,9 @@ static inline unsigned int rpcc(void){
99101
static inline int WhereAmI(void){
100102
int ret=0;
101103
__asm__ __volatile__(".set push \n"
104+
#if !defined(__mips_isa_rev) || __mips_isa_rev < 2
102105
".set mips32r2\n"
106+
#endif
103107
"rdhwr %0, $0\n"
104108
".set pop": "=r"(ret):: "memory");
105109
return ret;
@@ -197,9 +201,15 @@ static inline int blas_quickdivide(blasint x, blasint y){
197201

198202
#if defined(ASSEMBLER) && !defined(NEEDPARAM)
199203

204+
#if defined(__mips_isa_rev) && __mips_isa_rev >= 6
205+
#define ASSEMBLER_ARCH mips64r6
206+
#else
207+
#define ASSEMBLER_ARCH mips64
208+
#endif
209+
200210
#define PROLOGUE \
201211
.text ;\
202-
.set mips64 ;\
212+
.set ASSEMBLER_ARCH ;\
203213
.align 5 ;\
204214
.globl REALNAME ;\
205215
.ent REALNAME ;\

cpuid_mips64.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7070
/* or implied, of The University of Texas at Austin. */
7171
/*********************************************************************/
7272

73-
#define CPU_UNKNOWN 0
74-
#define CPU_SICORTEX 1
75-
#define CPU_LOONGSON3R3 2
76-
#define CPU_LOONGSON3R4 3
77-
#define CPU_I6400 4
78-
#define CPU_P6600 5
79-
#define CPU_I6500 6
73+
#define CPU_UNKNOWN 0
74+
#define CPU_MIPS64_GENERIC 1
75+
#define CPU_SICORTEX 2
76+
#define CPU_LOONGSON3R3 3
77+
#define CPU_LOONGSON3R4 4
78+
#define CPU_I6400 5
79+
#define CPU_P6600 6
80+
#define CPU_I6500 7
8081

8182
static char *cpuname[] = {
8283
"UNKNOWN",
84+
"MIPS64_GENERIC"
8385
"SICORTEX",
8486
"LOONGSON3R3",
8587
"LOONGSON3R4",
@@ -113,8 +115,11 @@ int detect(void){
113115
return CPU_SICORTEX;
114116
}
115117
}
118+
119+
return CPU_MIPS64_GENERIC;
120+
#else
121+
return CPU_UNKNOWN;
116122
#endif
117-
return CPU_UNKNOWN;
118123
}
119124

120125
char *get_corename(void){
@@ -136,9 +141,11 @@ void get_subarchitecture(void){
136141
printf("P6600");
137142
}else if(detect()==CPU_I6500){
138143
printf("I6500");
139-
}else{
144+
}else if(detect()==CPU_SICORTEX){
140145
printf("SICORTEX");
141-
}
146+
}else{
147+
printf("MIPS64_GENERIC");
148+
}
142149
}
143150

144151
void get_subdirname(void){
@@ -215,8 +222,8 @@ void get_libname(void){
215222
printf("p6600\n");
216223
}else if(detect()==CPU_I6500) {
217224
printf("i6500\n");
218-
}else{
219-
printf("mips64\n");
225+
}else {
226+
printf("mips64_generic\n");
220227
}
221228
}
222229

driver/others/dynamic_mips64.c

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,48 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#include <sys/resource.h>
3939
#include "common.h"
4040

41+
#if (defined OS_LINUX || defined OS_ANDROID)
42+
#include <asm/hwcap.h>
43+
#include <sys/auxv.h>
44+
45+
#ifndef HWCAP_LOONGSON_CPUCFG
46+
#define HWCAP_LOONGSON_CPUCFG (1 << 14)
47+
#endif
48+
#endif
49+
50+
#ifdef DYNAMIC_LIST
51+
extern gotoblas_t gotoblas_MIPS64_GENERIC;
52+
#ifdef DYN_LOONGSON3R3
4153
extern gotoblas_t gotoblas_LOONGSON3R3;
54+
#else
55+
#define gotoblas_LOONGSON3R3 gotoblas_MIPS64_GENERIC
56+
#endif
57+
#ifdef DYN_LOONGSON3R4
4258
extern gotoblas_t gotoblas_LOONGSON3R4;
59+
#else
60+
#define gotoblas_LOONGSON3R4 gotoblas_MIPS64_GENERIC
61+
#endif
62+
#else
63+
extern gotoblas_t gotoblas_LOONGSON3R3;
64+
extern gotoblas_t gotoblas_LOONGSON3R4;
65+
extern gotoblas_t gotoblas_MIPS64_GENERIC;
66+
#endif
4367

4468
extern void openblas_warning(int verbose, const char * msg);
4569

46-
#define NUM_CORETYPES 2
70+
#define NUM_CORETYPES 3
4771

4872
static char *corename[] = {
73+
"MIPS64_GENERIC"
4974
"loongson3r3",
5075
"loongson3r4",
5176
"UNKNOWN"
5277
};
5378

5479
char *gotoblas_corename(void) {
55-
if (gotoblas == &gotoblas_LOONGSON3R3) return corename[0];
56-
if (gotoblas == &gotoblas_LOONGSON3R4) return corename[1];
80+
if (gotoblas == &gotoblas_MIPS64_GENERIC) return corename[0];
81+
if (gotoblas == &gotoblas_LOONGSON3R3) return corename[1];
82+
if (gotoblas == &gotoblas_LOONGSON3R4) return corename[2];
5783
return corename[NUM_CORETYPES];
5884
}
5985

@@ -73,77 +99,32 @@ static gotoblas_t *force_coretype(char *coretype) {
7399

74100
switch (found)
75101
{
76-
case 0: return (&gotoblas_LOONGSON3R3);
77-
case 1: return (&gotoblas_LOONGSON3R4);
102+
case 0: return (&gotoblas_MIPS64_GENERIC);
103+
case 1: return (&gotoblas_LOONGSON3R3);
104+
case 2: return (&gotoblas_LOONGSON3R4);
78105
}
79106
snprintf(message, 128, "Core not found: %s\n", coretype);
80107
openblas_warning(1, message);
81108
return NULL;
82109
}
83110

111+
#if (defined OS_LINUX || defined OS_ANDROID)
84112
#define MMI_MASK 0x00000010
85113
#define MSA_MASK 0x00000020
86114

87-
int fd[2];
88-
int support_cpucfg;
89-
90-
static void handler(int signum)
91-
{
92-
close(fd[1]);
93-
exit(1);
94-
}
95-
96-
/* Brief : Function to check if cpucfg supported on loongson
97-
* Return: 1 supported
98-
* 0 not supported
99-
*/
100-
static int cpucfg_test(void) {
101-
pid_t pid;
102-
int status = 0;
103-
104-
support_cpucfg = 0;
105-
pipe(fd);
106-
pid = fork();
107-
if (pid == 0) { /* Subprocess */
108-
struct sigaction act;
109-
close(fd[0]);
110-
/* Set signal action for SIGILL. */
111-
act.sa_handler = handler;
112-
sigaction(SIGILL,&act,NULL);
113-
114-
/* Execute cpucfg in subprocess. */
115-
__asm__ volatile(
116-
".insn \n\t"
117-
".word (0xc8080118) \n\t"
118-
:::
119-
);
120-
support_cpucfg = 1;
121-
write(fd[1],&support_cpucfg,sizeof(support_cpucfg));
122-
close(fd[1]);
123-
exit(0);
124-
} else if (pid > 0){ /* Parent process*/
125-
close(fd[1]);
126-
if ((waitpid(pid,&status,0) <= 0) ||
127-
(read(fd[0],&support_cpucfg,sizeof(support_cpucfg)) <= 0))
128-
support_cpucfg = 0;
129-
close(fd[0]);
130-
} else {
131-
support_cpucfg = 0;
132-
}
133-
134-
return support_cpucfg;
135-
}
136-
137115
static gotoblas_t *get_coretype_from_cpucfg(void) {
138116
int flag = 0;
139117
__asm__ volatile(
118+
".set push \n\t"
119+
".set noat \n\t"
140120
".insn \n\t"
141-
"dli $8, 0x01 \n\t"
142-
".word (0xc9084918) \n\t"
143-
"usw $9, 0x00(%0) \n\t"
121+
"dli $1, 0x01 \n\t"
122+
".word (0xc8080118) \n\t"
123+
"move %0, $1 \n\t"
124+
".set pop \n\t"
125+
: "=r"(flag)
126+
:
144127
:
145-
: "r"(&flag)
146-
: "memory"
147128
);
148129
if (flag & MSA_MASK)
149130
return (&gotoblas_LOONGSON3R4);
@@ -153,7 +134,7 @@ static gotoblas_t *get_coretype_from_cpucfg(void) {
153134
}
154135

155136
static gotoblas_t *get_coretype_from_cpuinfo(void) {
156-
#ifdef linux
137+
#ifdef __linux
157138
FILE *infile;
158139
char buffer[512], *p;
159140

@@ -176,17 +157,19 @@ static gotoblas_t *get_coretype_from_cpuinfo(void) {
176157
return NULL;
177158
}
178159
#endif
179-
return NULL;
160+
return NULL;
180161
}
162+
#endif
181163

182164
static gotoblas_t *get_coretype(void) {
183-
int ret = 0;
184-
185-
ret = cpucfg_test();
186-
if (ret == 1)
187-
return get_coretype_from_cpucfg();
188-
else
189-
return get_coretype_from_cpuinfo();
165+
#if (!defined OS_LINUX && !defined OS_ANDROID)
166+
return NULL;
167+
#else
168+
if (!(getauxval(AT_HWCAP) & HWCAP_LOONGSON_CPUCFG))
169+
return get_coretype_from_cpucfg();
170+
else
171+
return get_coretype_from_cpuinfo();
172+
#endif
190173
}
191174

192175
void gotoblas_dynamic_init(void) {
@@ -208,9 +191,9 @@ void gotoblas_dynamic_init(void) {
208191

209192
if (gotoblas == NULL)
210193
{
211-
snprintf(coremsg, 128, "Falling back to loongson3r3 core\n");
194+
snprintf(coremsg, 128, "Falling back to MIPS64_GENEIRC\n");
212195
openblas_warning(1, coremsg);
213-
gotoblas = &gotoblas_LOONGSON3R3;
196+
gotoblas = &gotoblas_MIPS64_GENERIC;
214197
}
215198

216199
if (gotoblas && gotoblas->init) {

getarch.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
131131
/* #define FORCE_PPC440 */
132132
/* #define FORCE_PPC440FP2 */
133133
/* #define FORCE_CELL */
134+
/* #define FORCE_MIPS64_GENERIC */
134135
/* #define FORCE_SICORTEX */
135136
/* #define FORCE_LOONGSON3R3 */
136137
/* #define FORCE_LOONGSON3R4 */
@@ -918,6 +919,20 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
918919
#define CORENAME "CELL"
919920
#endif
920921

922+
#ifdef FORCE_MIPS64_GENERIC
923+
#define FORCE
924+
#define ARCHITECTURE "MIPS"
925+
#define SUBARCHITECTURE "MIPS64_GENERIC"
926+
#define SUBDIRNAME "mips64"
927+
#define ARCHCONFIG "-DMIPS64_GENERIC " \
928+
"-DL1_DATA_SIZE=65536 -DL1_DATA_LINESIZE=32 " \
929+
"-DL2_SIZE=1048576 -DL2_LINESIZE=32 " \
930+
"-DDTB_DEFAULT_ENTRIES=64 -DDTB_SIZE=4096 -DL2_ASSOCIATIVE=8 "
931+
#define LIBNAME "mips64_generic"
932+
#define CORENAME "MIPS64_GENERIC"
933+
#else
934+
#endif
935+
921936
#ifdef FORCE_SICORTEX
922937
#define FORCE
923938
#define ARCHITECTURE "MIPS"

0 commit comments

Comments
 (0)