Coverage Report

Created: 2025-09-27 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xnnpack/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x4c8-minmax-fp32-avx-ld128.c
Line
Count
Source
1
// clang-format off
2
// Auto-generated file. Do not edit!
3
//   Template: src/qs8-igemm/MRx4c8-sse.c.in
4
//   Generator: tools/xngen
5
//
6
// Copyright 2020 Google LLC
7
//
8
// This source code is licensed under the BSD-style license found in the
9
// LICENSE file in the root directory of this source tree.
10
11
#include <assert.h>
12
#include <stddef.h>
13
#include <stdint.h>
14
15
#ifdef _MSC_VER
16
  #include <intrin.h>
17
#else
18
  #include <x86intrin.h>
19
#endif
20
21
#include "src/xnnpack/common.h"
22
#include "src/xnnpack/igemm.h"
23
#include "src/xnnpack/math.h"
24
#include "src/xnnpack/microparams.h"
25
#include "src/xnnpack/unaligned.h"
26
27
28
void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x4c8__avx_ld128(
29
    size_t mr,
30
    size_t nc,
31
    size_t kc,
32
    size_t ks,
33
    const int8_t** restrict a,
34
    const void* restrict w,
35
    int8_t* restrict c,
36
    size_t cm_stride,
37
    size_t cn_stride,
38
    size_t a_offset,
39
    const int8_t* zero,
40
    const union xnn_qs8_qc8w_conv_minmax_params* restrict params) XNN_OOB_READS
41
0
{
42
0
  assert(mr != 0);
43
0
  assert(mr <= 2);
44
0
  assert(nc != 0);
45
0
  assert(kc != 0);
46
0
  assert(ks != 0);
47
0
  assert(ks % (2 * sizeof(void*)) == 0);
48
0
  assert(a_offset % sizeof(int8_t) == 0);
49
0
  assert(a != NULL);
50
0
  assert(w != NULL);
51
0
  assert(c != NULL);
52
53
0
  kc = round_up_po2(kc, 8 * sizeof(int8_t));
54
0
  int8_t* c0 = c;
55
0
  int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
56
0
  if XNN_UNPREDICTABLE(mr != 2) {
57
0
    c1 = c0;
58
0
  }
59
60
61
0
  const __m128 voutput_max_less_zero_point = _mm_set1_ps((int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point);
62
0
  const __m128i voutput_zero_point = _mm_set1_epi16(params->fp32_scalar.output_zero_point);
63
0
  const __m128i voutput_min = _mm_set1_epi8(params->fp32_scalar.output_min);
64
0
  XNN_FORCE_REALIZATION(voutput_max_less_zero_point);
65
0
  XNN_FORCE_REALIZATION(voutput_zero_point);
66
0
  XNN_FORCE_REALIZATION(voutput_min);
67
68
69
0
  do {
70
0
    __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]);
71
0
    __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]);
72
0
    __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]);
73
0
    __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]);
74
0
    __m128i vacc1x0 = vacc0x0;
75
0
    __m128i vacc1x1 = vacc0x1;
76
0
    __m128i vacc1x2 = vacc0x2;
77
0
    __m128i vacc1x3 = vacc0x3;
78
0
    w = (const int32_t*) w + 4;
79
80
0
    size_t p = ks;
81
0
    do {
82
0
      const int8_t* restrict a0 = a[0];
83
0
      if XNN_UNPREDICTABLE(a0 != zero) {
84
0
        a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
85
0
      }
86
0
      const int8_t* restrict a1 = a[1];
87
0
      if XNN_UNPREDICTABLE(a1 != zero) {
88
0
        a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
89
0
      }
90
0
      a += 2;
91
92
0
      size_t k = 0;
93
0
      while (k < kc) {
94
0
        const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0);
95
0
        const __m128i vxa0 = _mm_cvtepi8_epi16(va0);
96
0
        a0 += 8;
97
0
        const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1);
98
0
        const __m128i vxa1 = _mm_cvtepi8_epi16(va1);
99
0
        a1 += 8;
100
101
0
        const __m128i vb01 = _mm_load_si128((const __m128i*) w);
102
0
        const __m128i vxb0 = _mm_cvtepi8_epi16(vb01);
103
0
        const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8);
104
105
0
        vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0));
106
0
        vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1));
107
0
        vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0));
108
0
        vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1));
109
0
        const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16));
110
0
        const __m128i vxb2 = _mm_cvtepi8_epi16(vb23);
111
0
        const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8);
112
113
0
        vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2));
114
0
        vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3));
115
0
        vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2));
116
0
        vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3));
117
118
0
        w = (const void*) ((const int8_t*) w + 32);
119
0
        k += 8 * sizeof(int8_t);
120
0
      }
121
0
      p -= 2 * sizeof(void*);
122
0
    } while (p != 0);
123
124
0
    const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1);
125
0
    const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3);
126
0
    const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1);
127
0
    const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3);
128
129
0
    __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23);
130
0
    __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23);
131
132
0
    __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123);
133
0
    __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123);
134
135
0
    const __m128 vscale0123 = _mm_load_ps((const float*) w);
136
0
    w = (const float*) w + 4;
137
0
    vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123);
138
0
    vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123);
139
140
0
    vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point);
141
0
    vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point);
142
143
0
    vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123);
144
0
    vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123);
145
146
0
    __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point);
147
148
149
0
    __m128i vout = _mm_packs_epi16(vacc01x0123, vacc01x0123);
150
151
0
    vout = _mm_max_epi8(vout, voutput_min);
152
153
0
    if (nc >= 4) {
154
0
      unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1));
155
0
      c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
156
0
      unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout));
157
0
      c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
158
159
0
      a = (const int8_t**restrict) ((uintptr_t) a - ks);
160
161
0
      nc -= 4;
162
0
    } else {
163
0
      if (nc & 2) {
164
0
        unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2));
165
0
        c1 += 2;
166
0
        unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0));
167
0
        c0 += 2;
168
0
        vout = _mm_srli_epi32(vout, 16);
169
0
      }
170
0
      if (nc & 1) {
171
0
        *c1 = (int8_t) _mm_extract_epi8(vout, 4);
172
0
        *c0 = (int8_t) _mm_extract_epi8(vout, 0);
173
0
      }
174
175
0
      nc = 0;
176
0
    }
177
0
  } while (nc != 0);
178
0
}