optimized sgemv_n kernel for sandybridge
authorwernsaar <wernsaar@googlemail.com>
Tue, 5 Aug 2014 06:53:09 +0000 (08:53 +0200)
committerwernsaar <wernsaar@googlemail.com>
Tue, 5 Aug 2014 06:53:09 +0000 (08:53 +0200)
kernel/x86_64/KERNEL.SANDYBRIDGE
kernel/x86_64/sgemv_n.c
kernel/x86_64/sgemv_n_microk_sandy-2.c [new file with mode: 0644]

index 9d7a495..7869e37 100644 (file)
@@ -2,7 +2,7 @@ ifdef OS_WINDOWS
 SGEMVNKERNEL = ../arm/gemv_n.c
 SGEMVTKERNEL = ../arm/gemv_t.c
 else
-SGEMVNKERNEL = sgemv_n_avx.c
+SGEMVNKERNEL = sgemv_n.c
 SGEMVTKERNEL = sgemv_t_avx.c
 endif
 
index d1f4d5f..2f30fd9 100644 (file)
@@ -33,6 +33,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "sgemv_n_microk_bulldozer-2.c"
 #elif defined(HASWELL)
 #include "sgemv_n_microk_haswell-2.c"
+#elif defined(SANDYBRIDGE)
+#include "sgemv_n_microk_sandy-2.c"
 #endif
 
 
diff --git a/kernel/x86_64/sgemv_n_microk_sandy-2.c b/kernel/x86_64/sgemv_n_microk_sandy-2.c
new file mode 100644 (file)
index 0000000..dfcb0e1
--- /dev/null
@@ -0,0 +1,97 @@
+/***************************************************************************
+Copyright (c) 2014, The OpenBLAS Project
+All rights reserved.
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+1. Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the
+distribution.
+3. Neither the name of the OpenBLAS project nor the names of
+its contributors may be used to endorse or promote products
+derived from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*****************************************************************************/
+
+#define HAVE_KERNEL_16x4 1
+static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) __attribute__ ((noinline));
+
+static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y)
+{
+
+       long register i = 0;
+
+       __asm__  __volatile__
+       (
+       "vzeroupper                      \n\t"
+       "vbroadcastss    (%2), %%ymm12   \n\t"  // x0 
+       "vbroadcastss   4(%2), %%ymm13   \n\t"  // x1 
+       "vbroadcastss   8(%2), %%ymm14   \n\t"  // x2 
+       "vbroadcastss  12(%2), %%ymm15   \n\t"  // x3 
+
+       ".align 16                               \n\t"
+       ".L01LOOP%=:                             \n\t"
+       "vmovups        (%3,%0,4), %%ymm4        \n\t"  // 8 * y
+       "vmovups      32(%3,%0,4), %%ymm5        \n\t"  // 8 * y
+
+       "prefetcht0      192(%4,%0,4)                  \n\t"
+       "vmulps   (%4,%0,4), %%ymm12, %%ymm8      \n\t" 
+       "vaddps   %%ymm4, %%ymm8 , %%ymm4         \n\t"
+       "vmulps 32(%4,%0,4), %%ymm12, %%ymm9      \n\t" 
+       "vaddps   %%ymm5, %%ymm9 , %%ymm5         \n\t"
+       "prefetcht0      192(%5,%0,4)                  \n\t"
+       "vmulps   (%5,%0,4), %%ymm13, %%ymm10     \n\t" 
+       "vaddps   %%ymm4, %%ymm10, %%ymm4         \n\t"
+       "vmulps 32(%5,%0,4), %%ymm13, %%ymm11     \n\t" 
+       "vaddps   %%ymm5, %%ymm11, %%ymm5         \n\t"
+       "prefetcht0      192(%6,%0,4)                  \n\t"
+       "vmulps   (%6,%0,4), %%ymm14, %%ymm8      \n\t" 
+       "vaddps   %%ymm4, %%ymm8 , %%ymm4         \n\t"
+       "vmulps 32(%6,%0,4), %%ymm14, %%ymm9      \n\t" 
+       "vaddps   %%ymm5, %%ymm9 , %%ymm5         \n\t"
+       "prefetcht0      192(%7,%0,4)                  \n\t"
+       "vmulps   (%7,%0,4), %%ymm15, %%ymm10     \n\t" 
+       "vaddps   %%ymm4, %%ymm10, %%ymm4         \n\t"
+       "vmulps 32(%7,%0,4), %%ymm15, %%ymm11     \n\t" 
+       "vaddps   %%ymm5, %%ymm11, %%ymm5         \n\t"
+
+       "vmovups  %%ymm4,   (%3,%0,4)                 \n\t"     // 8 * y
+       "vmovups  %%ymm5, 32(%3,%0,4)                 \n\t"     // 8 * y
+
+        "addq          $16, %0                       \n\t"
+       "subq           $16, %1                       \n\t"             
+       "jnz            .L01LOOP%=                    \n\t"
+       "vzeroupper                      \n\t"
+
+       :
+        : 
+          "r" (i),     // 0    
+         "r" (n),      // 1
+          "r" (x),      // 2
+          "r" (y),      // 3
+          "r" (ap[0]),  // 4
+          "r" (ap[1]),  // 5
+          "r" (ap[2]),  // 6
+          "r" (ap[3])   // 7
+       : "cc", 
+         "%xmm4", "%xmm5", 
+         "%xmm8", "%xmm9", "%xmm10", "%xmm11",
+         "%xmm12", "%xmm13", "%xmm14", "%xmm15",
+         "memory"
+       );
+
+} 
+
+