1 // Auto-generated file. Do not edit!
2 // Template: src/f16-gemm/neonfp16arith-ld64.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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include <xnnpack/common.h>
16
17 #include <xnnpack/gemm.h>
18
19
xnn_f16_gemminc_minmax_ukernel_1x8__neonfp16arith_ld64(size_t mr,size_t nc,size_t kc,const void * restrict a,size_t a_stride,const void * restrict w,void * restrict c,size_t cm_stride,size_t cn_stride,const void * restrict acc,const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f16_gemminc_minmax_ukernel_1x8__neonfp16arith_ld64(
21 size_t mr,
22 size_t nc,
23 size_t kc,
24 const void* restrict a,
25 size_t a_stride,
26 const void* restrict w,
27 void* restrict c,
28 size_t cm_stride,
29 size_t cn_stride,
30 const void*restrict acc,
31 const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS(1)])
32 {
33 assert(mr != 0);
34 assert(mr <= 1);
35 assert(nc != 0);
36 assert(kc != 0);
37 assert(kc % sizeof(__fp16) == 0);
38 assert(a != NULL);
39 assert(w != NULL);
40 assert(c != NULL);
41 assert(acc != NULL);
42
43 const __fp16* a0 = (const __fp16*) a;
44 __fp16* c0 = (__fp16*) c;
45
46 do {
47 float16x8_t vacc0x01234567 = vld1q_f16(acc); acc = (const void*) ((uintptr_t) acc + sizeof(float16x8_t));
48
49 size_t k = kc;
50 while (k >= 4 * sizeof(__fp16)) {
51 const float16x4_t va0 = vld1_f16(a0); a0 += 4;
52
53 const float16x8_t vb01234567c0 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
54
55 #if XNN_ARCH_ARM64
56 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c0, va0, 0);
57 #else
58 const float16x8_t va0c0 = vdupq_lane_f16(va0, 0);
59
60 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c0, vb01234567c0);
61 #endif
62 const float16x8_t vb01234567c1 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
63
64 #if XNN_ARCH_ARM64
65 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c1, va0, 1);
66 #else
67 const float16x8_t va0c1 = vdupq_lane_f16(va0, 1);
68
69 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c1, vb01234567c1);
70 #endif
71 const float16x8_t vb01234567c2 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
72
73 #if XNN_ARCH_ARM64
74 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c2, va0, 2);
75 #else
76 const float16x8_t va0c2 = vdupq_lane_f16(va0, 2);
77
78 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c2, vb01234567c2);
79 #endif
80 const float16x8_t vb01234567c3 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
81
82 #if XNN_ARCH_ARM64
83 vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c3, va0, 3);
84 #else
85 const float16x8_t va0c3 = vdupq_lane_f16(va0, 3);
86
87 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c3, vb01234567c3);
88 #endif
89
90 k -= 4 * sizeof(__fp16);
91 }
92 if XNN_UNLIKELY(k != 0) {
93 do {
94 const float16x8_t va0 = vld1q_dup_f16(a0); a0 += 1;
95
96 const float16x8_t vb01234567 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
97
98 vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0, vb01234567);
99
100 k -= sizeof(__fp16);
101 } while (k != 0);
102 }
103
104 const float16x8_t vscale = vld1q_dup_f16((const __fp16*) ¶ms->scale);
105 vacc0x01234567 = vmulq_f16(vacc0x01234567, vscale);
106
107 const float16x8_t vmax = vld1q_dup_f16((const __fp16*) ¶ms->max);
108 vacc0x01234567 = vminq_f16(vacc0x01234567, vmax);
109
110 const float16x8_t vmin = vld1q_dup_f16((const __fp16*) ¶ms->min);
111 vacc0x01234567 = vmaxq_f16(vacc0x01234567, vmin);
112
113 if XNN_LIKELY(nc >= 8) {
114 vst1q_f16(c0, vacc0x01234567);
115 c0 = (__fp16*) ((uintptr_t) c0 + cn_stride);
116
117 a0 = (const __fp16*) ((uintptr_t) a0 - kc);
118
119 nc -= 8;
120 } else {
121 float16x4_t vacc0x0123 = vget_low_f16(vacc0x01234567);
122 if (nc & 4) {
123 vst1_f16(c0, vacc0x0123); c0 += 4;
124
125 vacc0x0123 = vget_high_f16(vacc0x01234567);
126 }
127 if (nc & 2) {
128 vst1_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpret_u32_f16(vacc0x0123), 0); c0 += 2;
129
130 vacc0x0123 = vext_f16(vacc0x0123, vacc0x0123, 2);
131 }
132 if (nc & 1) {
133 vst1_lane_f16(c0, vacc0x0123, 0);
134 }
135
136 nc = 0;
137 }
138 } while (nc != 0);
139 }
140