|
| 1 | +/*************************************************************************** |
| 2 | + * Copyright (c) 2022, The OpenBLAS Project |
| 3 | + * All rights reserved. |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions are |
| 6 | + * met: |
| 7 | + * 1. Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in |
| 11 | + * the documentation and/or other materials provided with the |
| 12 | + * distribution. |
| 13 | + * 3. Neither the name of the OpenBLAS project nor the names of |
| 14 | + * its contributors may be used to endorse or promote products |
| 15 | + * derived from this software without specific prior written permission. |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * *****************************************************************************/ |
| 28 | + |
| 29 | +#include <arm_sve.h> |
| 30 | + |
| 31 | +#include "common.h" |
| 32 | + |
| 33 | +int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b) { |
| 34 | + IFLOAT *a_offset; |
| 35 | + IFLOAT *a_offsetx[8]; |
| 36 | + IFLOAT *b_offset; |
| 37 | + a_offset = a; |
| 38 | + b_offset = b; |
| 39 | + |
| 40 | + svbool_t pg16 = svdupq_b16(1, 1, 1, 1, 0, 0, 0, 0); |
| 41 | + svbfloat16_t v0, v1, v2, v3, v4, v5, v6, v7; |
| 42 | + |
| 43 | + for (BLASLONG j = 0; j < n / 8; j++) { |
| 44 | + a_offsetx[0] = a_offset; |
| 45 | + a_offsetx[1] = a_offsetx[0] + lda; |
| 46 | + a_offsetx[2] = a_offsetx[1] + lda; |
| 47 | + a_offsetx[3] = a_offsetx[2] + lda; |
| 48 | + a_offsetx[4] = a_offsetx[3] + lda; |
| 49 | + a_offsetx[5] = a_offsetx[4] + lda; |
| 50 | + a_offsetx[6] = a_offsetx[5] + lda; |
| 51 | + a_offsetx[7] = a_offsetx[6] + lda; |
| 52 | + a_offset += 8 * lda; |
| 53 | + |
| 54 | + for (BLASLONG i = 0; i < m / 4; i++) { |
| 55 | + v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]); |
| 56 | + v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]); |
| 57 | + v2 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[2]); |
| 58 | + v3 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[3]); |
| 59 | + v4 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[4]); |
| 60 | + v5 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[5]); |
| 61 | + v6 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[6]); |
| 62 | + v7 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[7]); |
| 63 | + |
| 64 | + svst1_bf16(pg16, (bfloat16_t *)b_offset, v0); |
| 65 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1); |
| 66 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 8, v2); |
| 67 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 12, v3); |
| 68 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 16, v4); |
| 69 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 20, v5); |
| 70 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 24, v6); |
| 71 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 28, v7); |
| 72 | + |
| 73 | + b_offset += 32; |
| 74 | + a_offsetx[0] += 4; |
| 75 | + a_offsetx[1] += 4; |
| 76 | + a_offsetx[2] += 4; |
| 77 | + a_offsetx[3] += 4; |
| 78 | + a_offsetx[4] += 4; |
| 79 | + a_offsetx[5] += 4; |
| 80 | + a_offsetx[6] += 4; |
| 81 | + a_offsetx[7] += 4; |
| 82 | + } |
| 83 | + |
| 84 | + if (m & 3) { |
| 85 | + BLASLONG rest = m & 3; |
| 86 | + for (BLASLONG col = 0; col < 4; col++) { |
| 87 | + b_offset[4 * col] = a_offsetx[col][0]; |
| 88 | + b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1]; |
| 89 | + b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2]; |
| 90 | + b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3]; |
| 91 | + } |
| 92 | + b_offset += 16; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + if (n & 4) { |
| 97 | + a_offsetx[0] = a_offset; |
| 98 | + a_offsetx[1] = a_offsetx[0] + lda; |
| 99 | + a_offsetx[2] = a_offsetx[1] + lda; |
| 100 | + a_offsetx[3] = a_offsetx[2] + lda; |
| 101 | + a_offset += 4 * lda; |
| 102 | + |
| 103 | + for (BLASLONG i = 0; i < m / 4; i++) { |
| 104 | + v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]); |
| 105 | + v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]); |
| 106 | + v2 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[2]); |
| 107 | + v3 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[3]); |
| 108 | + |
| 109 | + svst1_bf16(pg16, (bfloat16_t *)b_offset, v0); |
| 110 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1); |
| 111 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 8, v2); |
| 112 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 12, v3); |
| 113 | + |
| 114 | + b_offset += 16; |
| 115 | + a_offsetx[0] += 4; |
| 116 | + a_offsetx[1] += 4; |
| 117 | + a_offsetx[2] += 4; |
| 118 | + a_offsetx[3] += 4; |
| 119 | + } |
| 120 | + |
| 121 | + if (m & 3) { |
| 122 | + BLASLONG rest = m & 3; |
| 123 | + for (BLASLONG col = 0; col < 4; col++) { |
| 124 | + b_offset[4 * col] = a_offsetx[col][0]; |
| 125 | + b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1]; |
| 126 | + b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2]; |
| 127 | + b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3]; |
| 128 | + } |
| 129 | + b_offset += 16; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if (n & 2) { |
| 134 | + a_offsetx[0] = a_offset; |
| 135 | + a_offsetx[1] = a_offsetx[0] + lda; |
| 136 | + a_offset += 2 * lda; |
| 137 | + |
| 138 | + for (BLASLONG i = 0; i < m / 4; i++) { |
| 139 | + v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]); |
| 140 | + v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]); |
| 141 | + svst1_bf16(pg16, (bfloat16_t *)b_offset, v0); |
| 142 | + svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1); |
| 143 | + |
| 144 | + b_offset += 8; |
| 145 | + a_offsetx[0] += 4; |
| 146 | + a_offsetx[1] += 4; |
| 147 | + } |
| 148 | + |
| 149 | + if (m & 3) { |
| 150 | + BLASLONG rest = m & 3; |
| 151 | + for (BLASLONG col = 0; col < 2; col++) { |
| 152 | + b_offset[4 * col] = a_offsetx[col][0]; |
| 153 | + b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1]; |
| 154 | + b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2]; |
| 155 | + b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3]; |
| 156 | + } |
| 157 | + b_offset += 8; |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + if (n & 1) { |
| 162 | + a_offsetx[0] = a_offset; |
| 163 | + for (BLASLONG i = 0; i < m / 4; i++) { |
| 164 | + v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]); |
| 165 | + svst1_bf16(pg16, (bfloat16_t *)b_offset, v0); |
| 166 | + b_offset += 4; |
| 167 | + a_offsetx[0] += 4; |
| 168 | + } |
| 169 | + if (m & 3) { |
| 170 | + BLASLONG rest = m & 3; |
| 171 | + b_offset[0] = a_offsetx[0][0]; |
| 172 | + b_offset[1] = rest == 1 ? 0 : a_offsetx[0][1]; |
| 173 | + b_offset[2] = rest <= 2 ? 0 : a_offsetx[0][2]; |
| 174 | + b_offset[3] = rest <= 3 ? 0 : a_offsetx[0][3]; |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + return 0; |
| 179 | +} |
0 commit comments