• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_gemm_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 struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f16_gemm_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 struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32   assert(mr != 0);
33   assert(mr <= 1);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(kc % sizeof(__fp16) == 0);
37   assert(a != NULL);
38   assert(w != NULL);
39   assert(c != NULL);
40 
41   const __fp16* a0 = (const __fp16*) a;
42   __fp16* c0 = (__fp16*) c;
43 
44   do {
45     float16x8_t vacc0x01234567 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
46 
47     size_t k = kc;
48     while (k >= 4 * sizeof(__fp16)) {
49       const float16x4_t va0 = vld1_f16(a0); a0 += 4;
50 
51       const float16x8_t vb01234567c0 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
52 
53       #if XNN_ARCH_ARM64
54         vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c0, va0, 0);
55       #else
56         const float16x8_t va0c0 = vdupq_lane_f16(va0, 0);
57 
58         vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c0, vb01234567c0);
59       #endif
60       const float16x8_t vb01234567c1 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
61 
62       #if XNN_ARCH_ARM64
63         vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c1, va0, 1);
64       #else
65         const float16x8_t va0c1 = vdupq_lane_f16(va0, 1);
66 
67         vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c1, vb01234567c1);
68       #endif
69       const float16x8_t vb01234567c2 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
70 
71       #if XNN_ARCH_ARM64
72         vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c2, va0, 2);
73       #else
74         const float16x8_t va0c2 = vdupq_lane_f16(va0, 2);
75 
76         vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c2, vb01234567c2);
77       #endif
78       const float16x8_t vb01234567c3 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
79 
80       #if XNN_ARCH_ARM64
81         vacc0x01234567 = vfmaq_lane_f16(vacc0x01234567, vb01234567c3, va0, 3);
82       #else
83         const float16x8_t va0c3 = vdupq_lane_f16(va0, 3);
84 
85         vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0c3, vb01234567c3);
86       #endif
87 
88       k -= 4 * sizeof(__fp16);
89     }
90     if XNN_UNLIKELY(k != 0) {
91       do {
92         const float16x8_t va0 = vld1q_dup_f16(a0); a0 += 1;
93 
94         const float16x8_t vb01234567 = vld1q_f16(w); w = (const void*) ((uintptr_t) w + sizeof(float16x8_t));
95 
96         vacc0x01234567 = vfmaq_f16(vacc0x01234567, va0, vb01234567);
97 
98         k -= sizeof(__fp16);
99       } while (k != 0);
100     }
101 
102     const float16x8_t vscale = vld1q_dup_f16((const __fp16*) &params->scale);
103     vacc0x01234567 = vmulq_f16(vacc0x01234567, vscale);
104 
105     const float16x8_t vmax = vld1q_dup_f16((const __fp16*) &params->max);
106     vacc0x01234567 = vminq_f16(vacc0x01234567, vmax);
107 
108     const float16x8_t vmin = vld1q_dup_f16((const __fp16*) &params->min);
109     vacc0x01234567 = vmaxq_f16(vacc0x01234567, vmin);
110 
111     if XNN_LIKELY(nc >= 8) {
112       vst1q_f16(c0, vacc0x01234567);
113       c0 = (__fp16*) ((uintptr_t) c0 + cn_stride);
114 
115       a0 = (const __fp16*) ((uintptr_t) a0 - kc);
116 
117       nc -= 8;
118     } else {
119       float16x4_t vacc0x0123 = vget_low_f16(vacc0x01234567);
120       if (nc & 4) {
121         vst1_f16(c0, vacc0x0123); c0 += 4;
122 
123         vacc0x0123 = vget_high_f16(vacc0x01234567);
124       }
125       if (nc & 2) {
126         vst1_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpret_u32_f16(vacc0x0123), 0); c0 += 2;
127 
128         vacc0x0123 = vext_f16(vacc0x0123, vacc0x0123, 2);
129       }
130       if (nc & 1) {
131         vst1_lane_f16(c0, vacc0x0123, 0);
132       }
133 
134       nc = 0;
135     }
136   } while (nc != 0);
137 }
138