xref: /aosp_15_r20/external/XNNPACK/src/f16-vunary/gen/vneg-sse2-x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f16-vunary/sse2.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 <emmintrin.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/unaligned.h>
17 #include <xnnpack/vunary.h>
18 
19 
xnn_f16_vneg_ukernel__sse2_x8(size_t n,const void * input,void * output,const union xnn_f16_neg_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f16_vneg_ukernel__sse2_x8(
21     size_t n,
22     const void* input,
23     void* output,
24     const union xnn_f16_neg_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
25 {
26   assert(n != 0);
27   assert(n % sizeof(uint16_t) == 0);
28   assert(input != NULL);
29   assert(output != NULL);
30 
31   const uint16_t* i = (const uint16_t*) input;
32   uint16_t* o = (uint16_t*) output;
33   const __m128i vsign_mask = _mm_load_si128((const __m128i*) params->sse.sign_mask);
34   for (; n >= 8 * sizeof(uint16_t); n -= 8 * sizeof(uint16_t)) {
35     __m128i vacc = _mm_loadu_si128((const __m128i*) i);
36     i += 8;
37     vacc = _mm_xor_si128(vacc, vsign_mask);
38     _mm_storeu_si128((__m128i*) o, vacc);
39     o += 8;
40   }
41   if XNN_UNLIKELY(n != 0) {
42     __m128i vacc = _mm_loadu_si128((const __m128i*) i);
43     vacc = _mm_xor_si128(vacc, vsign_mask);
44     if (n & (4 * sizeof(uint16_t))) {
45       _mm_storel_epi64((__m128i*) o, vacc);
46       o += 4;
47       vacc = _mm_unpackhi_epi64(vacc, vacc);
48     }
49     if (n & (2 * sizeof(uint16_t))) {
50       unaligned_store_u32(o, (uint32_t) _mm_cvtsi128_si32(vacc));
51       o += 2;
52       vacc = _mm_srli_epi64(vacc, 32);
53     }
54     if (n & (1 * sizeof(uint16_t))) {
55       *o = (uint16_t) _mm_extract_epi16(vacc, 0);
56     }
57   }
58 }
59