From db6917303f12a64fe11430a3b46aaabdefd36234 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Mon, 4 Aug 2014 14:29:01 +0200 Subject: [PATCH 1/9] added a better optimized sgemv_n kernel for bulldozer and piledriver --- kernel/x86_64/KERNEL.BULLDOZER | 2 +- kernel/x86_64/KERNEL.PILEDRIVER | 2 +- kernel/x86_64/sgemv_n.c | 203 +++++++++++++++++++++ kernel/x86_64/sgemv_n_microk_bulldozer-2.c | 99 ++++++++++ 4 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 kernel/x86_64/sgemv_n.c create mode 100644 kernel/x86_64/sgemv_n_microk_bulldozer-2.c diff --git a/kernel/x86_64/KERNEL.BULLDOZER b/kernel/x86_64/KERNEL.BULLDOZER index 73a9ad2ec..ca7a0b7c4 100644 --- a/kernel/x86_64/KERNEL.BULLDOZER +++ b/kernel/x86_64/KERNEL.BULLDOZER @@ -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 diff --git a/kernel/x86_64/KERNEL.PILEDRIVER b/kernel/x86_64/KERNEL.PILEDRIVER index 453e7b762..b9d680c43 100644 --- a/kernel/x86_64/KERNEL.PILEDRIVER +++ b/kernel/x86_64/KERNEL.PILEDRIVER @@ -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 diff --git a/kernel/x86_64/sgemv_n.c b/kernel/x86_64/sgemv_n.c new file mode 100644 index 000000000..6f240797d --- /dev/null +++ b/kernel/x86_64/sgemv_n.c @@ -0,0 +1,203 @@ +/*************************************************************************** +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. +*****************************************************************************/ + + +#include "common.h" + + +#if defined(BULLDOZER) || defined(PILEDRIVER) +#include "sgemv_n_microk_bulldozer-2.c" +#endif + + +#define NBMAX 4096 + +#ifndef HAVE_KERNEL_16x4 + +static void sgemv_kernel_16x4(BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y) +{ + int i; + float *a0,*a1,*a2,*a3; + a0 = ap[0]; + a1 = ap[1]; + a2 = ap[2]; + a3 = ap[3]; + + for ( i=0; i< n; i+=4 ) + { + y[i] += a0[i]*x[0] + a1[i]*x[1] + a2[i]*x[2] + a3[i]*x[3]; + y[i+1] += a0[i+1]*x[0] + a1[i+1]*x[1] + a2[i+1]*x[2] + a3[i+1]*x[3]; + y[i+2] += a0[i+2]*x[0] + a1[i+2]*x[1] + a2[i+2]*x[2] + a3[i+2]*x[3]; + y[i+3] += a0[i+3]*x[0] + a1[i+3]*x[1] + a2[i+3]*x[2] + a3[i+3]*x[3]; + } +} + +#endif + +static void sgemv_kernel_16x1(BLASLONG n, FLOAT *ap, FLOAT *x, FLOAT *y) +{ + int i; + float *a0; + a0 = ap; + + for ( i=0; i< n; i+=4 ) + { + y[i] += a0[i]*x[0]; + y[i+1] += a0[i+1]*x[0]; + y[i+2] += a0[i+2]*x[0]; + y[i+3] += a0[i+3]*x[0]; + } +} + + +static void zero_y(BLASLONG n, FLOAT *dest) +{ + BLASLONG i; + for ( i=0; i Date: Mon, 4 Aug 2014 16:22:11 +0200 Subject: [PATCH 2/9] modified sgemv_n for haswell --- kernel/x86_64/KERNEL.HASWELL | 2 +- kernel/x86_64/sgemv_n.c | 2 + kernel/x86_64/sgemv_n_microk_haswell-2.c | 86 ++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 kernel/x86_64/sgemv_n_microk_haswell-2.c diff --git a/kernel/x86_64/KERNEL.HASWELL b/kernel/x86_64/KERNEL.HASWELL index 871a7d490..df4aad92f 100644 --- a/kernel/x86_64/KERNEL.HASWELL +++ b/kernel/x86_64/KERNEL.HASWELL @@ -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 diff --git a/kernel/x86_64/sgemv_n.c b/kernel/x86_64/sgemv_n.c index 6f240797d..d1f4d5f60 100644 --- a/kernel/x86_64/sgemv_n.c +++ b/kernel/x86_64/sgemv_n.c @@ -31,6 +31,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(BULLDOZER) || defined(PILEDRIVER) #include "sgemv_n_microk_bulldozer-2.c" +#elif defined(HASWELL) +#include "sgemv_n_microk_haswell-2.c" #endif diff --git a/kernel/x86_64/sgemv_n_microk_haswell-2.c b/kernel/x86_64/sgemv_n_microk_haswell-2.c new file mode 100644 index 000000000..0bad0ec79 --- /dev/null +++ b/kernel/x86_64/sgemv_n_microk_haswell-2.c @@ -0,0 +1,86 @@ +/*************************************************************************** +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__ + ( + "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" + "vfmadd231ps (%4,%0,4), %%ymm12, %%ymm4 \n\t" + "vfmadd231ps 32(%4,%0,4), %%ymm12, %%ymm5 \n\t" + "prefetcht0 192(%5,%0,4) \n\t" + "vfmadd231ps (%5,%0,4), %%ymm13, %%ymm4 \n\t" + "vfmadd231ps 32(%5,%0,4), %%ymm13, %%ymm5 \n\t" + "prefetcht0 192(%6,%0,4) \n\t" + "vfmadd231ps (%6,%0,4), %%ymm14, %%ymm4 \n\t" + "vfmadd231ps 32(%6,%0,4), %%ymm14, %%ymm5 \n\t" + "prefetcht0 192(%7,%0,4) \n\t" + "vfmadd231ps (%7,%0,4), %%ymm15, %%ymm4 \n\t" + "vfmadd231ps 32(%7,%0,4), %%ymm15, %%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" + + : + : + "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", + "%xmm12", "%xmm13", "%xmm14", "%xmm15", + "memory" + ); + +} + + From 7fa7ea3e1e73a79edc6a9facaa573a5f94193827 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 08:04:47 +0200 Subject: [PATCH 3/9] updated haswell optimized sgmv_n kernel --- kernel/x86_64/sgemv_n_microk_haswell-2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/x86_64/sgemv_n_microk_haswell-2.c b/kernel/x86_64/sgemv_n_microk_haswell-2.c index 0bad0ec79..b19db9e1e 100644 --- a/kernel/x86_64/sgemv_n_microk_haswell-2.c +++ b/kernel/x86_64/sgemv_n_microk_haswell-2.c @@ -35,6 +35,7 @@ static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) __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 @@ -64,6 +65,7 @@ static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) "addq $16, %0 \n\t" "subq $16, %1 \n\t" "jnz .L01LOOP%= \n\t" + "vzeroupper \n\t" : : From a4dde45f879494387f8a6a6015fefc0174b86238 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 08:53:09 +0200 Subject: [PATCH 4/9] optimized sgemv_n kernel for sandybridge --- kernel/x86_64/KERNEL.SANDYBRIDGE | 2 +- kernel/x86_64/sgemv_n.c | 2 + kernel/x86_64/sgemv_n_microk_sandy-2.c | 97 ++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 kernel/x86_64/sgemv_n_microk_sandy-2.c diff --git a/kernel/x86_64/KERNEL.SANDYBRIDGE b/kernel/x86_64/KERNEL.SANDYBRIDGE index 9d7a49562..7869e37a8 100644 --- a/kernel/x86_64/KERNEL.SANDYBRIDGE +++ b/kernel/x86_64/KERNEL.SANDYBRIDGE @@ -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 diff --git a/kernel/x86_64/sgemv_n.c b/kernel/x86_64/sgemv_n.c index d1f4d5f60..2f30fd9de 100644 --- a/kernel/x86_64/sgemv_n.c +++ b/kernel/x86_64/sgemv_n.c @@ -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 index 000000000..dfcb0e17b --- /dev/null +++ b/kernel/x86_64/sgemv_n_microk_sandy-2.c @@ -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" + ); + +} + + From 793f2d43b0a557163f556f744f81fd9031779919 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 10:50:08 +0200 Subject: [PATCH 5/9] added optimized sgemv_n kernel for nehalem --- kernel/x86_64/KERNEL.NEHALEM | 7 ++ kernel/x86_64/sgemv_n.c | 2 + kernel/x86_64/sgemv_n_microk_nehalem-2.c | 144 +++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 kernel/x86_64/sgemv_n_microk_nehalem-2.c diff --git a/kernel/x86_64/KERNEL.NEHALEM b/kernel/x86_64/KERNEL.NEHALEM index 2f9c20583..bb1264316 100644 --- a/kernel/x86_64/KERNEL.NEHALEM +++ b/kernel/x86_64/KERNEL.NEHALEM @@ -1,3 +1,10 @@ +ifdef OS_WINDOWS +SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVTKERNEL = ../arm/gemv_t.c +else +SGEMVNKERNEL = sgemv_n.c +endif + SGEMMKERNEL = gemm_kernel_4x8_nehalem.S SGEMMINCOPY = gemm_ncopy_4.S diff --git a/kernel/x86_64/sgemv_n.c b/kernel/x86_64/sgemv_n.c index 2f30fd9de..4961deffb 100644 --- a/kernel/x86_64/sgemv_n.c +++ b/kernel/x86_64/sgemv_n.c @@ -35,6 +35,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "sgemv_n_microk_haswell-2.c" #elif defined(SANDYBRIDGE) #include "sgemv_n_microk_sandy-2.c" +#elif defined(NEHALEM) +#include "sgemv_n_microk_nehalem-2.c" #endif diff --git a/kernel/x86_64/sgemv_n_microk_nehalem-2.c b/kernel/x86_64/sgemv_n_microk_nehalem-2.c new file mode 100644 index 000000000..8499a01a6 --- /dev/null +++ b/kernel/x86_64/sgemv_n_microk_nehalem-2.c @@ -0,0 +1,144 @@ +/*************************************************************************** +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__ + ( + "movss (%2), %%xmm12 \n\t" // x0 + "movss 4(%2), %%xmm13 \n\t" // x1 + "movss 8(%2), %%xmm14 \n\t" // x2 + "movss 12(%2), %%xmm15 \n\t" // x3 + "shufps $0, %%xmm12, %%xmm12\n\t" + "shufps $0, %%xmm13, %%xmm13\n\t" + "shufps $0, %%xmm14, %%xmm14\n\t" + "shufps $0, %%xmm15, %%xmm15\n\t" + + ".align 16 \n\t" + ".L01LOOP%=: \n\t" + "movups (%3,%0,4), %%xmm4 \n\t" // 4 * y + "movups 16(%3,%0,4), %%xmm5 \n\t" // 4 * y + "movups 32(%3,%0,4), %%xmm6 \n\t" // 4 * y + "movups 48(%3,%0,4), %%xmm7 \n\t" // 4 * y + + "prefetcht0 192(%4,%0,4) \n\t" + + "movups (%4,%0,4), %%xmm8 \n\t" + "movups 16(%4,%0,4), %%xmm9 \n\t" + "movups 32(%4,%0,4), %%xmm10 \n\t" + "movups 48(%4,%0,4), %%xmm11 \n\t" + "mulps %%xmm12, %%xmm8 \n\t" + "addps %%xmm8 , %%xmm4 \n\t" + "mulps %%xmm12, %%xmm9 \n\t" + "addps %%xmm9 , %%xmm5 \n\t" + "mulps %%xmm12, %%xmm10 \n\t" + "addps %%xmm10, %%xmm6 \n\t" + "mulps %%xmm12, %%xmm11 \n\t" + "addps %%xmm11, %%xmm7 \n\t" + + "prefetcht0 192(%5,%0,4) \n\t" + + "movups (%5,%0,4), %%xmm8 \n\t" + "movups 16(%5,%0,4), %%xmm9 \n\t" + "movups 32(%5,%0,4), %%xmm10 \n\t" + "movups 48(%5,%0,4), %%xmm11 \n\t" + "mulps %%xmm13, %%xmm8 \n\t" + "addps %%xmm8 , %%xmm4 \n\t" + "mulps %%xmm13, %%xmm9 \n\t" + "addps %%xmm9 , %%xmm5 \n\t" + "mulps %%xmm13, %%xmm10 \n\t" + "addps %%xmm10, %%xmm6 \n\t" + "mulps %%xmm13, %%xmm11 \n\t" + "addps %%xmm11, %%xmm7 \n\t" + + "prefetcht0 192(%6,%0,4) \n\t" + + "movups (%6,%0,4), %%xmm8 \n\t" + "movups 16(%6,%0,4), %%xmm9 \n\t" + "movups 32(%6,%0,4), %%xmm10 \n\t" + "movups 48(%6,%0,4), %%xmm11 \n\t" + "mulps %%xmm14, %%xmm8 \n\t" + "addps %%xmm8 , %%xmm4 \n\t" + "mulps %%xmm14, %%xmm9 \n\t" + "addps %%xmm9 , %%xmm5 \n\t" + "mulps %%xmm14, %%xmm10 \n\t" + "addps %%xmm10, %%xmm6 \n\t" + "mulps %%xmm14, %%xmm11 \n\t" + "addps %%xmm11, %%xmm7 \n\t" + + "prefetcht0 192(%7,%0,4) \n\t" + + "movups (%7,%0,4), %%xmm8 \n\t" + "movups 16(%7,%0,4), %%xmm9 \n\t" + "movups 32(%7,%0,4), %%xmm10 \n\t" + "movups 48(%7,%0,4), %%xmm11 \n\t" + "mulps %%xmm15, %%xmm8 \n\t" + "addps %%xmm8 , %%xmm4 \n\t" + "mulps %%xmm15, %%xmm9 \n\t" + "addps %%xmm9 , %%xmm5 \n\t" + "mulps %%xmm15, %%xmm10 \n\t" + "addps %%xmm10, %%xmm6 \n\t" + "mulps %%xmm15, %%xmm11 \n\t" + "addps %%xmm11, %%xmm7 \n\t" + + + "movups %%xmm4, (%3,%0,4) \n\t" // 4 * y + "movups %%xmm5, 16(%3,%0,4) \n\t" // 4 * y + "movups %%xmm6, 32(%3,%0,4) \n\t" // 4 * y + "movups %%xmm7, 48(%3,%0,4) \n\t" // 4 * y + + "addq $16, %0 \n\t" + "subq $16, %1 \n\t" + "jnz .L01LOOP%= \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", + "%xmm6", "%xmm7", + "%xmm8", "%xmm9", "%xmm10", "%xmm11", + "%xmm12", "%xmm13", "%xmm14", "%xmm15", + "memory" + ); + +} + + From 9175b8bd5f8df59146b8539f9760d7ed42611648 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 13:28:39 +0200 Subject: [PATCH 6/9] changed long to blaslong for windows compatibility --- kernel/x86_64/sgemv_n_microk_bulldozer-2.c | 6 +++--- kernel/x86_64/sgemv_n_microk_haswell-2.c | 6 +++--- kernel/x86_64/sgemv_n_microk_nehalem-2.c | 6 +++--- kernel/x86_64/sgemv_n_microk_sandy-2.c | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/kernel/x86_64/sgemv_n_microk_bulldozer-2.c b/kernel/x86_64/sgemv_n_microk_bulldozer-2.c index 7e9ee5cc9..d50fa4268 100644 --- a/kernel/x86_64/sgemv_n_microk_bulldozer-2.c +++ b/kernel/x86_64/sgemv_n_microk_bulldozer-2.c @@ -26,12 +26,12 @@ 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( BLASLONG n, float **ap, float *x, float *y) __attribute__ ((noinline)); -static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) +static void sgemv_kernel_16x4( BLASLONG n, float **ap, float *x, float *y) { - long register i = 0; + BLASLONG register i = 0; __asm__ __volatile__ ( diff --git a/kernel/x86_64/sgemv_n_microk_haswell-2.c b/kernel/x86_64/sgemv_n_microk_haswell-2.c index b19db9e1e..d3fee67c3 100644 --- a/kernel/x86_64/sgemv_n_microk_haswell-2.c +++ b/kernel/x86_64/sgemv_n_microk_haswell-2.c @@ -26,12 +26,12 @@ 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( BLASLONG n, float **ap, float *x, float *y) __attribute__ ((noinline)); -static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) +static void sgemv_kernel_16x4( BLASLONG n, float **ap, float *x, float *y) { - long register i = 0; + BLASLONG register i = 0; __asm__ __volatile__ ( diff --git a/kernel/x86_64/sgemv_n_microk_nehalem-2.c b/kernel/x86_64/sgemv_n_microk_nehalem-2.c index 8499a01a6..3cfb82a45 100644 --- a/kernel/x86_64/sgemv_n_microk_nehalem-2.c +++ b/kernel/x86_64/sgemv_n_microk_nehalem-2.c @@ -26,12 +26,12 @@ 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( BLASLONG n, float **ap, float *x, float *y) __attribute__ ((noinline)); -static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) +static void sgemv_kernel_16x4( BLASLONG n, float **ap, float *x, float *y) { - long register i = 0; + BLASLONG register i = 0; __asm__ __volatile__ ( diff --git a/kernel/x86_64/sgemv_n_microk_sandy-2.c b/kernel/x86_64/sgemv_n_microk_sandy-2.c index dfcb0e17b..21eff1c5e 100644 --- a/kernel/x86_64/sgemv_n_microk_sandy-2.c +++ b/kernel/x86_64/sgemv_n_microk_sandy-2.c @@ -26,12 +26,12 @@ 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( BLASLONG n, float **ap, float *x, float *y) __attribute__ ((noinline)); -static void sgemv_kernel_16x4( long n, float **ap, float *x, float *y) +static void sgemv_kernel_16x4( BLASLONG n, float **ap, float *x, float *y) { - long register i = 0; + BLASLONG register i = 0; __asm__ __volatile__ ( From 2bab92961f5031f8881d5d6635e470b6e7c0a416 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 14:52:54 +0200 Subject: [PATCH 7/9] enabled optimized sgemv_n kernels for windows --- kernel/x86_64/KERNEL.BULLDOZER | 2 +- kernel/x86_64/KERNEL.HASWELL | 2 +- kernel/x86_64/KERNEL.NEHALEM | 3 ++- kernel/x86_64/KERNEL.PILEDRIVER | 2 +- kernel/x86_64/KERNEL.SANDYBRIDGE | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/x86_64/KERNEL.BULLDOZER b/kernel/x86_64/KERNEL.BULLDOZER index ca7a0b7c4..21fc94701 100644 --- a/kernel/x86_64/KERNEL.BULLDOZER +++ b/kernel/x86_64/KERNEL.BULLDOZER @@ -1,5 +1,5 @@ ifdef OS_WINDOWS -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c SGEMVTKERNEL = ../arm/gemv_t.c else SGEMVNKERNEL = sgemv_n.c diff --git a/kernel/x86_64/KERNEL.HASWELL b/kernel/x86_64/KERNEL.HASWELL index df4aad92f..3e20fcfc7 100644 --- a/kernel/x86_64/KERNEL.HASWELL +++ b/kernel/x86_64/KERNEL.HASWELL @@ -1,5 +1,5 @@ ifdef OS_WINDOWS -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c SGEMVTKERNEL = ../arm/gemv_t.c else SGEMVNKERNEL = sgemv_n.c diff --git a/kernel/x86_64/KERNEL.NEHALEM b/kernel/x86_64/KERNEL.NEHALEM index bb1264316..04efa391a 100644 --- a/kernel/x86_64/KERNEL.NEHALEM +++ b/kernel/x86_64/KERNEL.NEHALEM @@ -1,8 +1,9 @@ ifdef OS_WINDOWS -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c SGEMVTKERNEL = ../arm/gemv_t.c else SGEMVNKERNEL = sgemv_n.c +SGEMVTKERNEL = ../arm/gemv_t.c endif diff --git a/kernel/x86_64/KERNEL.PILEDRIVER b/kernel/x86_64/KERNEL.PILEDRIVER index b9d680c43..b7565edeb 100644 --- a/kernel/x86_64/KERNEL.PILEDRIVER +++ b/kernel/x86_64/KERNEL.PILEDRIVER @@ -1,5 +1,5 @@ ifdef OS_WINDOWS -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c SGEMVTKERNEL = ../arm/gemv_t.c else SGEMVNKERNEL = sgemv_n.c diff --git a/kernel/x86_64/KERNEL.SANDYBRIDGE b/kernel/x86_64/KERNEL.SANDYBRIDGE index 7869e37a8..9dae3a41d 100644 --- a/kernel/x86_64/KERNEL.SANDYBRIDGE +++ b/kernel/x86_64/KERNEL.SANDYBRIDGE @@ -1,5 +1,5 @@ ifdef OS_WINDOWS -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c SGEMVTKERNEL = ../arm/gemv_t.c else SGEMVNKERNEL = sgemv_n.c From c80084a98f2882a7bb959bad26cc66ebd65bef63 Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 19:42:56 +0200 Subject: [PATCH 8/9] changed default x86_64 sgemv_n kernel to sgemv_n.c --- kernel/x86_64/KERNEL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/x86_64/KERNEL b/kernel/x86_64/KERNEL index ec21826d7..9d0080ae7 100644 --- a/kernel/x86_64/KERNEL +++ b/kernel/x86_64/KERNEL @@ -373,7 +373,7 @@ endif GEMVDEP = ../l2param.h ifndef SGEMVNKERNEL -SGEMVNKERNEL = ../arm/gemv_n.c +SGEMVNKERNEL = sgemv_n.c endif ifndef SGEMVTKERNEL From 8c05b8105b1dad9b9f1ae16d7e0774ce153b6bdd Mon Sep 17 00:00:00 2001 From: wernsaar Date: Tue, 5 Aug 2014 20:14:29 +0200 Subject: [PATCH 9/9] bugfix in sgemv_n.c --- kernel/x86_64/sgemv_n.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/x86_64/sgemv_n.c b/kernel/x86_64/sgemv_n.c index 4961deffb..f2de1b76a 100644 --- a/kernel/x86_64/sgemv_n.c +++ b/kernel/x86_64/sgemv_n.c @@ -46,8 +46,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static void sgemv_kernel_16x4(BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y) { - int i; - float *a0,*a1,*a2,*a3; + BLASLONG i; + FLOAT *a0,*a1,*a2,*a3; a0 = ap[0]; a1 = ap[1]; a2 = ap[2]; @@ -66,8 +66,8 @@ static void sgemv_kernel_16x4(BLASLONG n, FLOAT **ap, FLOAT *x, FLOAT *y) static void sgemv_kernel_16x1(BLASLONG n, FLOAT *ap, FLOAT *x, FLOAT *y) { - int i; - float *a0; + BLASLONG i; + FLOAT *a0; a0 = ap; for ( i=0; i< n; i+=4 ) @@ -130,11 +130,11 @@ int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLO BLASLONG m2; BLASLONG n2; FLOAT xbuffer[4],*ybuffer; + ybuffer = buffer; n1 = n / 4 ; n2 = n % 4 ; - m1 = m - ( m % 16 ); m2 = (m % NBMAX) - (m % 16) ;