// Copyright 2019 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. $assert CHANNEL_TILE % 4 == 0 $assert CHANNEL_TILE >= 4 $assert ROW_TILE >= 1 $ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" #include #include #include #include void xnn_f32_vmulcaddc_minmax_ukernel_c${CHANNEL_TILE}__${"neonfma" if FMA else "neon"}_${ROW_TILE}x( size_t rows, size_t channels, const float*restrict input, size_t input_stride, const float*restrict weights, float*restrict output, size_t output_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN { assert(rows != 0); assert(channels != 0); assert(channels % sizeof(float) == 0); const float* i0 = input; float* o0 = output; $for M in range(1, ROW_TILE): const float* i${M} = (const float*) ((uintptr_t) i${M-1} + input_stride); float* o${M} = (float*) ((uintptr_t) o${M-1} + output_stride); $if M % 2 == 0: if XNN_UNPREDICTABLE(rows <= ${M}) { i${M} = i${M-1}; o${M} = o${M-1}; } $else: if XNN_UNPREDICTABLE(rows < ${M+1}) { i${M} = i${M-1}; o${M} = o${M-1}; } const size_t input_increment = input_stride * ${ROW_TILE} - channels; const size_t output_increment = output_stride * ${ROW_TILE} - channels; const float32x4_t vmin = vld1q_dup_f32(¶ms->scalar.min); const float32x4_t vmax = vld1q_dup_f32(¶ms->scalar.max); do { const float* w = weights; size_t c = channels; for (; c >= ${CHANNEL_TILE} * sizeof(float); c -= ${CHANNEL_TILE} * sizeof(float)) { $for C in range(0, CHANNEL_TILE, 4): const float32x4_t vscale${ABC[C:C+4]} = vld1q_f32(w); w += 4; $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): float32x4_t vacc${M}x${ABC[C:C+4]} = vld1q_f32(i${M}); i${M} += 4; $if not FMA: $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vacc${M}x${ABC[C:C+4]} = vmulq_f32(vacc${M}x${ABC[C:C+4]}, vscale${ABC[C:C+4]}); $for C in range(0, CHANNEL_TILE, 4): const float32x4_t vbias${ABC[C:C+4]} = vld1q_f32(w); w += 4; $if not FMA: $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vacc${M}x${ABC[C:C+4]} = vaddq_f32(vacc${M}x${ABC[C:C+4]}, vbias${ABC[C:C+4]}); $else: $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vacc${M}x${ABC[C:C+4]} = vfmaq_f32(vbias${ABC[C:C+4]}, vscale${ABC[C:C+4]}, vacc${M}x${ABC[C:C+4]}); $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vacc${M}x${ABC[C:C+4]} = vmaxq_f32(vacc${M}x${ABC[C:C+4]}, vmin); $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vacc${M}x${ABC[C:C+4]} = vminq_f32(vacc${M}x${ABC[C:C+4]}, vmax); $for M in range(ROW_TILE): $for C in range(0, CHANNEL_TILE, 4): vst1q_f32(o${M}, vacc${M}x${ABC[C:C+4]}); o${M} += 4; } $if CHANNEL_TILE > 4: for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) { const float32x4_t vscale0123 = vld1q_f32(w); w += 4; $for M in range(ROW_TILE): float32x4_t vacc${M}x0123 = vld1q_f32(i${M}); i${M} += 4; $if not FMA: $for M in range(ROW_TILE): vacc${M}x0123 = vmulq_f32(vacc${M}x0123, vscale0123); const float32x4_t vbias0123 = vld1q_f32(w + ${CHANNEL_TILE - 4}); $if not FMA: $for M in range(ROW_TILE): vacc${M}x0123 = vaddq_f32(vacc${M}x0123, vbias0123); $else: $for M in range(ROW_TILE): vacc${M}x0123 = vfmaq_f32(vbias0123, vscale0123, vacc${M}x0123); $for M in range(ROW_TILE): vacc${M}x0123 = vmaxq_f32(vacc${M}x0123, vmin); $for M in range(ROW_TILE): vacc${M}x0123 = vminq_f32(vacc${M}x0123, vmax); $for M in range(ROW_TILE): vst1q_f32(o${M}, vacc${M}x0123); o${M} += 4; } if XNN_UNLIKELY(c != 0) { const float32x4_t vscale0123 = vld1q_f32(w); $for M in range(ROW_TILE): float32x4_t vacc${M}x0123 = vld1q_f32(i${M}); i${M} = (const float*) ((uintptr_t) i${M} + c); $if not FMA: $for M in range(ROW_TILE): vacc${M}x0123 = vmulq_f32(vacc${M}x0123, vscale0123); const float32x4_t vbias0123 = vld1q_f32(w + ${CHANNEL_TILE}); $if not FMA: $for M in range(ROW_TILE): vacc${M}x0123 = vaddq_f32(vacc${M}x0123, vbias0123); $else: $for M in range(ROW_TILE): vacc${M}x0123 = vfmaq_f32(vbias0123, vscale0123, vacc${M}x0123); $for M in range(ROW_TILE): vacc${M}x0123 = vmaxq_f32(vacc${M}x0123, vmin); $for M in range(ROW_TILE): vacc${M}x0123 = vminq_f32(vacc${M}x0123, vmax); $for M in range(ROW_TILE): float32x2_t vacc${M}x01 = vget_low_f32(vacc${M}x0123); if (c & (2 * sizeof(float))) { $for M in range(ROW_TILE): vst1_f32(o${M}, vacc${M}x01); o${M} += 2; $for M in range(ROW_TILE): vacc${M}x01 = vget_high_f32(vacc${M}x0123); } if (c & (1 * sizeof(float))) { $for M in range(ROW_TILE): vst1_lane_f32(o${M}, vacc${M}x01, 0); o${M} += 1; } } $for M in range(ROW_TILE): i${M} = (const float*) ((uintptr_t) i${M} + input_increment); o${M} = (float*) ((uintptr_t) o${M} + output_increment); $if M % 2 == 1: if XNN_UNPREDICTABLE(rows < ${ROW_TILE + M + 1}) { i${M} = i${M-1}; o${M} = o${M-1}; } $elif M != 0: if XNN_UNPREDICTABLE(rows <= ${ROW_TILE + M}) { i${M} = i${M-1}; o${M} = o${M-1}; } rows = doz(rows, ${ROW_TILE}); } while (rows != 0); }