No strncasecmp with MSVC
[platform/upstream/openblas.git] / cpuid_mips.c
1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9    1. Redistributions of source code must retain the above copyright
10       notice, this list of conditions and the following disclaimer.
11
12    2. Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the
15       distribution.
16    3. Neither the name of the OpenBLAS project nor the names of 
17       its contributors may be used to endorse or promote products 
18       derived from this software without specific prior written 
19       permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 **********************************************************************************/
33
34
35 /*********************************************************************/
36 /* Copyright 2009, 2010 The University of Texas at Austin.           */
37 /* All rights reserved.                                              */
38 /*                                                                   */
39 /* Redistribution and use in source and binary forms, with or        */
40 /* without modification, are permitted provided that the following   */
41 /* conditions are met:                                               */
42 /*                                                                   */
43 /*   1. Redistributions of source code must retain the above         */
44 /*      copyright notice, this list of conditions and the following  */
45 /*      disclaimer.                                                  */
46 /*                                                                   */
47 /*   2. Redistributions in binary form must reproduce the above      */
48 /*      copyright notice, this list of conditions and the following  */
49 /*      disclaimer in the documentation and/or other materials       */
50 /*      provided with the distribution.                              */
51 /*                                                                   */
52 /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
53 /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
54 /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
55 /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
56 /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
57 /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
58 /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
59 /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
60 /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
61 /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
62 /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
63 /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
64 /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
65 /*    POSSIBILITY OF SUCH DAMAGE.                                    */
66 /*                                                                   */
67 /* The views and conclusions contained in the software and           */
68 /* documentation are those of the authors and should not be          */
69 /* interpreted as representing official policies, either expressed   */
70 /* or implied, of The University of Texas at Austin.                 */
71 /*********************************************************************/
72
73 #define CPU_UNKNOWN     0
74 #define CPU_P5600       1
75
76 static char *cpuname[] = {
77   "UNKOWN",
78   "P5600"
79 };
80
81 int detect(void){
82
83 #ifdef linux
84   FILE *infile;
85   char buffer[512], *p;
86
87   p = (char *)NULL;
88   infile = fopen("/proc/cpuinfo", "r");
89   while (fgets(buffer, sizeof(buffer), infile)){
90     if (!strncmp("cpu", buffer, 3)){
91         p = strchr(buffer, ':') + 2;
92 #if 0
93         fprintf(stderr, "%s\n", p);
94 #endif
95         break;
96       }
97   }
98
99   fclose(infile);
100
101   if(p != NULL){
102   if (strstr(p, "Loongson-3A")){
103     return CPU_LOONGSON3A;
104   }else if(strstr(p, "Loongson-3B")){
105     return CPU_LOONGSON3B;
106   }else if (strstr(p, "Loongson-3")){
107     infile = fopen("/proc/cpuinfo", "r");
108     p = (char *)NULL;
109     while (fgets(buffer, sizeof(buffer), infile)){
110       if (!strncmp("system type", buffer, 11)){
111         p = strchr(buffer, ':') + 2;
112         break;
113       }
114     }
115     fclose(infile);
116     if (strstr(p, "loongson3a"))
117       return CPU_LOONGSON3A;
118   }else{
119     return CPU_UNKNOWN;
120   }
121   }
122   //Check model name for Loongson3
123   infile = fopen("/proc/cpuinfo", "r");
124   p = (char *)NULL;
125   while (fgets(buffer, sizeof(buffer), infile)){
126     if (!strncmp("model name", buffer, 10)){
127       p = strchr(buffer, ':') + 2;
128       break;
129     }
130   }
131   fclose(infile);
132   if(p != NULL){
133   if (strstr(p, "Loongson-3A")){
134     return CPU_LOONGSON3A;
135   }else if(strstr(p, "Loongson-3B")){
136     return CPU_LOONGSON3B;
137   }
138   }
139 #endif
140     return CPU_UNKNOWN;
141 }
142
143 char *get_corename(void){
144   return cpuname[detect()];
145 }
146
147 void get_architecture(void){
148   printf("MIPS");
149 }
150
151 void get_subarchitecture(void){
152   if(detect()==CPU_P5600){
153     printf("P5600");
154   }else{
155     printf("UNKNOWN");
156   }
157 }
158
159 void get_subdirname(void){
160   printf("mips");
161 }
162
163 void get_cpuconfig(void){
164   if(detect()==CPU_P5600){
165     printf("#define P5600\n");
166     printf("#define L1_DATA_SIZE 65536\n");
167     printf("#define L1_DATA_LINESIZE 32\n");
168     printf("#define L2_SIZE 1048576\n");
169     printf("#define L2_LINESIZE 32\n");
170     printf("#define DTB_DEFAULT_ENTRIES 64\n");
171     printf("#define DTB_SIZE 4096\n");
172     printf("#define L2_ASSOCIATIVE 8\n");
173   }else{
174     printf("#define UNKNOWN\n");
175   }
176 }
177
178 void get_libname(void){
179   if(detect()==CPU_P5600) {
180     printf("p5600\n");
181   }else{
182     printf("mips\n");
183   }
184 }