Skip to content

Commit ce814e8

Browse files
authored
Merge pull request #3619 from martin-frbg/fixup-3613
Initial attempt at proper cpu detection on RISCV
2 parents 8f13ab9 + 46d2215 commit ce814e8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cpuid_riscv64.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ static char *cpuname[] = {
7979
};
8080

8181
int detect(void){
82+
#ifdef __linux
83+
FILE *infile;
84+
char buffer[512], *p;
85+
86+
p = (char *)NULL;
87+
infile = fopen("/proc/cpuinfo", "r");
88+
while (fgets(buffer, sizeof(buffer), infile)){
89+
if (!strncmp("isa", buffer, 3)){
90+
p = strchr(buffer, '4') + 1; /* the 4 in rv64ima... */
91+
#if 0
92+
fprintf(stderr, "%s\n", p);
93+
#endif
94+
break;
95+
}
96+
}
97+
98+
fclose(infile);
99+
100+
if (strchr(p, 'v')) return CPU_C910V;
101+
102+
return CPU_GENERIC;
103+
#endif
104+
82105
return CPU_GENERIC;
83106
}
84107

@@ -91,6 +114,7 @@ void get_architecture(void){
91114
}
92115

93116
void get_subarchitecture(void){
117+
printf("%s",cpuname[detect()]);
94118
}
95119

96120
void get_subdirname(void){

0 commit comments

Comments
 (0)