Add an AVX512 enabled DSCAL function
[platform/upstream/openblas.git] / cpuid_mips64.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_SICORTEX    1
75 #define CPU_LOONGSON3A  2
76 #define CPU_LOONGSON3B  3
77 #define CPU_I6400       4
78 #define CPU_P6600       5
79 #define CPU_I6500       6
80
81 static char *cpuname[] = {
82   "UNKOWN",
83   "SICORTEX",
84   "LOONGSON3A",
85   "LOONGSON3B",
86   "I6400",
87   "P6600",
88   "I6500"
89 };
90
91 int detect(void){
92
93 #ifdef linux
94   FILE *infile;
95   char buffer[512], *p;
96
97   p = (char *)NULL;
98   infile = fopen("/proc/cpuinfo", "r");
99   while (fgets(buffer, sizeof(buffer), infile)){
100     if (!strncmp("cpu", buffer, 3)){
101         p = strchr(buffer, ':') + 2;
102 #if 0
103         fprintf(stderr, "%s\n", p);
104 #endif
105         break;
106       }
107   }
108
109   fclose(infile);
110
111   if(p != NULL){
112   if (strstr(p, "Loongson-3A")){
113     return CPU_LOONGSON3A;
114   }else if(strstr(p, "Loongson-3B")){
115     return CPU_LOONGSON3B;
116   }else if (strstr(p, "Loongson-3")){
117     infile = fopen("/proc/cpuinfo", "r");
118     p = (char *)NULL;
119     while (fgets(buffer, sizeof(buffer), infile)){
120       if (!strncmp("system type", buffer, 11)){
121         p = strchr(buffer, ':') + 2;
122         break;
123       }
124     }
125     fclose(infile);
126     if (strstr(p, "loongson3a"))
127       return CPU_LOONGSON3A;
128   }else{
129     return CPU_SICORTEX;
130   }
131   }
132   //Check model name for Loongson3
133   infile = fopen("/proc/cpuinfo", "r");
134   p = (char *)NULL;
135   while (fgets(buffer, sizeof(buffer), infile)){
136     if (!strncmp("model name", buffer, 10)){
137       p = strchr(buffer, ':') + 2;
138       break;
139     }
140   }
141   fclose(infile);
142   if(p != NULL){
143   if (strstr(p, "Loongson-3A")){
144     return CPU_LOONGSON3A;
145   }else if(strstr(p, "Loongson-3B")){
146     return CPU_LOONGSON3B;
147   }
148   }
149 #endif
150     return CPU_UNKNOWN;
151 }
152
153 char *get_corename(void){
154   return cpuname[detect()];
155 }
156
157 void get_architecture(void){
158   printf("MIPS64");
159 }
160
161 void get_subarchitecture(void){
162   if(detect()==CPU_LOONGSON3A) {
163     printf("LOONGSON3A");
164   }else if(detect()==CPU_LOONGSON3B){
165     printf("LOONGSON3B");
166   }else if(detect()==CPU_I6400){
167     printf("I6400");
168   }else if(detect()==CPU_P6600){
169     printf("P6600");
170   }else if(detect()==CPU_I6500){
171     printf("I6500");
172   }else{
173     printf("SICORTEX");
174   }
175 }
176
177 void get_subdirname(void){
178   printf("mips64");
179 }
180
181 void get_cpuconfig(void){
182   if(detect()==CPU_LOONGSON3A) {
183     printf("#define LOONGSON3A\n");
184     printf("#define L1_DATA_SIZE 65536\n");
185     printf("#define L1_DATA_LINESIZE 32\n");
186     printf("#define L2_SIZE 512488\n");
187     printf("#define L2_LINESIZE 32\n");
188     printf("#define DTB_DEFAULT_ENTRIES 64\n");
189     printf("#define DTB_SIZE 4096\n");
190     printf("#define L2_ASSOCIATIVE 4\n");
191   }else if(detect()==CPU_LOONGSON3B){
192     printf("#define LOONGSON3B\n");
193     printf("#define L1_DATA_SIZE 65536\n");
194     printf("#define L1_DATA_LINESIZE 32\n");
195     printf("#define L2_SIZE 512488\n");
196     printf("#define L2_LINESIZE 32\n");
197     printf("#define DTB_DEFAULT_ENTRIES 64\n");
198     printf("#define DTB_SIZE 4096\n");
199     printf("#define L2_ASSOCIATIVE 4\n");
200   }else if(detect()==CPU_I6400){
201     printf("#define I6400\n");
202     printf("#define L1_DATA_SIZE 65536\n");
203     printf("#define L1_DATA_LINESIZE 32\n");
204     printf("#define L2_SIZE 1048576\n");
205     printf("#define L2_LINESIZE 32\n");
206     printf("#define DTB_DEFAULT_ENTRIES 64\n");
207     printf("#define DTB_SIZE 4096\n");
208     printf("#define L2_ASSOCIATIVE 8\n");
209   }else if(detect()==CPU_P6600){
210     printf("#define P6600\n");
211     printf("#define L1_DATA_SIZE 65536\n");
212     printf("#define L1_DATA_LINESIZE 32\n");
213     printf("#define L2_SIZE 1048576\n");
214     printf("#define L2_LINESIZE 32\n");
215     printf("#define DTB_DEFAULT_ENTRIES 64\n");
216     printf("#define DTB_SIZE 4096\n");
217     printf("#define L2_ASSOCIATIVE 8\n");
218   }else if(detect()==CPU_I6500){
219     printf("#define I6500\n");
220     printf("#define L1_DATA_SIZE 65536\n");
221     printf("#define L1_DATA_LINESIZE 32\n");
222     printf("#define L2_SIZE 1048576\n");
223     printf("#define L2_LINESIZE 32\n");
224     printf("#define DTB_DEFAULT_ENTRIES 64\n");
225     printf("#define DTB_SIZE 4096\n");
226     printf("#define L2_ASSOCIATIVE 8\n");
227   }else{
228     printf("#define SICORTEX\n");
229     printf("#define L1_DATA_SIZE 32768\n");
230     printf("#define L1_DATA_LINESIZE 32\n");
231     printf("#define L2_SIZE 512488\n");
232     printf("#define L2_LINESIZE 32\n");
233     printf("#define DTB_DEFAULT_ENTRIES 32\n");
234     printf("#define DTB_SIZE 4096\n");
235     printf("#define L2_ASSOCIATIVE 8\n");
236   }
237 }
238
239 void get_libname(void){
240   if(detect()==CPU_LOONGSON3A) {
241     printf("loongson3a\n");
242   }else if(detect()==CPU_LOONGSON3B) {
243     printf("loongson3b\n");
244   }else if(detect()==CPU_I6400) {
245     printf("i6400\n");
246   }else if(detect()==CPU_P6600) {
247     printf("p6600\n");
248   }else if(detect()==CPU_I6500) {
249     printf("i6500\n");
250   }else{
251     printf("mips64\n");
252   }
253 }