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_loongarch64.c 4.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*****************************************************************************
  2. Copyright (c) 2011-2020, 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
  16. permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **********************************************************************************/
  28. #include <stdint.h>
  29. #include <sys/auxv.h>
  30. #include <stdio.h>
  31. /* If LASX extension instructions supported,
  32. * using core LOONGSON3R5
  33. * If only LSX extension instructions supported,
  34. * using core LOONGSON2K1000
  35. * If neither LASX nor LSX extension instructions supported,
  36. * using core LOONGSONGENERIC (As far as I know, there is no such
  37. * CPU yet)
  38. */
  39. #define CPU_GENERIC 0
  40. #define CPU_LOONGSON3R5 1
  41. #define CPU_LOONGSON2K1000 2
  42. #define LA_HWCAP_LSX (1U << 4)
  43. #define LA_HWCAP_LASX (1U << 5)
  44. static char *cpuname[] = {
  45. "LOONGSONGENERIC",
  46. "LOONGSON3R5",
  47. "LOONGSON2K1000"
  48. };
  49. static char *cpuname_lower[] = {
  50. "loongsongeneric",
  51. "loongson3r5",
  52. "loongson2k1000"
  53. };
  54. int detect(void) {
  55. #ifdef __linux
  56. int hwcap = (int)getauxval(AT_HWCAP);
  57. if (hwcap & LA_HWCAP_LASX)
  58. return CPU_LOONGSON3R5;
  59. else if (hwcap & LA_HWCAP_LSX)
  60. return CPU_LOONGSON2K1000;
  61. else
  62. return CPU_GENERIC;
  63. #endif
  64. return CPU_GENERIC;
  65. }
  66. char *get_corename(void) {
  67. return cpuname[detect()];
  68. }
  69. void get_architecture(void) {
  70. printf("LOONGARCH64");
  71. }
  72. void get_subarchitecture(void) {
  73. int d = detect();
  74. printf("%s", cpuname[d]);
  75. }
  76. void get_subdirname(void) {
  77. printf("loongarch64");
  78. }
  79. void get_cpuconfig(void) {
  80. uint32_t hwcaps = 0;
  81. int d = detect();
  82. switch (d) {
  83. case CPU_LOONGSON3R5:
  84. printf("#define LOONGSON3R5\n");
  85. printf("#define L1_DATA_SIZE 65536\n");
  86. printf("#define L1_DATA_LINESIZE 64\n");
  87. printf("#define L2_SIZE 1048576\n");
  88. printf("#define L2_LINESIZE 64\n");
  89. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  90. printf("#define DTB_SIZE 4096\n");
  91. printf("#define L2_ASSOCIATIVE 16\n");
  92. break;
  93. case CPU_LOONGSON2K1000:
  94. printf("#define LOONGSON2K1000\n");
  95. printf("#define L1_DATA_SIZE 65536\n");
  96. printf("#define L1_DATA_LINESIZE 64\n");
  97. printf("#define L2_SIZE 262144\n");
  98. printf("#define L2_LINESIZE 64\n");
  99. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  100. printf("#define DTB_SIZE 4096\n");
  101. printf("#define L2_ASSOCIATIVE 16\n");
  102. break;
  103. default:
  104. printf("#define LOONGSONGENERIC\n");
  105. printf("#define L1_DATA_SIZE 65536\n");
  106. printf("#define L1_DATA_LINESIZE 64\n");
  107. printf("#define L2_SIZE 262144\n");
  108. printf("#define L2_LINESIZE 64\n");
  109. printf("#define DTB_DEFAULT_ENTRIES 64\n");
  110. printf("#define DTB_SIZE 4096\n");
  111. printf("#define L2_ASSOCIATIVE 16\n");
  112. break;
  113. }
  114. hwcaps = (uint32_t)getauxval( AT_HWCAP );
  115. if (hwcaps & LA_HWCAP_LSX) printf("#define HAVE_LSX\n");
  116. if (hwcaps & LA_HWCAP_LASX) printf("#define HAVE_LASX\n");
  117. }
  118. void get_libname(void){
  119. int d = detect();
  120. printf("%s", cpuname_lower[d]);
  121. }