Optimize cdot function for POWER10
[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 #define CPU_1004K       2
76 #define CPU_24K         3
77
78 static char *cpuname[] = {
79   "UNKNOWN",
80   "P5600",
81   "MIPS1004K",
82   "MIPS24K"
83 };
84
85 int detect(void){
86
87 #ifdef __linux
88   FILE *infile;
89   char buffer[512], *p;
90
91   p = (char *)NULL;
92   infile = fopen("/proc/cpuinfo", "r");
93   while (fgets(buffer, sizeof(buffer), infile)){
94     if (!strncmp("cpu", buffer, 3)){
95         p = strchr(buffer, ':') + 2;
96 #if 0
97         fprintf(stderr, "%s \n", p);
98 #endif
99         break;
100       }
101   }
102
103   fclose(infile);
104
105   if(p != NULL){
106   if (strstr(p, "5600")) {
107     return CPU_P5600;
108   } else if (strstr(p, "1004K")) {
109     return CPU_1004K;
110   } else if (strstr(p, " 24K")) {
111     return CPU_24K;
112   } else  
113     return CPU_UNKNOWN;
114   }
115 #endif
116     return CPU_UNKNOWN;
117 }
118
119 char *get_corename(void){
120   return cpuname[detect()];
121 }
122
123 void get_architecture(void){
124   printf("MIPS");
125 }
126
127 void get_subarchitecture(void){
128   if(detect()==CPU_P5600|| detect()==CPU_1004K|| detect()==CPU_24K){
129     printf("P5600");
130   }else{
131     printf("UNKNOWN");
132   }
133 }
134
135 void get_subdirname(void){
136   printf("mips");
137 }
138
139 void get_cpuconfig(void){
140   if(detect()==CPU_P5600){
141     printf("#define P5600\n");
142     printf("#define L1_DATA_SIZE 65536\n");
143     printf("#define L1_DATA_LINESIZE 32\n");
144     printf("#define L2_SIZE 1048576\n");
145     printf("#define L2_LINESIZE 32\n");
146     printf("#define DTB_DEFAULT_ENTRIES 64\n");
147     printf("#define DTB_SIZE 4096\n");
148     printf("#define L2_ASSOCIATIVE 8\n");
149   } else if (detect()==CPU_1004K) {
150     printf("#define MIPS1004K\n");
151     printf("#define L1_DATA_SIZE 32768\n");
152     printf("#define L1_DATA_LINESIZE 32\n");
153     printf("#define L2_SIZE 262144\n");
154     printf("#define DTB_DEFAULT_ENTRIES 8\n");
155     printf("#define DTB_SIZE 4096\n");
156     printf("#define L2_ASSOCIATIVE 4\n");
157   } else if (detect()==CPU_24K) {
158     printf("#define MIPS24K\n");
159     printf("#define L1_DATA_SIZE 32768\n");
160     printf("#define L1_DATA_LINESIZE 32\n");
161     printf("#define L2_SIZE 32768\n");
162     printf("#define DTB_DEFAULT_ENTRIES 8\n");
163     printf("#define DTB_SIZE 4096\n");
164     printf("#define L2_ASSOCIATIVE 4\n");
165   }else{
166     printf("#define UNKNOWN\n");
167   }
168 }
169
170 void get_libname(void){
171   if(detect()==CPU_P5600) {
172     printf("p5600\n");
173   } else if (detect()==CPU_1004K) {
174     printf("mips1004K\n");
175   } else if (detect()==CPU_24K) {
176     printf("mips24K\n");
177   }else{
178     printf("mips\n");
179   }
180 }