You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpuid_arm.c 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**************************************************************************
  2. Copyright (c) 2013, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include <string.h>
  28. #define CPU_UNKNOWN 0
  29. #define CPU_ARMV6 1
  30. #define CPU_ARMV7 2
  31. #define CPU_CORTEXA15 3
  32. static char *cpuname[] = {
  33. "UNKOWN",
  34. "ARMV6",
  35. "ARMV7",
  36. "CORTEXA15"
  37. };
  38. int get_feature(char *search)
  39. {
  40. #ifdef linux
  41. FILE *infile;
  42. char buffer[2048], *p,*t;
  43. p = (char *) NULL ;
  44. infile = fopen("/proc/cpuinfo", "r");
  45. while (fgets(buffer, sizeof(buffer), infile))
  46. {
  47. if (!strncmp("Features", buffer, 8))
  48. {
  49. p = strchr(buffer, ':') + 2;
  50. break;
  51. }
  52. }
  53. fclose(infile);
  54. if( p == NULL ) return;
  55. t = strtok(p," ");
  56. while( t = strtok(NULL," "))
  57. {
  58. if (!strcmp(t, search)) { return(1); }
  59. }
  60. #endif
  61. return(0);
  62. }
  63. int detect(void)
  64. {
  65. #ifdef linux
  66. FILE *infile;
  67. char buffer[512], *p;
  68. p = (char *) NULL ;
  69. infile = fopen("/proc/cpuinfo", "r");
  70. while (fgets(buffer, sizeof(buffer), infile))
  71. {
  72. if (!strncmp("model name", buffer, 10))
  73. {
  74. p = strchr(buffer, ':') + 2;
  75. break;
  76. }
  77. }
  78. fclose(infile);
  79. if(p != NULL)
  80. {
  81. if (strstr(p, "ARMv7"))
  82. {
  83. if ( get_feature("vfpv4"))
  84. return CPU_ARMV7;
  85. if ( get_feature("vfpv3"))
  86. return CPU_ARMV7;
  87. if ( get_feature("vfp"))
  88. return CPU_ARMV6;
  89. }
  90. if (strstr(p, "ARMv6"))
  91. {
  92. if ( get_feature("vfp"))
  93. return CPU_ARMV6;
  94. }
  95. }
  96. #endif
  97. return CPU_UNKNOWN;
  98. }
  99. char *get_corename(void)
  100. {
  101. return cpuname[detect()];
  102. }
  103. void get_architecture(void)
  104. {
  105. printf("ARM");
  106. }
  107. void get_subarchitecture(void)
  108. {
  109. int d = detect();
  110. switch (d)
  111. {
  112. case CPU_ARMV7:
  113. printf("ARMV7");
  114. break;
  115. case CPU_ARMV6:
  116. printf("ARMV6");
  117. break;
  118. default:
  119. printf("UNKNOWN");
  120. break;
  121. }
  122. }
  123. void get_subdirname(void)
  124. {
  125. printf("arm");
  126. }
  127. void get_cpuconfig(void)
  128. {
  129. int d = detect();
  130. switch (d)
  131. {
  132. case CPU_ARMV7:
  133. printf("#define ARMV7\n");
  134. printf("#define HAVE_VFP\n");
  135. printf("#define HAVE_VFPV3\n");
  136. if ( get_feature("neon")) printf("#define HAVE_NEON\n");
  137. if ( get_feature("vfpv4")) printf("#define HAVE_VFPV4\n");
  138. printf("#define L1_DATA_SIZE 65536\n");
  139. printf("#define L1_DATA_LINESIZE 32\n");
  140. printf("#define L2_SIZE 512488\n");
  141. printf("#define L2_LINESIZE 32\n");
  142. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  143. printf("#define DTB_SIZE 4096\n");
  144. printf("#define L2_ASSOCIATIVE 4\n");
  145. break;
  146. case CPU_ARMV6:
  147. printf("#define ARMV6\n");
  148. printf("#define HAVE_VFP\n");
  149. printf("#define L1_DATA_SIZE 65536\n");
  150. printf("#define L1_DATA_LINESIZE 32\n");
  151. printf("#define L2_SIZE 512488\n");
  152. printf("#define L2_LINESIZE 32\n");
  153. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  154. printf("#define DTB_SIZE 4096\n");
  155. printf("#define L2_ASSOCIATIVE 4\n");
  156. break;
  157. }
  158. }
  159. void get_libname(void)
  160. {
  161. int d = detect();
  162. switch (d)
  163. {
  164. case CPU_ARMV7:
  165. printf("armv7\n");
  166. break;
  167. case CPU_ARMV6:
  168. printf("armv6\n");
  169. break;
  170. }
  171. }
  172. void get_features(void)
  173. {
  174. #ifdef linux
  175. FILE *infile;
  176. char buffer[2048], *p,*t;
  177. p = (char *) NULL ;
  178. infile = fopen("/proc/cpuinfo", "r");
  179. while (fgets(buffer, sizeof(buffer), infile))
  180. {
  181. if (!strncmp("Features", buffer, 8))
  182. {
  183. p = strchr(buffer, ':') + 2;
  184. break;
  185. }
  186. }
  187. fclose(infile);
  188. if( p == NULL ) return;
  189. t = strtok(p," ");
  190. while( t = strtok(NULL," "))
  191. {
  192. if (!strcmp(t, "vfp")) { printf("HAVE_VFP=1\n"); continue; }
  193. if (!strcmp(t, "vfpv3")) { printf("HAVE_VFPV3=1\n"); continue; }
  194. if (!strcmp(t, "vfpv4")) { printf("HAVE_VFPV4=1\n"); continue; }
  195. if (!strcmp(t, "neon")) { printf("HAVE_NEON=1\n"); continue; }
  196. }
  197. #endif
  198. return;
  199. }