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.

cdot.c 5.6 kB

6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*Copyright (c) 2013-201\n8, The OpenBLAS Project
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions are
  5. met:
  6. 1. Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the
  11. distribution.
  12. 3. Neither the name of the OpenBLAS project nor the names of
  13. its contributors may be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  24. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *****************************************************************************/
  26. #if !defined(__VEC__) || !defined(__ALTIVEC__)
  27. #include "../arm/zdot.c"
  28. #else
  29. #include "common.h"
  30. #if defined(POWER10)
  31. #pragma GCC optimize "O1"
  32. #include "cdot_microk_power10.c"
  33. #else
  34. #ifndef HAVE_KERNEL_8
  35. #include <altivec.h>
  36. #define offset_0 0
  37. #define offset_1 16
  38. #define offset_2 32
  39. #define offset_3 48
  40. static const unsigned char __attribute__((aligned(16))) swap_mask_arr[]={ 4,5,6,7,0,1,2,3, 12,13,14,15, 8,9,10,11};
  41. static void cdot_kernel_8(BLASLONG n, FLOAT *x, FLOAT *y, float *dot)
  42. {
  43. __vector unsigned char swap_mask = *((__vector unsigned char*)swap_mask_arr);
  44. register __vector float *vptr_y = (__vector float *) y;
  45. register __vector float *vptr_x = (__vector float *) x;
  46. register __vector float vd_0 = { 0 };
  47. register __vector float vd_1 = { 0 };
  48. register __vector float vd_2 = { 0 };
  49. register __vector float vd_3 = { 0 };
  50. register __vector float vdd_0 = { 0 };
  51. register __vector float vdd_1 = { 0 };
  52. register __vector float vdd_2 = { 0 };
  53. register __vector float vdd_3 = { 0 };
  54. BLASLONG i=0;
  55. for(;i<n/2;i+=4){
  56. register __vector float vy_0 = vec_vsx_ld( offset_0 ,vptr_y ) ;
  57. register __vector float vy_1 = vec_vsx_ld( offset_1 ,vptr_y ) ;
  58. register __vector float vy_2 = vec_vsx_ld( offset_2 ,vptr_y ) ;
  59. register __vector float vy_3 = vec_vsx_ld( offset_3 ,vptr_y ) ;
  60. register __vector float vx_0 = vec_vsx_ld( offset_0 ,vptr_x ) ;
  61. register __vector float vx_1 = vec_vsx_ld( offset_1 ,vptr_x ) ;
  62. register __vector float vyy_0 = vec_perm(vy_0, vy_0, swap_mask);
  63. register __vector float vyy_1 = vec_perm(vy_1, vy_1, swap_mask);
  64. register __vector float vx_2 = vec_vsx_ld( offset_2 ,vptr_x ) ;
  65. register __vector float vx_3 = vec_vsx_ld( offset_3 ,vptr_x ) ;
  66. register __vector float vyy_2 = vec_perm(vy_2, vy_2, swap_mask);
  67. register __vector float vyy_3 = vec_perm(vy_3, vy_3, swap_mask);
  68. vd_0 += vx_0 * vy_0;
  69. vd_1 += vx_1 * vy_1;
  70. vd_2 += vx_2 * vy_2;
  71. vd_3 += vx_3 * vy_3;
  72. vdd_0 += vx_0 * vyy_0;
  73. vdd_1 += vx_1 * vyy_1;
  74. vdd_2 += vx_2 * vyy_2;
  75. vdd_3 += vx_3 * vyy_3;
  76. vptr_x+=4;
  77. vptr_y+=4;
  78. }
  79. //aggregate
  80. vd_0 = vd_0 + vd_1 +vd_2 +vd_3;
  81. vdd_0= vdd_0 + vdd_1 +vdd_2 +vdd_3;
  82. //reverse and aggregate
  83. vd_1=vec_xxpermdi(vd_0,vd_0,2) ;
  84. vdd_1=vec_xxpermdi(vdd_0,vdd_0,2);
  85. vd_2=vd_0+vd_1;
  86. vdd_2=vdd_0+vdd_1;
  87. dot[0]=vd_2[0];
  88. dot[1]=vd_2[1];
  89. dot[2]=vdd_2[0];
  90. dot[3]=vdd_2[1];
  91. }
  92. #endif
  93. #endif
  94. OPENBLAS_COMPLEX_FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y) {
  95. BLASLONG i = 0;
  96. BLASLONG ix=0, iy=0;
  97. OPENBLAS_COMPLEX_FLOAT result;
  98. FLOAT dot[4] __attribute__((aligned(16))) = {0.0, 0.0, 0.0, 0.0};
  99. if (n <= 0) {
  100. CREAL(result) = 0.0;
  101. CIMAG(result) = 0.0;
  102. return (result);
  103. }
  104. if ((inc_x == 1) && (inc_y == 1)) {
  105. #if defined(POWER10)
  106. BLASLONG n1 = n & -16;
  107. #else
  108. BLASLONG n1 = n & -8;
  109. #endif
  110. BLASLONG j=0;
  111. if (n1){
  112. cdot_kernel_8(n1, x, y, dot);
  113. i = n1;
  114. j = n1 <<1;
  115. }
  116. while (i < n) {
  117. dot[0] += x[j] * y[j];
  118. dot[1] += x[j + 1] * y[j + 1];
  119. dot[2] += x[j] * y[j + 1];
  120. dot[3] += x[j + 1] * y[j];
  121. j += 2;
  122. i++;
  123. }
  124. } else {
  125. i = 0;
  126. ix = 0;
  127. iy = 0;
  128. inc_x <<= 1;
  129. inc_y <<= 1;
  130. while (i < n) {
  131. dot[0] += x[ix] * y[iy];
  132. dot[1] += x[ix + 1] * y[iy + 1];
  133. dot[2] += x[ix] * y[iy + 1];
  134. dot[3] += x[ix + 1] * y[iy];
  135. ix += inc_x;
  136. iy += inc_y;
  137. i++;
  138. }
  139. }
  140. #if !defined(CONJ)
  141. CREAL(result) = dot[0] - dot[1];
  142. CIMAG(result) = dot[2] + dot[3];
  143. #else
  144. CREAL(result) = dot[0] + dot[1];
  145. CIMAG(result) = dot[2] - dot[3];
  146. #endif
  147. return (result);
  148. }
  149. #endif