@@ -38,6 +38,15 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
38
#include <sys/resource.h>
39
39
#include "common.h"
40
40
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
+
41
50
extern gotoblas_t gotoblas_LOONGSON3R3 ;
42
51
extern gotoblas_t gotoblas_LOONGSON3R4 ;
43
52
@@ -81,59 +90,10 @@ static gotoblas_t *force_coretype(char *coretype) {
81
90
return NULL ;
82
91
}
83
92
93
+ #if (defined OS_LINUX || defined OS_ANDROID )
84
94
#define MMI_MASK 0x00000010
85
95
#define MSA_MASK 0x00000020
86
96
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
-
137
97
static gotoblas_t * get_coretype_from_cpucfg (void ) {
138
98
int flag = 0 ;
139
99
__asm__ volatile (
@@ -153,7 +113,7 @@ static gotoblas_t *get_coretype_from_cpucfg(void) {
153
113
}
154
114
155
115
static gotoblas_t * get_coretype_from_cpuinfo (void ) {
156
- #ifdef linux
116
+ #ifdef __linux
157
117
FILE * infile ;
158
118
char buffer [512 ], * p ;
159
119
@@ -176,17 +136,19 @@ static gotoblas_t *get_coretype_from_cpuinfo(void) {
176
136
return NULL ;
177
137
}
178
138
#endif
179
- return NULL ;
139
+ return NULL ;
180
140
}
141
+ #endif
181
142
182
143
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 ();
144
+ #if (!defined OS_LINUX && !defined OS_ANDROID )
145
+ return NULL ;
146
+ #else
147
+ if (!(getauxval (AT_HWCAP ) & HWCAP_LOONGSON_CPUCFG ))
148
+ return get_coretype_from_cpucfg ();
149
+ else
150
+ return get_coretype_from_cpuinfo ();
151
+ #endif
190
152
}
191
153
192
154
void gotoblas_dynamic_init (void ) {
0 commit comments