📄 zgemm_kernel_4x1_sse.s
字号:
/*********************************************************************//* *//* Optimized BLAS libraries *//* By Kazushige Goto <kgoto@tacc.utexas.edu> *//* *//* Copyright (c) The University of Texas, 2005. All rights reserved. *//* UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING *//* THIS SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF *//* MERCHANTABILITY, FITNESS FOR ANY PARTICULAR PURPOSE, *//* NON-INFRINGEMENT AND WARRANTIES OF PERFORMANCE, AND ANY WARRANTY *//* THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF *//* TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO *//* THE USE OF THE SOFTWARE OR DOCUMENTATION. *//* Under no circumstances shall University be liable for incidental, *//* special, indirect, direct or consequential damages or loss of *//* profits, interruption of business, or related expenses which may *//* arise from use of Software or Documentation, including but not *//* limited to those resulting from defects in Software and/or *//* Documentation, or loss or inaccuracy of data of any kind. *//*********************************************************************/#define ASSEMBLER#include "common.h"#if !defined(HAVE_SSE) || !defined(HAVE_MMX)#error You have to check your configuration.#endif#define STACK 16#define ARGS 0 #define STACK_M 4 + STACK + ARGS(%esi)#define STACK_N 8 + STACK + ARGS(%esi)#define STACK_K 12 + STACK + ARGS(%esi)#define STACK_ALPHA_R 16 + STACK + ARGS(%esi)#define STACK_ALPHA_I 20 + STACK + ARGS(%esi)#define STACK_A 24 + STACK + ARGS(%esi)#define STACK_B 28 + STACK + ARGS(%esi)#define STACK_C 32 + STACK + ARGS(%esi)#define STACK_LDC 36 + STACK + ARGS(%esi)#define STACK_OFFT 40 + STACK + ARGS(%esi)#define POSINV 0(%esp)#define ALPHA_R 16(%esp)#define ALPHA_I 32(%esp)#define K 48(%esp)#define N 52(%esp)#define M 56(%esp)#define A 60(%esp)#define C 64(%esp)#define J 68(%esp)#define OLD_STACK 72(%esp)#define TEMP 76(%esp)#define OFFSET 80(%esp)#define KK 84(%esp)#define KKK 88(%esp)#define BUFFER 128(%esp)#define B %edi#define LDC %ebp#define STACK_ALIGN 4096#define STACK_OFFSET 1024#define LOCAL_BUFFER_SIZE GEMM_Q * GEMM_UNROLL_N * COMPSIZE * 16#define AA %edx#define BB %ecx#ifdef HAVE_SSE2#define XORPS pxor#define MOVSD movsd#else#define XORPS xorps#define MOVSD movlps#endif#define KERNEL1(address) \ mulps %xmm0, %xmm2; \ mulps 4 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm4; \ movaps 0 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm5; \ movaps 4 * SIZE + (address) * SIZE * 2(AA), %xmm0; \ mulps %xmm0, %xmm2; \ mulps 4 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm6; \ movaps 8 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm7; \ movaps 8 * SIZE + (address) * SIZE * 2(AA), %xmm0#define KERNEL2(address) \ mulps %xmm0, %xmm2; \ mulps 12 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm4; \ movaps 8 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm5; \ movaps 12 * SIZE + (address) * SIZE * 2(AA), %xmm0; \ mulps %xmm0, %xmm2; \ mulps 12 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm6; \ movaps 32 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm7; \ movaps 32 * SIZE + (address) * SIZE * 2(AA), %xmm0#define KERNEL3(address) \ mulps %xmm1, %xmm3; \ mulps 20 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm4; \ movaps 16 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm5; \ movaps 20 * SIZE + (address) * SIZE * 2(AA), %xmm1; \ mulps %xmm1, %xmm3; \ mulps 20 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm6; \ movaps 24 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm7; \ movaps 24 * SIZE + (address) * SIZE * 2(AA), %xmm1#define KERNEL4(address) \ mulps %xmm1, %xmm3; \ mulps 28 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm4; \ movaps 24 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm5; \ movaps 28 * SIZE + (address) * SIZE * 2(AA), %xmm1; \ mulps %xmm1, %xmm3; \ mulps 28 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm6; \ movaps 48 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm7; \ movaps 48 * SIZE + (address) * SIZE * 2(AA), %xmm1#define KERNEL5(address) \ mulps %xmm0, %xmm2; \ mulps 36 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm4; \ movaps 32 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm5; \ movaps 36 * SIZE + (address) * SIZE * 2(AA), %xmm0; \ mulps %xmm0, %xmm2; \ mulps 36 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm6; \ movaps 40 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm7; \ movaps 40 * SIZE + (address) * SIZE * 2(AA), %xmm0#define KERNEL6(address) \ mulps %xmm0, %xmm2; \ mulps 44 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm4; \ movaps 40 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm5; \ movaps 44 * SIZE + (address) * SIZE * 2(AA), %xmm0; \ mulps %xmm0, %xmm2; \ mulps 44 * SIZE + (address) * SIZE * 2(BB), %xmm0; \ addps %xmm2, %xmm6; \ movaps 64 * SIZE + (address) * SIZE * 2(BB), %xmm2; \ addps %xmm0, %xmm7; \ movaps 64 * SIZE + (address) * SIZE * 2(AA), %xmm0#define KERNEL7(address) \ mulps %xmm1, %xmm3; \ mulps 52 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm4; \ movaps 48 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm5; \ movaps 52 * SIZE + (address) * SIZE * 2(AA), %xmm1; \ mulps %xmm1, %xmm3; \ mulps 52 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm6; \ movaps 56 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm7; \ movaps 56 * SIZE + (address) * SIZE * 2(AA), %xmm1#define KERNEL8(address) \ mulps %xmm1, %xmm3; \ mulps 60 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm4; \ movaps 56 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm5; \ movaps 60 * SIZE + (address) * SIZE * 2(AA), %xmm1; \ mulps %xmm1, %xmm3; \ mulps 60 * SIZE + (address) * SIZE * 2(BB), %xmm1; \ addps %xmm3, %xmm6; \ movaps 80 * SIZE + (address) * SIZE * 2(BB), %xmm3; \ addps %xmm1, %xmm7; \ movaps 80 * SIZE + (address) * SIZE * 2(AA), %xmm1 PROLOGUE pushl %ebp pushl %edi pushl %esi pushl %ebx PROFCODE EMMS movl %esp, %esi # save old stack subl $128 + LOCAL_BUFFER_SIZE + STACK_OFFSET, %esp andl $-STACK_ALIGN, %esp # align stack addl $STACK_OFFSET, %esp#ifdef WINDOWS_ABI#if LOCAL_BUFFER_SIZE > 12288 movl $0, 4096 * 3(%esp)#endif#if LOCAL_BUFFER_SIZE > 8192 movl $0, 4096 * 2(%esp)#endif#if LOCAL_BUFFER_SIZE > 4096 movl $0, 4096 * 1(%esp)#endif movl $0, 4096 * 0(%esp)#endif movd STACK_M, %mm0 movl STACK_N, %eax movd STACK_K, %mm1 movd STACK_A, %mm2 movl STACK_B, B movd STACK_C, %mm3 movl STACK_LDC, LDC#ifdef TRMMKERNEL movd STACK_OFFT, %mm4#endif movd %mm1, K movd %mm0, M movl %eax, N movd %mm2, A movd %mm3, C movl %esi, OLD_STACK#ifdef TRMMKERNEL movd %mm4, OFFSET movd %mm4, KK#ifndef LEFT negl KK#endif #endif leal (, LDC, SIZE * 2), LDC movss STACK_ALPHA_R, %xmm0 movss STACK_ALPHA_I, %xmm1#ifdef HAVE_SSE2 pxor %xmm7, %xmm7 cmpeqps %xmm7, %xmm7 pslld $31, %xmm7 # Generate mask#else movl $0x80000000, TEMP movss TEMP, %xmm7 shufps $0, %xmm7, %xmm7#endif XORPS %xmm2, %xmm2 shufps $0, %xmm0, %xmm0 movaps %xmm0, 0 + ALPHA_R movss %xmm1, 4 + ALPHA_I movss %xmm1, 12 + ALPHA_I XORPS %xmm7, %xmm1 movss %xmm1, 0 + ALPHA_I movss %xmm1, 8 + ALPHA_I#if defined(NN) || defined(NT) || defined(NR) || defined(NC) || \ defined(TN) || defined(TT) || defined(TR) || defined(TC) movss %xmm7, 0 + POSINV movss %xmm2, 4 + POSINV movss %xmm7, 8 + POSINV movss %xmm2, 12 + POSINV#else movss %xmm2, 0 + POSINV movss %xmm7, 4 + POSINV movss %xmm2, 8 + POSINV movss %xmm7, 12 + POSINV#endif movl %eax, J # j = n testl %eax, %eax jle .L999.L01:#if defined(TRMMKERNEL) && defined(LEFT) movl OFFSET, %eax movl %eax, KK#endif leal BUFFER, BB movaps POSINV, %xmm7 movl K, %eax sarl $2, %eax jle .L03.L02: movss 0 * SIZE(B), %xmm0 movss 1 * SIZE(B), %xmm1 movss 2 * SIZE(B), %xmm2 movss 3 * SIZE(B), %xmm3 shufps $0, %xmm0, %xmm0 shufps $0, %xmm1, %xmm1 shufps $0, %xmm2, %xmm2 shufps $0, %xmm3, %xmm3#if defined(NN) || defined(NT) || defined(NR) || defined(NC) || \ defined(TN) || defined(TT) || defined(TR) || defined(TC) XORPS %xmm7, %xmm1 XORPS %xmm7, %xmm3#else XORPS %xmm7, %xmm0 XORPS %xmm7, %xmm2#endif movaps %xmm0, 0 * SIZE(BB) movaps %xmm1, 4 * SIZE(BB) movaps %xmm2, 8 * SIZE(BB) movaps %xmm3, 12 * SIZE(BB) movss 4 * SIZE(B), %xmm0 movss 5 * SIZE(B), %xmm1 movss 6 * SIZE(B), %xmm2 movss 7 * SIZE(B), %xmm3 shufps $0, %xmm0, %xmm0 shufps $0, %xmm1, %xmm1 shufps $0, %xmm2, %xmm2 shufps $0, %xmm3, %xmm3#if defined(NN) || defined(NT) || defined(NR) || defined(NC) || \ defined(TN) || defined(TT) || defined(TR) || defined(TC) XORPS %xmm7, %xmm1 XORPS %xmm7, %xmm3#else XORPS %xmm7, %xmm0 XORPS %xmm7, %xmm2#endif movaps %xmm0, 16 * SIZE(BB) movaps %xmm1, 20 * SIZE(BB) movaps %xmm2, 24 * SIZE(BB) movaps %xmm3, 28 * SIZE(BB) prefetcht0 104 * SIZE(B) addl $ 8 * SIZE, B addl $32 * SIZE, BB decl %eax jne .L02.L03: movl K, %eax andl $3, %eax BRANCH jle .L05.L04: movss 0 * SIZE(B), %xmm0 movss 1 * SIZE(B), %xmm1 shufps $0, %xmm0, %xmm0 shufps $0, %xmm1, %xmm1#if defined(NN) || defined(NT) || defined(NR) || defined(NC) || \ defined(TN) || defined(TT) || defined(TR) || defined(TC) XORPS %xmm7, %xmm1#else XORPS %xmm7, %xmm0#endif movaps %xmm0, 0 * SIZE(BB) movaps %xmm1, 4 * SIZE(BB) addl $2 * SIZE, B addl $8 * SIZE, BB decl %eax jne .L04 ALIGN_4.L05: movl C, %esi # coffset = c movl A, AA # aoffset = a movl M, %ebx sarl $2, %ebx # i = (m >> 2) jle .L50 ALIGN_4.L10:#ifdef PENTIUM4#if !defined(TRMMKERNEL) || \ (defined(TRMMKERNEL) && defined(LEFT) && defined(TRANSA)) || \ (defined(TRMMKERNEL) && !defined(LEFT) && !defined(TRANSA)) leal BUFFER, BB movaps 0 * SIZE + BUFFER, %xmm2 XORPS %xmm4, %xmm4 movaps 0 * SIZE(AA), %xmm0 XORPS %xmm5, %xmm5 movaps 16 * SIZE + BUFFER, %xmm3 XORPS %xmm6, %xmm6 movaps 16 * SIZE(AA), %xmm1 XORPS %xmm7, %xmm7#else leal BUFFER, BB movl KK, %eax leal (, %eax, 8), %eax leal (AA, %eax, 4), AA leal (BB, %eax, 4), BB /* because it's doubled */ movaps 0 * SIZE(BB), %xmm2 XORPS %xmm4, %xmm4 movaps 0 * SIZE(AA), %xmm0 XORPS %xmm5, %xmm5 movaps 16 * SIZE(BB), %xmm3 XORPS %xmm6, %xmm6 movaps 16 * SIZE(AA), %xmm1 XORPS %xmm7, %xmm7#endif prefetchnta 8 * SIZE(%esi)#ifndef TRMMKERNEL movl K, %eax#elif (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA)) movl K, %eax subl KK, %eax movl %eax, KKK #else movl KK, %eax#ifdef LEFT addl $4, %eax#else addl $1, %eax#endif movl %eax, KKK#endif andl $-8, %eax je .L12 sall $3, %eax .L1X: KERNEL1(32 * 0) KERNEL2(32 * 0) KERNEL3(32 * 0) KERNEL4(32 * 0) KERNEL5(32 * 0) KERNEL6(32 * 0) KERNEL7(32 * 0) KERNEL8(32 * 0) cmpl $64 * 1, %eax jle,pn .L11 KERNEL1(32 * 1) KERNEL2(32 * 1) KERNEL3(32 * 1) KERNEL4(32 * 1) KERNEL5(32 * 1) KERNEL6(32 * 1) KERNEL7(32 * 1) KERNEL8(32 * 1) cmpl $64 * 2, %eax jle,pn .L11 KERNEL1(32 * 2) KERNEL2(32 * 2) KERNEL3(32 * 2) KERNEL4(32 * 2) KERNEL5(32 * 2) KERNEL6(32 * 2) KERNEL7(32 * 2) KERNEL8(32 * 2) cmpl $64 * 3, %eax jle,pn .L11 KERNEL1(32 * 3) KERNEL2(32 * 3) KERNEL3(32 * 3) KERNEL4(32 * 3) KERNEL5(32 * 3) KERNEL6(32 * 3) KERNEL7(32 * 3) KERNEL8(32 * 3) cmpl $64 * 4, %eax jle,pn .L11 KERNEL1(32 * 4) KERNEL2(32 * 4)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -