| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-gemm/MRx8c8-avx2.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2020 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <immintrin.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/gemm.h" |
| 16 |
#include "xnnpack/intrinsics-polyfill.h" |
| 17 |
#include "xnnpack/math.h" |
| 18 |
#include "xnnpack/unaligned.h" |
| 19 |
|
| 20 |
|
| 21 |
void xnn_qd8_f32_qb4w_gemm_minmax_ukernel_4x8c8__avx2( |
| 22 |
size_t mr, |
| 23 |
size_t nc, |
| 24 |
size_t kc, |
| 25 |
const int8_t* restrict a, |
| 26 |
size_t a_stride, |
| 27 |
const void* restrict w, |
| 28 |
float* restrict c, |
| 29 |
size_t cm_stride, |
| 30 |
size_t cn_stride, |
| 31 |
const struct xnn_f32_qb4w_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], |
| 32 |
const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 33 |
{ |
| 34 |
assert(mr != 0); |
| 35 |
assert(mr <= 4); |
| 36 |
assert(nc != 0); |
| 37 |
assert(kc != 0); |
| 38 |
assert(kc % sizeof(int8_t) == 0); |
| 39 |
assert(a != NULL); |
| 40 |
assert(w != NULL); |
| 41 |
assert(c != NULL); |
| 42 |
|
| 43 |
kc = round_up_po2(kc, 8 * sizeof(int8_t)); |
| 44 |
size_t bl = params->scalar.blocksize; |
| 45 |
assert(bl <= round_up_po2(kc, 16)); |
| 46 |
assert(bl != 0); |
| 47 |
assert(bl % 32 == 0); |
| 48 |
const int8_t* a0 = a; |
| 49 |
float* c0 = c; |
| 50 |
const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); |
| 51 |
float* c1 = (float*) ((uintptr_t) c0 + cm_stride); |
| 52 |
if XNN_UNPREDICTABLE(mr < 2) { |
| 53 |
a1 = a0; |
| 54 |
c1 = c0; |
| 55 |
} |
| 56 |
const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); |
| 57 |
float* c2 = (float*) ((uintptr_t) c1 + cm_stride); |
| 58 |
if XNN_UNPREDICTABLE(mr <= 2) { |
| 59 |
a2 = a1; |
| 60 |
c2 = c1; |
| 61 |
} |
| 62 |
const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); |
| 63 |
float* c3 = (float*) ((uintptr_t) c2 + cm_stride); |
| 64 |
if XNN_UNPREDICTABLE(mr != 4) { |
| 65 |
a3 = a2; |
| 66 |
c3 = c2; |
| 67 |
} |
| 68 |
|
| 69 |
const __m128i vmask = _mm_set1_epi8(0xF0); |
| 70 |
XNN_FORCE_REALIZATION(vmask); |
| 71 |
const __m256 vmin = _mm256_set1_ps(params->scalar.min); |
| 72 |
const __m256 vmax = _mm256_set1_ps(params->scalar.max); |
| 73 |
XNN_FORCE_REALIZATION(vmin); |
| 74 |
XNN_FORCE_REALIZATION(vmax); |
| 75 |
|
| 76 |
do { |
| 77 |
const __m128 vinit0 = _mm_load_ss(&((const float*) w)[0]); |
| 78 |
const __m128 vinit1 = _mm_load_ss(&((const float*) w)[1]); |
| 79 |
const __m256 vinit01 = _mm256_insertf128_ps(_mm256_castps128_ps256(vinit0), vinit1, 1); |
| 80 |
const __m128 vinit2 = _mm_load_ss(&((const float*) w)[2]); |
| 81 |
const __m128 vinit3 = _mm_load_ss(&((const float*) w)[3]); |
| 82 |
const __m256 vinit23 = _mm256_insertf128_ps(_mm256_castps128_ps256(vinit2), vinit3, 1); |
| 83 |
const __m128 vinit4 = _mm_load_ss(&((const float*) w)[4]); |
| 84 |
const __m128 vinit5 = _mm_load_ss(&((const float*) w)[5]); |
| 85 |
const __m256 vinit45 = _mm256_insertf128_ps(_mm256_castps128_ps256(vinit4), vinit5, 1); |
| 86 |
const __m128 vinit6 = _mm_load_ss(&((const float*) w)[6]); |
| 87 |
const __m128 vinit7 = _mm_load_ss(&((const float*) w)[7]); |
| 88 |
const __m256 vinit67 = _mm256_insertf128_ps(_mm256_castps128_ps256(vinit6), vinit7, 1); |
| 89 |
const __m256 vinput_zero_point0 = _mm256_set1_ps((float) quantization_params[0].zero_point); |
| 90 |
__m256 vout0x01 = _mm256_mul_ps(vinit01, vinput_zero_point0); |
| 91 |
__m256 vout0x23 = _mm256_mul_ps(vinit23, vinput_zero_point0); |
| 92 |
__m256 vout0x45 = _mm256_mul_ps(vinit45, vinput_zero_point0); |
| 93 |
__m256 vout0x67 = _mm256_mul_ps(vinit67, vinput_zero_point0); |
| 94 |
const __m256 vinput_zero_point1 = _mm256_set1_ps((float) quantization_params[1].zero_point); |
| 95 |
__m256 vout1x01 = _mm256_mul_ps(vinit01, vinput_zero_point1); |
| 96 |
__m256 vout1x23 = _mm256_mul_ps(vinit23, vinput_zero_point1); |
| 97 |
__m256 vout1x45 = _mm256_mul_ps(vinit45, vinput_zero_point1); |
| 98 |
__m256 vout1x67 = _mm256_mul_ps(vinit67, vinput_zero_point1); |
| 99 |
const __m256 vinput_zero_point2 = _mm256_set1_ps((float) quantization_params[2].zero_point); |
| 100 |
__m256 vout2x01 = _mm256_mul_ps(vinit01, vinput_zero_point2); |
| 101 |
__m256 vout2x23 = _mm256_mul_ps(vinit23, vinput_zero_point2); |
| 102 |
__m256 vout2x45 = _mm256_mul_ps(vinit45, vinput_zero_point2); |
| 103 |
__m256 vout2x67 = _mm256_mul_ps(vinit67, vinput_zero_point2); |
| 104 |
const __m256 vinput_zero_point3 = _mm256_set1_ps((float) quantization_params[3].zero_point); |
| 105 |
__m256 vout3x01 = _mm256_mul_ps(vinit01, vinput_zero_point3); |
| 106 |
__m256 vout3x23 = _mm256_mul_ps(vinit23, vinput_zero_point3); |
| 107 |
__m256 vout3x45 = _mm256_mul_ps(vinit45, vinput_zero_point3); |
| 108 |
__m256 vout3x67 = _mm256_mul_ps(vinit67, vinput_zero_point3); |
| 109 |
w = (const int32_t*) w + 8; |
| 110 |
|
| 111 |
for (size_t kb=0; kb < kc; kb += bl) { |
| 112 |
__m256i vacc0x01 = _mm256_setzero_si256(); |
| 113 |
__m256i vacc0x23 = _mm256_setzero_si256(); |
| 114 |
__m256i vacc0x45 = _mm256_setzero_si256(); |
| 115 |
__m256i vacc0x67 = _mm256_setzero_si256(); |
| 116 |
__m256i vacc1x01 = _mm256_setzero_si256(); |
| 117 |
__m256i vacc1x23 = _mm256_setzero_si256(); |
| 118 |
__m256i vacc1x45 = _mm256_setzero_si256(); |
| 119 |
__m256i vacc1x67 = _mm256_setzero_si256(); |
| 120 |
__m256i vacc2x01 = _mm256_setzero_si256(); |
| 121 |
__m256i vacc2x23 = _mm256_setzero_si256(); |
| 122 |
__m256i vacc2x45 = _mm256_setzero_si256(); |
| 123 |
__m256i vacc2x67 = _mm256_setzero_si256(); |
| 124 |
__m256i vacc3x01 = _mm256_setzero_si256(); |
| 125 |
__m256i vacc3x23 = _mm256_setzero_si256(); |
| 126 |
__m256i vacc3x45 = _mm256_setzero_si256(); |
| 127 |
__m256i vacc3x67 = _mm256_setzero_si256(); |
| 128 |
|
| 129 |
size_t k = bl; |
| 130 |
while (k >= 16 * sizeof(int8_t)) { |
| 131 |
__m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0)); |
| 132 |
__m256i vxa0 = _mm256_cvtepi8_epi16(va0); |
| 133 |
a0 += 8; |
| 134 |
__m128i va1 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a1)); |
| 135 |
__m256i vxa1 = _mm256_cvtepi8_epi16(va1); |
| 136 |
a1 += 8; |
| 137 |
__m128i va2 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a2)); |
| 138 |
__m256i vxa2 = _mm256_cvtepi8_epi16(va2); |
| 139 |
a2 += 8; |
| 140 |
__m128i va3 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a3)); |
| 141 |
__m256i vxa3 = _mm256_cvtepi8_epi16(va3); |
| 142 |
a3 += 8; |
| 143 |
|
| 144 |
__m128i vb01 = _mm_load_si128((const __m128i*) w); |
| 145 |
__m128i vbs01 = _mm_slli_epi32(vb01, 4); |
| 146 |
__m128i vbm01 = _mm_and_si128(vbs01, vmask); |
| 147 |
__m256i vxb01 = _mm256_cvtepi8_epi16(vbm01); |
| 148 |
|
| 149 |
vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01)); |
| 150 |
vacc1x01 = _mm256_add_epi32(vacc1x01, _mm256_madd_epi16(vxa1, vxb01)); |
| 151 |
vacc2x01 = _mm256_add_epi32(vacc2x01, _mm256_madd_epi16(vxa2, vxb01)); |
| 152 |
vacc3x01 = _mm256_add_epi32(vacc3x01, _mm256_madd_epi16(vxa3, vxb01)); |
| 153 |
__m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); |
| 154 |
__m128i vbs23 = _mm_slli_epi32(vb23, 4); |
| 155 |
__m128i vbm23 = _mm_and_si128(vbs23, vmask); |
| 156 |
__m256i vxb23 = _mm256_cvtepi8_epi16(vbm23); |
| 157 |
|
| 158 |
vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23)); |
| 159 |
vacc1x23 = _mm256_add_epi32(vacc1x23, _mm256_madd_epi16(vxa1, vxb23)); |
| 160 |
vacc2x23 = _mm256_add_epi32(vacc2x23, _mm256_madd_epi16(vxa2, vxb23)); |
| 161 |
vacc3x23 = _mm256_add_epi32(vacc3x23, _mm256_madd_epi16(vxa3, vxb23)); |
| 162 |
__m128i vb45 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 32)); |
| 163 |
__m128i vbs45 = _mm_slli_epi32(vb45, 4); |
| 164 |
__m128i vbm45 = _mm_and_si128(vbs45, vmask); |
| 165 |
__m256i vxb45 = _mm256_cvtepi8_epi16(vbm45); |
| 166 |
|
| 167 |
vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45)); |
| 168 |
vacc1x45 = _mm256_add_epi32(vacc1x45, _mm256_madd_epi16(vxa1, vxb45)); |
| 169 |
vacc2x45 = _mm256_add_epi32(vacc2x45, _mm256_madd_epi16(vxa2, vxb45)); |
| 170 |
vacc3x45 = _mm256_add_epi32(vacc3x45, _mm256_madd_epi16(vxa3, vxb45)); |
| 171 |
__m128i vb67 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 48)); |
| 172 |
__m128i vbs67 = _mm_slli_epi32(vb67, 4); |
| 173 |
__m128i vbm67 = _mm_and_si128(vbs67, vmask); |
| 174 |
__m256i vxb67 = _mm256_cvtepi8_epi16(vbm67); |
| 175 |
|
| 176 |
vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67)); |
| 177 |
vacc1x67 = _mm256_add_epi32(vacc1x67, _mm256_madd_epi16(vxa1, vxb67)); |
| 178 |
vacc2x67 = _mm256_add_epi32(vacc2x67, _mm256_madd_epi16(vxa2, vxb67)); |
| 179 |
vacc3x67 = _mm256_add_epi32(vacc3x67, _mm256_madd_epi16(vxa3, vxb67)); |
| 180 |
|
| 181 |
va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0)); |
| 182 |
vxa0 = _mm256_cvtepi8_epi16(va0); |
| 183 |
a0 += 8; |
| 184 |
va1 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a1)); |
| 185 |
vxa1 = _mm256_cvtepi8_epi16(va1); |
| 186 |
a1 += 8; |
| 187 |
va2 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a2)); |
| 188 |
vxa2 = _mm256_cvtepi8_epi16(va2); |
| 189 |
a2 += 8; |
| 190 |
va3 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a3)); |
| 191 |
vxa3 = _mm256_cvtepi8_epi16(va3); |
| 192 |
a3 += 8; |
| 193 |
|
| 194 |
vbm01 = _mm_and_si128(vb01, vmask); |
| 195 |
vxb01 = _mm256_cvtepi8_epi16(vbm01); |
| 196 |
|
| 197 |
vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01)); |
| 198 |
vacc1x01 = _mm256_add_epi32(vacc1x01, _mm256_madd_epi16(vxa1, vxb01)); |
| 199 |
vacc2x01 = _mm256_add_epi32(vacc2x01, _mm256_madd_epi16(vxa2, vxb01)); |
| 200 |
vacc3x01 = _mm256_add_epi32(vacc3x01, _mm256_madd_epi16(vxa3, vxb01)); |
| 201 |
vbm23 = _mm_and_si128(vb23, vmask); |
| 202 |
vxb23 = _mm256_cvtepi8_epi16(vbm23); |
| 203 |
|
| 204 |
vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23)); |
| 205 |
vacc1x23 = _mm256_add_epi32(vacc1x23, _mm256_madd_epi16(vxa1, vxb23)); |
| 206 |
vacc2x23 = _mm256_add_epi32(vacc2x23, _mm256_madd_epi16(vxa2, vxb23)); |
| 207 |
vacc3x23 = _mm256_add_epi32(vacc3x23, _mm256_madd_epi16(vxa3, vxb23)); |
| 208 |
vbm45 = _mm_and_si128(vb45, vmask); |
| 209 |
vxb45 = _mm256_cvtepi8_epi16(vbm45); |
| 210 |
|
| 211 |
vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45)); |
| 212 |
vacc1x45 = _mm256_add_epi32(vacc1x45, _mm256_madd_epi16(vxa1, vxb45)); |
| 213 |
vacc2x45 = _mm256_add_epi32(vacc2x45, _mm256_madd_epi16(vxa2, vxb45)); |
| 214 |
vacc3x45 = _mm256_add_epi32(vacc3x45, _mm256_madd_epi16(vxa3, vxb45)); |
| 215 |
vbm67 = _mm_and_si128(vb67, vmask); |
| 216 |
vxb67 = _mm256_cvtepi8_epi16(vbm67); |
| 217 |
|
| 218 |
vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67)); |
| 219 |
vacc1x67 = _mm256_add_epi32(vacc1x67, _mm256_madd_epi16(vxa1, vxb67)); |
| 220 |
vacc2x67 = _mm256_add_epi32(vacc2x67, _mm256_madd_epi16(vxa2, vxb67)); |
| 221 |
vacc3x67 = _mm256_add_epi32(vacc3x67, _mm256_madd_epi16(vxa3, vxb67)); |
| 222 |
|
| 223 |
w = (const int8_t*) w + 64; |
| 224 |
k -= 16 * sizeof(int8_t); |
| 225 |
} |
| 226 |
|
| 227 |
while (k >= 8 * sizeof(int8_t)) { |
| 228 |
const __m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0)); |
| 229 |
const __m256i vxa0 = _mm256_cvtepi8_epi16(va0); |
| 230 |
a0 += 8; |
| 231 |
const __m128i va1 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a1)); |
| 232 |
const __m256i vxa1 = _mm256_cvtepi8_epi16(va1); |
| 233 |
a1 += 8; |
| 234 |
const __m128i va2 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a2)); |
| 235 |
const __m256i vxa2 = _mm256_cvtepi8_epi16(va2); |
| 236 |
a2 += 8; |
| 237 |
const __m128i va3 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a3)); |
| 238 |
const __m256i vxa3 = _mm256_cvtepi8_epi16(va3); |
| 239 |
a3 += 8; |
| 240 |
|
| 241 |
const __m128i vb01 = _mm_load_si128((const __m128i*) w); |
| 242 |
const __m128i vbs01 = _mm_slli_epi32(vb01, 4); |
| 243 |
const __m128i vbm01 = _mm_and_si128(vbs01, vmask); |
| 244 |
const __m256i vxb01 = _mm256_cvtepi8_epi16(vbm01); |
| 245 |
|
| 246 |
vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01)); |
| 247 |
vacc1x01 = _mm256_add_epi32(vacc1x01, _mm256_madd_epi16(vxa1, vxb01)); |
| 248 |
vacc2x01 = _mm256_add_epi32(vacc2x01, _mm256_madd_epi16(vxa2, vxb01)); |
| 249 |
vacc3x01 = _mm256_add_epi32(vacc3x01, _mm256_madd_epi16(vxa3, vxb01)); |
| 250 |
const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); |
| 251 |
const __m128i vbs23 = _mm_slli_epi32(vb23, 4); |
| 252 |
const __m128i vbm23 = _mm_and_si128(vbs23, vmask); |
| 253 |
const __m256i vxb23 = _mm256_cvtepi8_epi16(vbm23); |
| 254 |
|
| 255 |
vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23)); |
| 256 |
vacc1x23 = _mm256_add_epi32(vacc1x23, _mm256_madd_epi16(vxa1, vxb23)); |
| 257 |
vacc2x23 = _mm256_add_epi32(vacc2x23, _mm256_madd_epi16(vxa2, vxb23)); |
| 258 |
vacc3x23 = _mm256_add_epi32(vacc3x23, _mm256_madd_epi16(vxa3, vxb23)); |
| 259 |
const __m128i vb45 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 32)); |
| 260 |
const __m128i vbs45 = _mm_slli_epi32(vb45, 4); |
| 261 |
const __m128i vbm45 = _mm_and_si128(vbs45, vmask); |
| 262 |
const __m256i vxb45 = _mm256_cvtepi8_epi16(vbm45); |
| 263 |
|
| 264 |
vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45)); |
| 265 |
vacc1x45 = _mm256_add_epi32(vacc1x45, _mm256_madd_epi16(vxa1, vxb45)); |
| 266 |
vacc2x45 = _mm256_add_epi32(vacc2x45, _mm256_madd_epi16(vxa2, vxb45)); |
| 267 |
vacc3x45 = _mm256_add_epi32(vacc3x45, _mm256_madd_epi16(vxa3, vxb45)); |
| 268 |
const __m128i vb67 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 48)); |
| 269 |
const __m128i vbs67 = _mm_slli_epi32(vb67, 4); |
| 270 |
const __m128i vbm67 = _mm_and_si128(vbs67, vmask); |
| 271 |
const __m256i vxb67 = _mm256_cvtepi8_epi16(vbm67); |
| 272 |
|
| 273 |
vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67)); |
| 274 |
vacc1x67 = _mm256_add_epi32(vacc1x67, _mm256_madd_epi16(vxa1, vxb67)); |
| 275 |
vacc2x67 = _mm256_add_epi32(vacc2x67, _mm256_madd_epi16(vxa2, vxb67)); |
| 276 |
vacc3x67 = _mm256_add_epi32(vacc3x67, _mm256_madd_epi16(vxa3, vxb67)); |
| 277 |
|
| 278 |
w = (const int8_t*) w + 64; |
| 279 |
k -= 8 * sizeof(int8_t); |
| 280 |
} |
| 281 |
|
| 282 |
const __m128 vfilter_output_scale0 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[0] << 16)); |
| 283 |
const __m128 vfilter_output_scale1 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[1] << 16)); |
| 284 |
const __m256 vfilter_output_scale01 = _mm256_insertf128_ps( |
| 285 |
_mm256_castps128_ps256(vfilter_output_scale0), vfilter_output_scale1, 1); |
| 286 |
vout0x01 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc0x01), vfilter_output_scale01, vout0x01); |
| 287 |
vout1x01 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc1x01), vfilter_output_scale01, vout1x01); |
| 288 |
vout2x01 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc2x01), vfilter_output_scale01, vout2x01); |
| 289 |
vout3x01 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc3x01), vfilter_output_scale01, vout3x01); |
| 290 |
const __m128 vfilter_output_scale2 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[2] << 16)); |
| 291 |
const __m128 vfilter_output_scale3 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[3] << 16)); |
| 292 |
const __m256 vfilter_output_scale23 = _mm256_insertf128_ps( |
| 293 |
_mm256_castps128_ps256(vfilter_output_scale2), vfilter_output_scale3, 1); |
| 294 |
vout0x23 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc0x23), vfilter_output_scale23, vout0x23); |
| 295 |
vout1x23 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc1x23), vfilter_output_scale23, vout1x23); |
| 296 |
vout2x23 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc2x23), vfilter_output_scale23, vout2x23); |
| 297 |
vout3x23 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc3x23), vfilter_output_scale23, vout3x23); |
| 298 |
const __m128 vfilter_output_scale4 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[4] << 16)); |
| 299 |
const __m128 vfilter_output_scale5 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[5] << 16)); |
| 300 |
const __m256 vfilter_output_scale45 = _mm256_insertf128_ps( |
| 301 |
_mm256_castps128_ps256(vfilter_output_scale4), vfilter_output_scale5, 1); |
| 302 |
vout0x45 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc0x45), vfilter_output_scale45, vout0x45); |
| 303 |
vout1x45 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc1x45), vfilter_output_scale45, vout1x45); |
| 304 |
vout2x45 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc2x45), vfilter_output_scale45, vout2x45); |
| 305 |
vout3x45 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc3x45), vfilter_output_scale45, vout3x45); |
| 306 |
const __m128 vfilter_output_scale6 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[6] << 16)); |
| 307 |
const __m128 vfilter_output_scale7 = _mm_castsi128_ps(_mm_set1_epi32((uint32_t) ((const uint16_t*) w)[7] << 16)); |
| 308 |
const __m256 vfilter_output_scale67 = _mm256_insertf128_ps( |
| 309 |
_mm256_castps128_ps256(vfilter_output_scale6), vfilter_output_scale7, 1); |
| 310 |
vout0x67 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc0x67), vfilter_output_scale67, vout0x67); |
| 311 |
vout1x67 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc1x67), vfilter_output_scale67, vout1x67); |
| 312 |
vout2x67 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc2x67), vfilter_output_scale67, vout2x67); |
| 313 |
vout3x67 = _mm256_fmadd_ps(_mm256_cvtepi32_ps(vacc3x67), vfilter_output_scale67, vout3x67); |
| 314 |
|
| 315 |
w = (const uint16_t*) w + 8; |
| 316 |
} |
| 317 |
|
| 318 |
const __m256 vout0x0213 = _mm256_hadd_ps(vout0x01, vout0x23); |
| 319 |
const __m256 vout0x4657 = _mm256_hadd_ps(vout0x45, vout0x67); |
| 320 |
const __m256 vout1x0213 = _mm256_hadd_ps(vout1x01, vout1x23); |
| 321 |
const __m256 vout1x4657 = _mm256_hadd_ps(vout1x45, vout1x67); |
| 322 |
const __m256 vout2x0213 = _mm256_hadd_ps(vout2x01, vout2x23); |
| 323 |
const __m256 vout2x4657 = _mm256_hadd_ps(vout2x45, vout2x67); |
| 324 |
const __m256 vout3x0213 = _mm256_hadd_ps(vout3x01, vout3x23); |
| 325 |
const __m256 vout3x4657 = _mm256_hadd_ps(vout3x45, vout3x67); |
| 326 |
|
| 327 |
const __m256 vout0x02461357 = _mm256_hadd_ps(vout0x0213, vout0x4657); |
| 328 |
const __m256 vout1x02461357 = _mm256_hadd_ps(vout1x0213, vout1x4657); |
| 329 |
const __m256 vout2x02461357 = _mm256_hadd_ps(vout2x0213, vout2x4657); |
| 330 |
const __m256 vout3x02461357 = _mm256_hadd_ps(vout3x0213, vout3x4657); |
| 331 |
|
| 332 |
const __m256i vpermute_mask = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0); |
| 333 |
__m256 vout0x01234567 = _mm256_permutevar8x32_ps(vout0x02461357, vpermute_mask); |
| 334 |
__m256 vout1x01234567 = _mm256_permutevar8x32_ps(vout1x02461357, vpermute_mask); |
| 335 |
__m256 vout2x01234567 = _mm256_permutevar8x32_ps(vout2x02461357, vpermute_mask); |
| 336 |
__m256 vout3x01234567 = _mm256_permutevar8x32_ps(vout3x02461357, vpermute_mask); |
| 337 |
|
| 338 |
const __m256 vinput_scale0 = _mm256_broadcast_ss(&quantization_params[0].inv_scale); |
| 339 |
const __m256 vinput_scale1 = _mm256_broadcast_ss(&quantization_params[1].inv_scale); |
| 340 |
const __m256 vinput_scale2 = _mm256_broadcast_ss(&quantization_params[2].inv_scale); |
| 341 |
const __m256 vinput_scale3 = _mm256_broadcast_ss(&quantization_params[3].inv_scale); |
| 342 |
|
| 343 |
const __m256 vbias01234567 = _mm256_loadu_ps((const float*) w); |
| 344 |
w = (const float*) w + 8; |
| 345 |
vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vinput_scale0, vbias01234567); |
| 346 |
vout1x01234567 = _mm256_fmadd_ps(vout1x01234567, vinput_scale1, vbias01234567); |
| 347 |
vout2x01234567 = _mm256_fmadd_ps(vout2x01234567, vinput_scale2, vbias01234567); |
| 348 |
vout3x01234567 = _mm256_fmadd_ps(vout3x01234567, vinput_scale3, vbias01234567); |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
vout0x01234567 = _mm256_max_ps(vout0x01234567, vmin); |
| 353 |
vout1x01234567 = _mm256_max_ps(vout1x01234567, vmin); |
| 354 |
vout2x01234567 = _mm256_max_ps(vout2x01234567, vmin); |
| 355 |
vout3x01234567 = _mm256_max_ps(vout3x01234567, vmin); |
| 356 |
|
| 357 |
vout0x01234567 = _mm256_min_ps(vout0x01234567, vmax); |
| 358 |
vout1x01234567 = _mm256_min_ps(vout1x01234567, vmax); |
| 359 |
vout2x01234567 = _mm256_min_ps(vout2x01234567, vmax); |
| 360 |
vout3x01234567 = _mm256_min_ps(vout3x01234567, vmax); |
| 361 |
|
| 362 |
if XNN_LIKELY(nc >= 8) { |
| 363 |
_mm256_storeu_ps(c0, vout0x01234567); |
| 364 |
c0 = (float*) ((uintptr_t) c0 + cn_stride); |
| 365 |
_mm256_storeu_ps(c1, vout1x01234567); |
| 366 |
c1 = (float*) ((uintptr_t) c1 + cn_stride); |
| 367 |
_mm256_storeu_ps(c2, vout2x01234567); |
| 368 |
c2 = (float*) ((uintptr_t) c2 + cn_stride); |
| 369 |
_mm256_storeu_ps(c3, vout3x01234567); |
| 370 |
c3 = (float*) ((uintptr_t) c3 + cn_stride); |
| 371 |
|
| 372 |
a0 = (const int8_t*) ((uintptr_t) a0 - kc); |
| 373 |
a1 = (const int8_t*) ((uintptr_t) a1 - kc); |
| 374 |
a2 = (const int8_t*) ((uintptr_t) a2 - kc); |
| 375 |
a3 = (const int8_t*) ((uintptr_t) a3 - kc); |
| 376 |
|
| 377 |
nc -= 8; |
| 378 |
} else { |
| 379 |
__m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567); |
| 380 |
__m128 vout1x0123 = _mm256_castps256_ps128(vout1x01234567); |
| 381 |
__m128 vout2x0123 = _mm256_castps256_ps128(vout2x01234567); |
| 382 |
__m128 vout3x0123 = _mm256_castps256_ps128(vout3x01234567); |
| 383 |
if (nc & 4) { |
| 384 |
_mm_storeu_ps(c0, vout0x0123); |
| 385 |
_mm_storeu_ps(c1, vout1x0123); |
| 386 |
_mm_storeu_ps(c2, vout2x0123); |
| 387 |
_mm_storeu_ps(c3, vout3x0123); |
| 388 |
|
| 389 |
vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1); |
| 390 |
vout1x0123 = _mm256_extractf128_ps(vout1x01234567, 1); |
| 391 |
vout2x0123 = _mm256_extractf128_ps(vout2x01234567, 1); |
| 392 |
vout3x0123 = _mm256_extractf128_ps(vout3x01234567, 1); |
| 393 |
|
| 394 |
c0 += 4; |
| 395 |
c1 += 4; |
| 396 |
c2 += 4; |
| 397 |
c3 += 4; |
| 398 |
} |
| 399 |
if (nc & 2) { |
| 400 |
_mm_storel_pi((__m64*) c0, vout0x0123); |
| 401 |
_mm_storel_pi((__m64*) c1, vout1x0123); |
| 402 |
_mm_storel_pi((__m64*) c2, vout2x0123); |
| 403 |
_mm_storel_pi((__m64*) c3, vout3x0123); |
| 404 |
|
| 405 |
vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123); |
| 406 |
vout1x0123 = _mm_movehl_ps(vout1x0123, vout1x0123); |
| 407 |
vout2x0123 = _mm_movehl_ps(vout2x0123, vout2x0123); |
| 408 |
vout3x0123 = _mm_movehl_ps(vout3x0123, vout3x0123); |
| 409 |
|
| 410 |
c0 += 2; |
| 411 |
c1 += 2; |
| 412 |
c2 += 2; |
| 413 |
c3 += 2; |
| 414 |
} |
| 415 |
if (nc & 1) { |
| 416 |
_mm_store_ss(c0, vout0x0123); |
| 417 |
_mm_store_ss(c1, vout1x0123); |
| 418 |
_mm_store_ss(c2, vout2x0123); |
| 419 |
_mm_store_ss(c3, vout3x0123); |
| 420 |
} |
| 421 |
nc = 0; |
| 422 |
} |
| 423 |
} while (nc != 0); |
| 424 |
} |