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_arm64.c 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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_ARMV8 1
  30. static char *cpuname[] = {
  31. "UNKOWN",
  32. "ARMV8"
  33. };
  34. int get_feature(char *search)
  35. {
  36. #ifdef linux
  37. FILE *infile;
  38. char buffer[2048], *p,*t;
  39. p = (char *) NULL ;
  40. infile = fopen("/proc/cpuinfo", "r");
  41. while (fgets(buffer, sizeof(buffer), infile))
  42. {
  43. if (!strncmp("Features", buffer, 8))
  44. {
  45. p = strchr(buffer, ':') + 2;
  46. break;
  47. }
  48. }
  49. fclose(infile);
  50. if( p == NULL ) return;
  51. t = strtok(p," ");
  52. while( t = strtok(NULL," "))
  53. {
  54. if (!strcmp(t, search)) { return(1); }
  55. }
  56. #endif
  57. return(0);
  58. }
  59. int detect(void)
  60. {
  61. #ifdef linux
  62. FILE *infile;
  63. char buffer[512], *p;
  64. p = (char *) NULL ;
  65. infile = fopen("/proc/cpuinfo", "r");
  66. while (fgets(buffer, sizeof(buffer), infile))
  67. {
  68. if ((!strncmp("model name", buffer, 10)) || (!strncmp("Processor", buffer, 9)))
  69. {
  70. p = strchr(buffer, ':') + 2;
  71. break;
  72. }
  73. }
  74. fclose(infile);
  75. if(p != NULL)
  76. {
  77. if (strstr(p, "AArch64"))
  78. {
  79. return CPU_ARMV8;
  80. }
  81. }
  82. #endif
  83. return CPU_UNKNOWN;
  84. }
  85. char *get_corename(void)
  86. {
  87. return cpuname[detect()];
  88. }
  89. void get_architecture(void)
  90. {
  91. printf("ARM");
  92. }
  93. void get_subarchitecture(void)
  94. {
  95. int d = detect();
  96. switch (d)
  97. {
  98. case CPU_ARMV8:
  99. printf("ARMV8");
  100. break;
  101. default:
  102. printf("UNKNOWN");
  103. break;
  104. }
  105. }
  106. void get_subdirname(void)
  107. {
  108. printf("arm64");
  109. }
  110. void get_cpuconfig(void)
  111. {
  112. int d = detect();
  113. switch (d)
  114. {
  115. case CPU_ARMV8:
  116. printf("#define ARMV8\n");
  117. printf("#define L1_DATA_SIZE 32768\n");
  118. printf("#define L1_DATA_LINESIZE 64\n");
  119. printf("#define L2_SIZE 262144\n");
  120. printf("#define L2_LINESIZE 64\n");
  121. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  122. printf("#define DTB_SIZE 4096\n");
  123. printf("#define L2_ASSOCIATIVE 4\n");
  124. break;
  125. }
  126. }
  127. void get_libname(void)
  128. {
  129. int d = detect();
  130. switch (d)
  131. {
  132. case CPU_ARMV8:
  133. printf("armv8\n");
  134. break;
  135. }
  136. }
  137. void get_features(void)
  138. {
  139. #ifdef linux
  140. FILE *infile;
  141. char buffer[2048], *p,*t;
  142. p = (char *) NULL ;
  143. infile = fopen("/proc/cpuinfo", "r");
  144. while (fgets(buffer, sizeof(buffer), infile))
  145. {
  146. if (!strncmp("Features", buffer, 8))
  147. {
  148. p = strchr(buffer, ':') + 2;
  149. break;
  150. }
  151. }
  152. fclose(infile);
  153. if( p == NULL ) return;
  154. t = strtok(p," ");
  155. while( t = strtok(NULL," "))
  156. {
  157. }
  158. #endif
  159. return;
  160. }