Debian Codegraph @

src/f16-spmm/gen/f16-spmm-8x1-minmax-neonfp16arith-x2.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-spmm/neonfp16arith.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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 <arm_neon.h>
13
14 #include "xnnpack/prefetch.h"
15 #include "xnnpack/spmm.h"
16
17
18 void xnn_f16_spmm_minmax_ukernel_8x1__neonfp16arith_x2(
19 size_t mc,
20 size_t nc,
21 const xnn_float16* input,
22 const xnn_float16* weights,
23 const int32_t* widx_dmap,
24 const uint32_t* nidx_nnzmap,
25 xnn_float16* output,
26 size_t output_stride,
27 const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29 assert(mc != 0);
30 assert(mc % sizeof(uint16_t) == 0);
31 assert(nc != 0);
32
33 const uint16_t* i = (const uint16_t*) input;
34 uint16_t* o = (uint16_t*) output;
35
36 #if XNN_ARCH_ARM64
37 const uint16x8x2_t vminmax = vld2q_dup_u16((const uint16_t*) &params->scalar.min);
38 const float16x8_t vmin = vreinterpretq_f16_u16(vminmax.val[0]);
39 const float16x8_t vmax = vreinterpretq_f16_u16(vminmax.val[1]);
40 #else
41 // vld2_dup is to work around aarch32 clang bug with vld1q_dup
42 const uint16x4x2_t vminmax = vld2_dup_u16((const uint16_t*) &params->scalar.min);
43 const float16x8_t vmin = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[0], vminmax.val[0]));
44 const float16x8_t vmax = vreinterpretq_f16_u16(vcombine_u16(vminmax.val[1], vminmax.val[1]));
45 #endif
46
47 size_t output_decrement = output_stride * nc - 8 * sizeof(uint16_t);
48 while XNN_LIKELY(mc >= 8 * sizeof(uint16_t)) {
49 const uint16_t* w = (const uint16_t*) weights;
50 const int32_t* dmap = widx_dmap;
51 const uint32_t* nnzmap = nidx_nnzmap;
52 size_t n = nc;
53 do {
54 uint32_t nnz = *nnzmap++;
55 float16x8_t vacc01234567x0 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
56 float16x8_t vacc01234567x1 = vreinterpretq_f16_u16(vmovq_n_u16(0));
57 for (; nnz >= 2; nnz -= 2) {
58 const intptr_t diff0 = dmap[0];
59 const intptr_t diff1 = dmap[1];
60 dmap += 2;
61 const float16x8_t va01234567x0 = vreinterpretq_f16_u16(vld1q_u16(i));
62 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff0);
63 xnn_prefetch_to_l1(i + 32);
64 const float16x8_t vw0 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
65 xnn_prefetch_to_l1(w + 64);
66 vacc01234567x0 = vfmaq_f16(vacc01234567x0, va01234567x0, vw0);
67 const float16x8_t va01234567x1 = vreinterpretq_f16_u16(vld1q_u16(i));
68 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff1);
69 xnn_prefetch_to_l1(i + 32);
70 const float16x8_t vw1 = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
71 xnn_prefetch_to_l1(w + 64);
72 vacc01234567x1 = vfmaq_f16(vacc01234567x1, va01234567x1, vw1);
73 }
74 float16x8_t vacc01234567 = vacc01234567x0;
75 vacc01234567 = vaddq_f16(vacc01234567, vacc01234567x1);
76 if XNN_LIKELY(nnz != 0) {
77 do {
78 const intptr_t diff = *dmap++;
79 const float16x8_t va01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
80 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
81 xnn_prefetch_to_l1(i + 32);
82 const float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
83 xnn_prefetch_to_l1(w + 64);
84 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vw);
85 } while (--nnz != 0);
86 }
87 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
88 vout01234567 = vmaxq_f16(vout01234567, vmin);
89 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
90 o = (uint16_t*) ((uintptr_t) o + output_stride);
91 } while (--n != 0);
92 o = (uint16_t*) ((uintptr_t) o - output_decrement);
93 i += 8;
94 mc -= 8 * sizeof(uint16_t);
95 }
96 if XNN_UNLIKELY(mc != 0) {
97 output_decrement += 4 * sizeof(uint16_t);
98 if (mc & (4 * sizeof(uint16_t))) {
99 const uint16_t* w = (const uint16_t*) weights;
100 const int32_t* dmap = widx_dmap;
101 const uint32_t* nnzmap = nidx_nnzmap;
102 size_t n = nc;
103 do {
104 uint32_t nnz = *nnzmap++;
105 float16x4_t vacc0123 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
106 if XNN_LIKELY(nnz != 0) {
107 do {
108 const intptr_t diff = *dmap++;
109 const float16x4_t va0123 = vreinterpret_f16_u16(vld1_u16(i));
110 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
111 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
112 vacc0123 = vfma_f16(vacc0123, va0123, vw);
113 } while (--nnz != 0);
114 }
115 float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
116 vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
117 vst1_u16(o, vreinterpret_u16_f16(vout0123));
118 o = (uint16_t*) ((uintptr_t) o + output_stride);
119 } while (--n != 0);
120 o = (uint16_t*) ((uintptr_t) o - output_decrement);
121 i += 4;
122 }
123 output_decrement += 2 * sizeof(uint16_t);
124 if (mc & (2 * sizeof(uint16_t))) {
125 const uint16_t* w = (const uint16_t*) weights;
126 const int32_t* dmap = widx_dmap;
127 const uint32_t* nnzmap = nidx_nnzmap;
128 size_t n = nc;
129 do {
130 uint32_t nnz = *nnzmap++;
131 float16x4_t vacc01 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
132 if XNN_LIKELY(nnz != 0) {
133 do {
134 const intptr_t diff = *dmap++;
135 const float16x4_t va01 = vreinterpret_f16_u32(vld1_dup_u32((const void*) i));
136 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
137 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
138 vacc01 = vfma_f16(vacc01, va01, vw);
139 } while (--nnz != 0);
140 }
141 float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
142 vout01 = vmax_f16(vout01, vget_low_f16(vmin));
143 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vout01), 0);
144 o = (uint16_t*) ((uintptr_t) o + output_stride);
145 } while (--n != 0);
146 o = (uint16_t*) ((uintptr_t) o - output_decrement);
147 i += 2;
148 }
149 output_decrement += 1 * sizeof(uint16_t);
150 if (mc & (1 * sizeof(uint16_t))) {
151 const uint16_t* w = (const uint16_t*) weights;
152 const int32_t* dmap = widx_dmap;
153 const uint32_t* nnzmap = nidx_nnzmap;
154 size_t n = nc;
155 do {
156 uint32_t nnz = *nnzmap++;
157 float16x4_t vacc0 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
158 if XNN_LIKELY(nnz != 0) {
159 do {
160 const intptr_t diff = *dmap++;
161 const float16x4_t va0 = vreinterpret_f16_u16(vld1_dup_u16(i));
162 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
163 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
164 vacc0 = vfma_f16(vacc0, va0, vw);
165 } while (--nnz != 0);
166 }
167 float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
168 vout0 = vmax_f16(vout0, vget_low_f16(vmin));
169 vst1_lane_u16(o, vreinterpret_u16_f16(vout0), 0);
170 o = (uint16_t*) ((uintptr_t) o + output_stride);
171 } while (--n != 0);
172 o = (uint16_t*) ((uintptr_t) o - output_decrement);
173 i += 1;
174 }
175 }
176 }