1// Copyright 2022 Google LLC 2// 3// This source code is licensed under the BSD-style license found in the 4// LICENSE file in the root directory of this source tree. 5 6$assert BATCH_TILE % 4 == 0 7$assert BATCH_TILE >= 4 8$SIMD_TILE = BATCH_TILE // 4 9#include <assert.h> 10#include <stddef.h> 11#include <stdint.h> 12 13#include <arm_neon.h> 14 15#include <xnnpack/vsquareabs.h> 16 17 18void xnn_cs16_vsquareabs_ukernel__neon_mlal_ld128_x${BATCH_TILE}( 19 size_t batch, 20 const int16_t* input, 21 uint32_t* output) { 22 23 assert(batch != 0); 24 assert(input != NULL); 25 assert(output != NULL); 26 27 $if BATCH_TILE > 4: 28 for (; batch >= ${BATCH_TILE}; batch -= ${BATCH_TILE}) { 29 $for N in range(SIMD_TILE): 30 const int16x4x2_t vi${N} = vld2_s16(input); input += 8; 31 32 $for N in range(SIMD_TILE): 33 int32x4_t vacc${N} = vmull_s16(vi${N}.val[0], vi${N}.val[0]); 34 vacc${N} = vmlal_s16(vacc${N}, vi${N}.val[1], vi${N}.val[1]); 35 36 $for N in range(SIMD_TILE): 37 vst1q_u32(output, vreinterpretq_u32_s32(vacc${N})); output += 4; 38 } 39 40 // Remainder of full vectors 41 for (; batch >= 4; batch -= 4) { 42 const int16x4x2_t vi = vld2_s16(input); input += 8; 43 44 int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]); 45 46 vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]); 47 48 vst1q_u32(output, vreinterpretq_u32_s32(vacc)); output += 4; 49 } 50 51 // Remainder of 1 to 3 elements 52 if XNN_UNLIKELY(batch != 0) { 53 const int16x4x2_t vi = vld2_s16(input); 54 55 int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]); 56 vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]); 57 58 uint32x2_t vacc_lo = vreinterpret_u32_s32(vget_low_s32(vacc)); 59 if (batch & 2) { 60 vst1_u32(output, vacc_lo); output += 2; 61 vacc_lo = vreinterpret_u32_s32(vget_high_s32(vacc)); 62 } 63 if (batch & 1) { 64 vst1_lane_u32(output, vacc_lo, 0); 65 } 66 } 67} 68