forked from OpenMathLib/OpenBLAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
374 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,3 +493,4 @@ CSUMKERNEL = zsum_sse.S | |
ZSUMKERNEL = zsum_sse2.S | ||
|
||
SOMATCOPY_RT = omatcopy_rt.c | ||
SOMATCOPY_RN = omatcopy_rn.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,373 @@ | ||
/*************************************************************************** | ||
Copyright (c) 2024, 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" | ||
|
||
#ifdef HAVE_AVX | ||
|
||
#define ROWS_OF_BLOCK 384 | ||
|
||
/* +r: %0 = src, %1 = dst, %2 = src_ld, %3 = dst_ld, %4 = dst_tmp */ | ||
/* m: %5 = num_rows, %6 = alpha */ | ||
/* xmm15 = alpha */ | ||
|
||
#define SAVE_4x4(b1_no,b2_no,b3_no,b4_no)\ | ||
"vmovups %%xmm"#b1_no",(%1); vmovups %%xmm"#b2_no",(%1,%3,1); leaq (%1,%3,2),%1;"\ | ||
"vmovups %%xmm"#b3_no",(%1); vmovups %%xmm"#b4_no",(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define SAVE_4x8(b1_no,b2_no,b3_no,b4_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); vmovups %%ymm"#b2_no",(%1,%3,1); leaq (%1,%3,2),%1;"\ | ||
"vmovups %%ymm"#b3_no",(%1); vmovups %%ymm"#b4_no",(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define SAVE_4x16(b1_no,b2_no,b3_no,b4_no,b5_no,b6_no,b7_no,b8_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); vmovups %%ymm"#b2_no",32(%1); leaq (%1,%3,1),%1;"\ | ||
"vmovups %%ymm"#b3_no",(%1); vmovups %%ymm"#b4_no",32(%1); leaq (%1,%3,1),%1;"\ | ||
"vmovups %%ymm"#b5_no",(%1); vmovups %%ymm"#b6_no",32(%1); leaq (%1,%3,1),%1;"\ | ||
"vmovups %%ymm"#b7_no",(%1); vmovups %%ymm"#b8_no",32(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define COPY_4x16 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; vmulps 32(%0),%%ymm15,%%ymm1; vmulps (%0,%2,1),%%ymm15,%%ymm2; vmulps 32(%0,%2,1),%%ymm15,%%ymm3; leaq (%0,%2,2),%0;"\ | ||
"vmulps (%0),%%ymm15,%%ymm4; vmulps 32(%0),%%ymm15,%%ymm5; vmulps (%0,%2,1),%%ymm15,%%ymm6; vmulps 32(%0,%2,1),%%ymm15,%%ymm7; leaq (%0,%2,2),%0;"\ | ||
SAVE_4x16(0,1,2,3,4,5,6,7) | ||
|
||
#define COPY_4x8 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; vmulps (%0,%2,1),%%ymm15,%%ymm1; leaq (%0,%2,2),%0;"\ | ||
"vmulps (%0),%%ymm15,%%ymm2; vmulps (%0,%2,1),%%ymm15,%%ymm3; leaq (%0,%2,2),%0;"\ | ||
SAVE_4x8(0,1,2,3) | ||
|
||
#define COPY_4x4 \ | ||
"vmulps (%0),%%xmm15,%%xmm0; vmulps (%0,%2,1),%%xmm15,%%xmm1; leaq (%0,%2,2),%0;"\ | ||
"vmulps (%0),%%xmm15,%%xmm2; vmulps (%0,%2,1),%%xmm15,%%xmm3; leaq (%0,%2,2),%0;"\ | ||
SAVE_4x4(0,1,2,3) | ||
|
||
#define COPY_4x2 \ | ||
"vmovsd (%0),%%xmm0; vmovhpd (%0,%2,1),%%xmm0,%%xmm0; vmulps %%xmm15,%%xmm0,%%xmm0; leaq (%0,%2,2),%0;"\ | ||
"vmovsd (%0),%%xmm1; vmovhpd (%0,%2,1),%%xmm1,%%xmm1; vmulps %%xmm15,%%xmm1,%%xmm1; leaq (%0,%2,2),%0;"\ | ||
"vmovsd %%xmm0,(%1); vmovhpd %%xmm0,(%1,%3,1); leaq (%1,%3,2),%1;"\ | ||
"vmovsd %%xmm1,(%1); vmovhpd %%xmm1,(%1,%3,1); leaq (%1,%3,2),%1;"\ | ||
|
||
#define COPY_4x1 \ | ||
"vmovss (%0),%%xmm0; vinsertps $16,(%0,%2,1),%%xmm0,%%xmm0; leaq (%0,%2,2),%0;"\ | ||
"vinsertps $32,(%0),%%xmm0,%%xmm0; vinsertps $48,(%0,%2,1),%%xmm0,%%xmm0; leaq (%0,%2,2),%0;"\ | ||
"vmulps %%xmm15,%%xmm0,%%xmm0; vmovss %%xmm0,(%1); vextractps $1,%%xmm0,(%1,%3,1); leaq (%1,%3,2),%1;"\ | ||
"vextractps $2,%%xmm0,(%1);vextractps $3,%%xmm0,(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define SAVE_2x16(b1_no,b2_no,b3_no,b4_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); vmovups %%ymm"#b2_no",32(%1); leaq (%1,%3,1),%1;"\ | ||
"vmovups %%ymm"#b3_no",(%1); vmovups %%ymm"#b4_no",32(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define SAVE_2x8(b1_no,b2_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); vmovups %%ymm"#b2_no",(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define SAVE_2x4(b1_no,b2_no)\ | ||
"vmovups %%xmm"#b1_no",(%1); vmovups %%xmm"#b2_no",(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define COPY_2x16 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; vmulps 32(%0),%%ymm15,%%ymm1; vmulps (%0,%2,1),%%ymm15,%%ymm2; vmulps 32(%0,%2,1),%%ymm15,%%ymm3; leaq (%0,%2,2),%0;"\ | ||
SAVE_2x16(0,1,2,3) | ||
|
||
#define COPY_2x8 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; vmulps (%0,%2,1),%%ymm15,%%ymm1; leaq (%0,%2,2),%0;"\ | ||
SAVE_2x8(0,1) | ||
|
||
#define COPY_2x4 \ | ||
"vmulps (%0),%%xmm15,%%xmm0; vmulps (%0,%2,1),%%xmm15,%%xmm1; leaq (%0,%2,2),%0;"\ | ||
SAVE_2x4(0,1) | ||
|
||
#define COPY_2x2 \ | ||
"vmovsd (%0),%%xmm0; vmovhpd (%0,%2,1),%%xmm0,%%xmm0; vmulps %%xmm15,%%xmm0,%%xmm0; leaq (%0,%2,2),%0;"\ | ||
"vmovsd %%xmm0,(%1); vmovhpd %%xmm0,(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define COPY_2x1 \ | ||
"vmovss (%0),%%xmm0; vinsertps $16,(%0,%2,1),%%xmm0,%%xmm0; leaq (%0,%2,2),%0;"\ | ||
"vmulps %%xmm15,%%xmm0,%%xmm0; vmovss %%xmm0,(%1); vextractps $1,%%xmm0,(%1,%3,1); leaq (%1,%3,2),%1;" | ||
|
||
#define SAVE_1x16(b1_no,b2_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); vmovups %%ymm"#b2_no",32(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define SAVE_1x8(b1_no)\ | ||
"vmovups %%ymm"#b1_no",(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define SAVE_1x4(b1_no)\ | ||
"vmovups %%xmm"#b1_no",(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define COPY_1x16 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; vmulps 32(%0),%%ymm15,%%ymm1; leaq (%0,%2,1),%0;"\ | ||
SAVE_1x16(0,1) | ||
|
||
#define COPY_1x8 \ | ||
"vmulps (%0),%%ymm15,%%ymm0; leaq (%0,%2,1),%0;"\ | ||
SAVE_1x8(0) | ||
|
||
#define COPY_1x4 \ | ||
"vmulps (%0),%%xmm15,%%xmm0; leaq (%0,%2,1),%0;"\ | ||
SAVE_1x4(0) | ||
|
||
#define COPY_1x2 \ | ||
"vmovsd (%0),%%xmm0; vmulps %%xmm15,%%xmm0,%%xmm0; leaq (%0,%2,1),%0;"\ | ||
"vmovsd %%xmm0,(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define COPY_1x1 \ | ||
"vmovss (%0),%%xmm0; leaq (%0,%2,1),%0;"\ | ||
"vmulps %%xmm15,%%xmm0,%%xmm0; vmovss %%xmm0,(%1); leaq (%1,%3,1),%1;" | ||
|
||
#define COMPUTE(ndim){\ | ||
src = src_base; dst = dst_base;\ | ||
__asm__ __volatile__(\ | ||
"vbroadcastss %6,%%ymm15; movq %5,%%r11; cmpq $4,%%r11; jb "#ndim"32f;"\ | ||
#ndim"31:\n\t"\ | ||
COPY_4x##ndim "subq $4,%%r11; cmpq $4,%%r11; jnb "#ndim"31b;"\ | ||
#ndim"32:\n\t"\ | ||
"cmpq $2,%%r11; jb "#ndim"33f;"\ | ||
COPY_2x##ndim "subq $2,%%r11;"\ | ||
#ndim"33:\n\t"\ | ||
"testq %%r11,%%r11; jz "#ndim"34f;"\ | ||
COPY_1x##ndim "subq $1,%%r11;"\ | ||
#ndim"34:\n\t"\ | ||
:"+r"(src),"+r"(dst),"+r"(src_ld_bytes),"+r"(dst_ld_bytes),"+r"(dst_tmp):"m"(num_rows),"m"(ALPHA):"r11","cc","memory"\ | ||
,"xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9","xmm10","xmm11","xmm12","xmm13","xmm14","xmm15");\ | ||
} | ||
int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *b, BLASLONG ldb){ | ||
float *src, *dst, *dst_tmp=0, *src_base, *dst_base; | ||
uint64_t src_ld_bytes = (uint64_t)lda * sizeof(float), dst_ld_bytes = (uint64_t)ldb * sizeof(float), num_rows = 0; | ||
BLASLONG cols_left, rows_done; float ALPHA = alpha; | ||
if(ALPHA==0.0){ | ||
dst_base = b; | ||
for(cols_left=cols;cols_left>0;cols_left--) {memset(dst_base,0,rows*sizeof(float)); dst_base += ldb;} | ||
return 0; | ||
} | ||
for(rows_done=0;rows_done<rows;rows_done+=num_rows){ | ||
num_rows = rows-rows_done; | ||
if(num_rows > ROWS_OF_BLOCK) num_rows = ROWS_OF_BLOCK; | ||
cols_left = cols; src_base = a + (int64_t)lda * (int64_t)rows_done; dst_base = b + rows_done; | ||
if(ldb%1024>3 && ldb%1024<1021) for(;cols_left>15;cols_left-=16){COMPUTE(16) src_base += 16; dst_base += 16;} | ||
for(;cols_left>7;cols_left-=8){COMPUTE(8) src_base += 8; dst_base += 8;} | ||
for(;cols_left>3;cols_left-=4){COMPUTE(4) src_base += 4; dst_base += 4;} | ||
for(;cols_left>1;cols_left-=2){COMPUTE(2) src_base += 2; dst_base += 2;} | ||
if(cols_left>0){COMPUTE(1) src_base ++; dst_base ++;} | ||
} | ||
return 0; | ||
} | ||
|
||
#else | ||
|
||
int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *b, BLASLONG ldb) | ||
{ | ||
BLASLONG i, j; | ||
FLOAT *a_offset, *a_offset1, *a_offset2, *a_offset3, *a_offset4; | ||
FLOAT *b_offset, *b_offset1, *b_offset2, *b_offset3, *b_offset4; | ||
|
||
if (rows <= 0) return 0; | ||
if (cols <= 0) return 0; | ||
|
||
a_offset = a; | ||
b_offset = b; | ||
|
||
i = (rows >> 2); | ||
if (i > 0) { | ||
do { | ||
a_offset1 = a_offset; | ||
a_offset2 = a_offset1 + lda; | ||
a_offset3 = a_offset2 + lda; | ||
a_offset4 = a_offset3 + lda; | ||
a_offset += 4 * lda; | ||
|
||
b_offset1 = b_offset; | ||
b_offset2 = b_offset1 + ldb; | ||
b_offset3 = b_offset2 + ldb; | ||
b_offset4 = b_offset3 + ldb; | ||
b_offset += 4 * ldb; | ||
|
||
j = (cols >> 2); | ||
if (j > 0) { | ||
do { | ||
/*Row 1 of MAT_B */ | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; // Row 1 of MAT_A | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
*(b_offset1 + 2) = *(a_offset1 + 2)*alpha; | ||
*(b_offset1 + 3) = *(a_offset1 + 3)*alpha; | ||
|
||
/* Row 2 of MAT_B */ | ||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; // Row 2 of MAT_A | ||
*(b_offset2 + 1) = *(a_offset2 + 1)*alpha; | ||
*(b_offset2 + 2) = *(a_offset2 + 2)*alpha; | ||
*(b_offset2 + 3) = *(a_offset2 + 3)*alpha; | ||
|
||
/* Row 3 of MAT_B */ | ||
*(b_offset3 + 0) = *(a_offset3 + 0)*alpha; // Row 3 of MAT_A | ||
*(b_offset3 + 1) = *(a_offset3 + 1)*alpha; | ||
*(b_offset3 + 2) = *(a_offset3 + 2)*alpha; | ||
*(b_offset3 + 3) = *(a_offset3 + 3)*alpha; | ||
|
||
/* Row 4 of MAT_B */ | ||
*(b_offset4 + 0) = *(a_offset4 + 0)*alpha; // Row 4 of MAT_A | ||
*(b_offset4 + 1) = *(a_offset4 + 1)*alpha; | ||
*(b_offset4 + 2) = *(a_offset4 + 2)*alpha; | ||
*(b_offset4 + 3) = *(a_offset4 + 3)*alpha; | ||
|
||
a_offset1 += 4; | ||
a_offset2 += 4; | ||
a_offset3 += 4; | ||
a_offset4 += 4; | ||
b_offset1 += 4; | ||
b_offset2 += 4; | ||
b_offset3 += 4; | ||
b_offset4 += 4; | ||
|
||
j--; | ||
} while (j > 0); | ||
} // if(j > 0) | ||
|
||
|
||
if (cols & 2) { | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
|
||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; | ||
*(b_offset2 + 1) = *(a_offset2 + 1)*alpha; | ||
|
||
*(b_offset3 + 0) = *(a_offset3 + 0)*alpha; | ||
*(b_offset3 + 1) = *(a_offset3 + 1)*alpha; | ||
|
||
*(b_offset4 + 0) = *(a_offset4 + 0)*alpha; | ||
*(b_offset4 + 1) = *(a_offset4 + 1)*alpha; | ||
|
||
a_offset1 += 2; | ||
a_offset2 += 2; | ||
a_offset3 += 2; | ||
a_offset4 += 2; | ||
|
||
b_offset1 += 2; | ||
b_offset2 += 2; | ||
b_offset3 += 2; | ||
b_offset4 += 2; | ||
} | ||
|
||
if (cols & 1) { | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
|
||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; | ||
|
||
*(b_offset3 + 0) = *(a_offset3 + 0)*alpha; | ||
|
||
*(b_offset4 + 0) = *(a_offset4 + 0)*alpha; | ||
} | ||
|
||
i--; | ||
} while (i > 0); | ||
} | ||
|
||
|
||
if (rows & 2) { | ||
a_offset1 = a_offset; | ||
a_offset2 = a_offset1 + lda; | ||
a_offset += 2 * lda; | ||
|
||
b_offset1 = b_offset; | ||
b_offset2 = b_offset1 + ldb; | ||
b_offset += 2 * ldb; | ||
|
||
j = (cols >> 2); | ||
if (j > 0){ | ||
do { | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
*(b_offset1 + 2) = *(a_offset1 + 2)*alpha; | ||
*(b_offset1 + 3) = *(a_offset1 + 3)*alpha; | ||
|
||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; | ||
*(b_offset2 + 1) = *(a_offset2 + 1)*alpha; | ||
*(b_offset2 + 2) = *(a_offset2 + 2)*alpha; | ||
*(b_offset2 + 3) = *(a_offset2 + 3)*alpha; | ||
|
||
a_offset1 += 4; | ||
a_offset2 += 4; | ||
b_offset1 += 4; | ||
b_offset2 += 4; | ||
|
||
j--; | ||
} while (j > 0); | ||
} | ||
|
||
|
||
if (cols & 2){ | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
|
||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; | ||
*(b_offset2 + 1) = *(a_offset2 + 1)*alpha; | ||
|
||
a_offset1 += 2; | ||
a_offset2 += 2; | ||
b_offset1 += 2; | ||
b_offset2 += 2; | ||
} | ||
|
||
if (cols & 1){ | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset2 + 0) = *(a_offset2 + 0)*alpha; | ||
} | ||
} // if (rows & 2) | ||
|
||
|
||
if (rows & 1) { | ||
a_offset1 = a_offset; | ||
|
||
b_offset1 = b_offset; | ||
|
||
j = (cols >> 2); | ||
if (j > 0){ | ||
do { | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
*(b_offset1 + 2) = *(a_offset1 + 2)*alpha; | ||
*(b_offset1 + 3) = *(a_offset1 + 3)*alpha; | ||
|
||
a_offset1 += 4; | ||
b_offset1 += 4; | ||
|
||
j--; | ||
} while (j > 0); | ||
} | ||
|
||
if (cols & 2){ | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
*(b_offset1 + 1) = *(a_offset1 + 1)*alpha; | ||
|
||
a_offset1 += 2; | ||
b_offset1 += 2; | ||
} | ||
|
||
if (cols & 1){ | ||
*(b_offset1 + 0) = *(a_offset1 + 0)*alpha; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#endif |