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.

cscal_microk_skylakex-2.c 6.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /***************************************************************************
  2. Copyright (c) 2014-2015, 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. /* need a new enough GCC for avx512 support */
  28. #ifdef __NVCOMPILER
  29. #define NVCOMPVERS ( __NVCOMPILER_MAJOR__ * 100 + __NVCOMPILER_MINOR__ )
  30. #endif
  31. #if (( defined(__GNUC__) && __GNUC__ > 6 && defined(__AVX2__)) || (defined(__clang__) && __clang_major__ >= 6)) || ( defined(__NVCOMPILER) && NVCOMPVERS >= 2203 )
  32. #include <immintrin.h>
  33. #define HAVE_KERNEL_16 1
  34. static void cscal_kernel_16( BLASLONG n, FLOAT *alpha, FLOAT *x)
  35. {
  36. BLASLONG i = 0;
  37. BLASLONG n2 = n + n;
  38. #ifdef __AVX512CD__
  39. /* _mm512_addsub_ps does not exist so we flip signs for odd elements of da_i */
  40. __m512 da_r = _mm512_set1_ps(alpha[0]);
  41. __m512 da_i = _mm512_set1_ps(alpha[1]) * _mm512_set4_ps(1, -1, 1, -1);
  42. for (; i < n2; i += 32) {
  43. __m512 x0 = _mm512_loadu_ps(&x[i + 0]);
  44. __m512 x1 = _mm512_loadu_ps(&x[i + 16]);
  45. __m512 y0 = _mm512_permute_ps(x0, 0xb1);
  46. __m512 y1 = _mm512_permute_ps(x1, 0xb1);
  47. _mm512_storeu_ps(&x[i + 0], _mm512_add_ps(da_r * x0, da_i * y0));
  48. _mm512_storeu_ps(&x[i + 16], _mm512_add_ps(da_r * x1, da_i * y1));
  49. }
  50. #else
  51. __m256 da_r = _mm256_set1_ps(alpha[0]);
  52. __m256 da_i = _mm256_set1_ps(alpha[1]);
  53. for (; i < n2; i += 32) {
  54. __m256 x0 = _mm256_loadu_ps(&x[i + 0]);
  55. __m256 x1 = _mm256_loadu_ps(&x[i + 8]);
  56. __m256 x2 = _mm256_loadu_ps(&x[i + 16]);
  57. __m256 x3 = _mm256_loadu_ps(&x[i + 24]);
  58. __m256 y0 = _mm256_permute_ps(x0, 0xb1);
  59. __m256 y1 = _mm256_permute_ps(x1, 0xb1);
  60. __m256 y2 = _mm256_permute_ps(x2, 0xb1);
  61. __m256 y3 = _mm256_permute_ps(x3, 0xb1);
  62. _mm256_storeu_ps(&x[i + 0], _mm256_addsub_ps(da_r * x0, da_i * y0));
  63. _mm256_storeu_ps(&x[i + 8], _mm256_addsub_ps(da_r * x1, da_i * y1));
  64. _mm256_storeu_ps(&x[i + 16], _mm256_addsub_ps(da_r * x2, da_i * y2));
  65. _mm256_storeu_ps(&x[i + 24], _mm256_addsub_ps(da_r * x3, da_i * y3));
  66. }
  67. #endif
  68. }
  69. static void cscal_kernel_16_zero_r( BLASLONG n, FLOAT *alpha, FLOAT *x)
  70. {
  71. BLASLONG i = 0;
  72. BLASLONG n2 = n + n;
  73. #ifdef __AVX512CD__
  74. __m512 da_i = _mm512_set1_ps(alpha[1]) * _mm512_set4_ps(1, -1, 1, -1);
  75. for (; i < n2; i += 32) {
  76. __m512 y0 = _mm512_permute_ps(_mm512_loadu_ps(&x[i + 0]), 0xb1);
  77. __m512 y1 = _mm512_permute_ps(_mm512_loadu_ps(&x[i + 16]), 0xb1);
  78. _mm512_storeu_ps(&x[i + 0], da_i * y0);
  79. _mm512_storeu_ps(&x[i + 16], da_i * y1);
  80. }
  81. #else
  82. __m256 da_i = _mm256_set1_ps(alpha[1]) * _mm256_set_ps(1, -1, 1, -1, 1, -1, 1, -1);
  83. for (; i < n2; i += 32) {
  84. __m256 y0 = _mm256_permute_ps(_mm256_loadu_ps(&x[i + 0]), 0xb1);
  85. __m256 y1 = _mm256_permute_ps(_mm256_loadu_ps(&x[i + 8]), 0xb1);
  86. __m256 y2 = _mm256_permute_ps(_mm256_loadu_ps(&x[i + 16]), 0xb1);
  87. __m256 y3 = _mm256_permute_ps(_mm256_loadu_ps(&x[i + 24]), 0xb1);
  88. _mm256_storeu_ps(&x[i + 0], da_i * y0);
  89. _mm256_storeu_ps(&x[i + 8], da_i * y1);
  90. _mm256_storeu_ps(&x[i + 16], da_i * y2);
  91. _mm256_storeu_ps(&x[i + 24], da_i * y3);
  92. }
  93. #endif
  94. }
  95. static void cscal_kernel_16_zero_i( BLASLONG n, FLOAT *alpha, FLOAT *x)
  96. {
  97. BLASLONG i = 0;
  98. BLASLONG n2 = n + n;
  99. #ifdef __AVX512CD__
  100. __m512 da_r = _mm512_set1_ps(alpha[0]);
  101. for (; i < n2; i += 32) {
  102. _mm512_storeu_ps(&x[i + 0], da_r * _mm512_loadu_ps(&x[i + 0]));
  103. _mm512_storeu_ps(&x[i + 16], da_r * _mm512_loadu_ps(&x[i + 16]));
  104. }
  105. #else
  106. __m256 da_r = _mm256_set1_ps(alpha[0]);
  107. for (; i < n2; i += 32) {
  108. _mm256_storeu_ps(&x[i + 0], da_r * _mm256_loadu_ps(&x[i + 0]));
  109. _mm256_storeu_ps(&x[i + 8], da_r * _mm256_loadu_ps(&x[i + 8]));
  110. _mm256_storeu_ps(&x[i + 16], da_r * _mm256_loadu_ps(&x[i + 16]));
  111. _mm256_storeu_ps(&x[i + 24], da_r * _mm256_loadu_ps(&x[i + 24]));
  112. }
  113. #endif
  114. }
  115. static void cscal_kernel_16_zero( BLASLONG n, FLOAT *alpha, FLOAT *x)
  116. {
  117. BLASLONG i = 0;
  118. BLASLONG n2 = n + n;
  119. /* question to self: Why is this not just memset() */
  120. #ifdef __AVX512CD__
  121. __m512 zero = _mm512_setzero_ps();
  122. for (; i < n2; i += 32) {
  123. _mm512_storeu_ps(&x[i], zero);
  124. _mm512_storeu_ps(&x[i + 16], zero);
  125. }
  126. #else
  127. __m256 zero = _mm256_setzero_ps();
  128. for (; i < n2; i += 32) {
  129. _mm256_storeu_ps(&x[i + 0], zero);
  130. _mm256_storeu_ps(&x[i + 8], zero);
  131. _mm256_storeu_ps(&x[i + 16], zero);
  132. _mm256_storeu_ps(&x[i + 24], zero);
  133. }
  134. #endif
  135. }
  136. #else
  137. #include "cscal_microk_haswell-2.c"
  138. #endif