Debian Codegraph @

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

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-spmm/neonfp16arith-pipelined.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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_pipelined(
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 float16x8_t vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
53 intptr_t diff = *dmap++;
54 float16x8_t vi01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
55 size_t n = nc;
56 do {
57 uint32_t nnz = *nnzmap++;
58 float16x8_t vacc01234567 = vw;
59 vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
60 if XNN_LIKELY(nnz != 0) {
61 do {
62 vacc01234567 = vfmaq_f16(vacc01234567, vi01234567, vw);
63 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
64 xnn_prefetch_to_l1(i + 32);
65 diff = *dmap++;
66 vw = vreinterpretq_f16_u16(vld1q_dup_u16(w)); w += 1;
67 xnn_prefetch_to_l1(w + 64);
68 vi01234567 = vreinterpretq_f16_u16(vld1q_u16(i));
69 } while (--nnz != 0);
70 }
71 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
72 vout01234567 = vmaxq_f16(vout01234567, vmin);
73 vst1q_u16(o, vreinterpretq_u16_f16(vout01234567));
74 o = (uint16_t*) ((uintptr_t) o + output_stride);
75 } while (--n != 0);
76 o = (uint16_t*) ((uintptr_t) o - output_decrement);
77 i += 8;
78 mc -= 8 * sizeof(uint16_t);
79 }
80 if XNN_UNLIKELY(mc != 0) {
81 output_decrement += 4 * sizeof(uint16_t);
82 if (mc & (4 * sizeof(uint16_t))) {
83 const uint16_t* w = (const uint16_t*) weights;
84 const int32_t* dmap = widx_dmap;
85 const uint32_t* nnzmap = nidx_nnzmap;
86 size_t n = nc;
87 do {
88 uint32_t nnz = *nnzmap++;
89 float16x4_t vacc0123 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
90 if XNN_LIKELY(nnz != 0) {
91 do {
92 const intptr_t diff = *dmap++;
93 const float16x4_t va0123 = vreinterpret_f16_u16(vld1_u16(i));
94 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
95 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
96 vacc0123 = vfma_f16(vacc0123, va0123, vw);
97 } while (--nnz != 0);
98 }
99 float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
100 vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
101 vst1_u16(o, vreinterpret_u16_f16(vout0123));
102 o = (uint16_t*) ((uintptr_t) o + output_stride);
103 } while (--n != 0);
104 o = (uint16_t*) ((uintptr_t) o - output_decrement);
105 i += 4;
106 }
107 output_decrement += 2 * sizeof(uint16_t);
108 if (mc & (2 * sizeof(uint16_t))) {
109 const uint16_t* w = (const uint16_t*) weights;
110 const int32_t* dmap = widx_dmap;
111 const uint32_t* nnzmap = nidx_nnzmap;
112 size_t n = nc;
113 do {
114 uint32_t nnz = *nnzmap++;
115 float16x4_t vacc01 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
116 if XNN_LIKELY(nnz != 0) {
117 do {
118 const intptr_t diff = *dmap++;
119 const float16x4_t va01 = vreinterpret_f16_u32(vld1_dup_u32((const void*) i));
120 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
121 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
122 vacc01 = vfma_f16(vacc01, va01, vw);
123 } while (--nnz != 0);
124 }
125 float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
126 vout01 = vmax_f16(vout01, vget_low_f16(vmin));
127 vst1_lane_u32((void*) o, vreinterpret_u32_f16(vout01), 0);
128 o = (uint16_t*) ((uintptr_t) o + output_stride);
129 } while (--n != 0);
130 o = (uint16_t*) ((uintptr_t) o - output_decrement);
131 i += 2;
132 }
133 output_decrement += 1 * sizeof(uint16_t);
134 if (mc & (1 * sizeof(uint16_t))) {
135 const uint16_t* w = (const uint16_t*) weights;
136 const int32_t* dmap = widx_dmap;
137 const uint32_t* nnzmap = nidx_nnzmap;
138 size_t n = nc;
139 do {
140 uint32_t nnz = *nnzmap++;
141 float16x4_t vacc0 = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
142 if XNN_LIKELY(nnz != 0) {
143 do {
144 const intptr_t diff = *dmap++;
145 const float16x4_t va0 = vreinterpret_f16_u16(vld1_dup_u16(i));
146 i = (const uint16_t*) ((uintptr_t) i + (uintptr_t) diff);
147 const float16x4_t vw = vreinterpret_f16_u16(vld1_dup_u16(w)); w += 1;
148 vacc0 = vfma_f16(vacc0, va0, vw);
149 } while (--nnz != 0);
150 }
151 float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
152 vout0 = vmax_f16(vout0, vget_low_f16(vmin));
153 vst1_lane_u16(o, vreinterpret_u16_f16(vout0), 0);
154 o = (uint16_t*) ((uintptr_t) o + output_stride);
155 } while (--n != 0);
156 o = (uint16_t*) ((uintptr_t) o - output_decrement);
157 i += 1;
158 }
159 }
160 }