1 /*****************************************************************************
2 Copyright (c) 2011-2014, The OpenBLAS Project
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
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
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
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.
32 **********************************************************************************/
35 /*********************************************************************/
36 /* Copyright 2009, 2010 The University of Texas at Austin. */
37 /* All rights reserved. */
39 /* Redistribution and use in source and binary forms, with or */
40 /* without modification, are permitted provided that the following */
41 /* conditions are met: */
43 /* 1. Redistributions of source code must retain the above */
44 /* copyright notice, this list of conditions and the following */
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. */
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. */
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 /*********************************************************************/
74 #define CPU_SICORTEX 1
75 #define CPU_LOONGSON3A 2
76 #define CPU_LOONGSON3B 3
80 static char *cpuname[] = {
96 infile = fopen("/proc/cpuinfo", "r");
97 while (fgets(buffer, sizeof(buffer), infile)){
98 if (!strncmp("cpu", buffer, 3)){
99 p = strchr(buffer, ':') + 2;
101 fprintf(stderr, "%s\n", p);
110 if (strstr(p, "Loongson-3A")){
111 return CPU_LOONGSON3A;
112 }else if(strstr(p, "Loongson-3B")){
113 return CPU_LOONGSON3B;
114 }else if (strstr(p, "Loongson-3")){
115 infile = fopen("/proc/cpuinfo", "r");
117 while (fgets(buffer, sizeof(buffer), infile)){
118 if (!strncmp("system type", buffer, 11)){
119 p = strchr(buffer, ':') + 2;
124 if (strstr(p, "loongson3a"))
125 return CPU_LOONGSON3A;
130 //Check model name for Loongson3
131 infile = fopen("/proc/cpuinfo", "r");
133 while (fgets(buffer, sizeof(buffer), infile)){
134 if (!strncmp("model name", buffer, 10)){
135 p = strchr(buffer, ':') + 2;
141 if (strstr(p, "Loongson-3A")){
142 return CPU_LOONGSON3A;
143 }else if(strstr(p, "Loongson-3B")){
144 return CPU_LOONGSON3B;
151 char *get_corename(void){
152 return cpuname[detect()];
155 void get_architecture(void){
159 void get_subarchitecture(void){
160 if(detect()==CPU_LOONGSON3A) {
161 printf("LOONGSON3A");
162 }else if(detect()==CPU_LOONGSON3B){
163 printf("LOONGSON3B");
164 }else if(detect()==CPU_I6400){
166 }else if(detect()==CPU_P6600){
173 void get_subdirname(void){
177 void get_cpuconfig(void){
178 if(detect()==CPU_LOONGSON3A) {
179 printf("#define LOONGSON3A\n");
180 printf("#define L1_DATA_SIZE 65536\n");
181 printf("#define L1_DATA_LINESIZE 32\n");
182 printf("#define L2_SIZE 512488\n");
183 printf("#define L2_LINESIZE 32\n");
184 printf("#define DTB_DEFAULT_ENTRIES 64\n");
185 printf("#define DTB_SIZE 4096\n");
186 printf("#define L2_ASSOCIATIVE 4\n");
187 }else if(detect()==CPU_LOONGSON3B){
188 printf("#define LOONGSON3B\n");
189 printf("#define L1_DATA_SIZE 65536\n");
190 printf("#define L1_DATA_LINESIZE 32\n");
191 printf("#define L2_SIZE 512488\n");
192 printf("#define L2_LINESIZE 32\n");
193 printf("#define DTB_DEFAULT_ENTRIES 64\n");
194 printf("#define DTB_SIZE 4096\n");
195 printf("#define L2_ASSOCIATIVE 4\n");
196 }else if(detect()==CPU_I6400){
197 printf("#define I6400\n");
198 printf("#define L1_DATA_SIZE 65536\n");
199 printf("#define L1_DATA_LINESIZE 32\n");
200 printf("#define L2_SIZE 1048576\n");
201 printf("#define L2_LINESIZE 32\n");
202 printf("#define DTB_DEFAULT_ENTRIES 64\n");
203 printf("#define DTB_SIZE 4096\n");
204 printf("#define L2_ASSOCIATIVE 8\n");
205 }else if(detect()==CPU_P6600){
206 printf("#define P6600\n");
207 printf("#define L1_DATA_SIZE 65536\n");
208 printf("#define L1_DATA_LINESIZE 32\n");
209 printf("#define L2_SIZE 1048576\n");
210 printf("#define L2_LINESIZE 32\n");
211 printf("#define DTB_DEFAULT_ENTRIES 64\n");
212 printf("#define DTB_SIZE 4096\n");
213 printf("#define L2_ASSOCIATIVE 8\n");
215 printf("#define SICORTEX\n");
216 printf("#define L1_DATA_SIZE 32768\n");
217 printf("#define L1_DATA_LINESIZE 32\n");
218 printf("#define L2_SIZE 512488\n");
219 printf("#define L2_LINESIZE 32\n");
220 printf("#define DTB_DEFAULT_ENTRIES 32\n");
221 printf("#define DTB_SIZE 4096\n");
222 printf("#define L2_ASSOCIATIVE 8\n");
226 void get_libname(void){
227 if(detect()==CPU_LOONGSON3A) {
228 printf("loongson3a\n");
229 }else if(detect()==CPU_LOONGSON3B) {
230 printf("loongson3b\n");
231 }else if(detect()==CPU_I6400) {
233 }else if(detect()==CPU_P6600) {