• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/s8-ibilinear/wasmsimd-dot16x2.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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 <wasm_simd128.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/ibilinear.h>
16 
17 
xnn_s8_ibilinear_ukernel__wasmsimd_dot16x2_c8(size_t output_pixels,size_t channels,const int8_t ** restrict input,size_t input_offset,const int16_t * restrict weights,int8_t * restrict output,size_t output_increment)18 void xnn_s8_ibilinear_ukernel__wasmsimd_dot16x2_c8(
19     size_t output_pixels,
20     size_t channels,
21     const int8_t**restrict input,
22     size_t input_offset,
23     const int16_t*restrict weights,
24     int8_t*restrict output,
25     size_t output_increment) XNN_OOB_READS
26 {
27   assert(output_pixels != 0);
28   assert(channels != 0);
29 
30   do {
31     const int8_t* i0 = (const int8_t*) ((uintptr_t) input[0] + input_offset);
32     const int8_t* i1 = (const int8_t*) ((uintptr_t) input[1] + input_offset);
33     const int8_t* i2 = (const int8_t*) ((uintptr_t) input[2] + input_offset);
34     const int8_t* i3 = (const int8_t*) ((uintptr_t) input[3] + input_offset);
35     input += 4;
36 
37     const v128_t valphah =
38       wasm_i16x8_add(
39         wasm_v128_xor(
40           wasm_v128_load16_splat(weights),
41           wasm_i32x4_const_splat(0xFFFF0000)),
42         wasm_i32x4_const_splat(0x08010000));
43     const v128_t valphav = wasm_i32x4_extend_low_i16x8(wasm_v128_load16_splat(weights + 1));
44     weights += 2;
45 
46     const v128_t vrounding = wasm_i32x4_const_splat(0x00200000);
47 
48     size_t c = channels;
49     for (; c >= 8 * sizeof(int8_t); c -= 8 * sizeof(int8_t)) {
50       const v128_t vtl01234567 = wasm_i16x8_load8x8(i0);
51       i0 += 8;
52       const v128_t vtr01234567 = wasm_i16x8_load8x8(i1);
53       i1 += 8;
54       const v128_t vbl01234567 = wasm_i16x8_load8x8(i2);
55       i2 += 8;
56       const v128_t vbr01234567 = wasm_i16x8_load8x8(i3);
57       i3 += 8;
58 
59       const v128_t vdr01234567 = wasm_i16x8_sub(vbr01234567, vtr01234567);
60       const v128_t vt0123 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vtr01234567, vtl01234567, 0, 8, 1, 9, 2, 10, 3, 11), valphah);
61       const v128_t vdl01234567 = wasm_i16x8_sub(vbl01234567, vtl01234567);
62       const v128_t vt4567 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vtr01234567, vtl01234567, 4, 12, 5, 13, 6, 14, 7, 15), valphah);
63 
64       const v128_t vd0123 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vdr01234567, vdl01234567, 0, 8, 1, 9, 2, 10, 3, 11), valphah);
65       const v128_t vd4567 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vdr01234567, vdl01234567, 4, 12, 5, 13, 6, 14, 7, 15), valphah);
66 
67       v128_t vacc0123 = wasm_i32x4_mul(vd0123, valphav);
68       v128_t vacc4567 = wasm_i32x4_mul(vd4567, valphav);
69 
70       vacc0123 = wasm_i32x4_add(wasm_i32x4_shl(vt0123, 11), vacc0123);
71       vacc4567 = wasm_i32x4_add(wasm_i32x4_shl(vt4567, 11), vacc4567);
72 
73       vacc0123 = wasm_i32x4_shr(wasm_i16x8_add(vacc0123, vrounding), 22);
74       vacc4567 = wasm_i32x4_shr(wasm_i16x8_add(vacc4567, vrounding), 22);
75 
76       const v128_t vacc01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
77 
78       const v128_t vo01234567 = wasm_i8x16_narrow_i16x8(vacc01234567, vacc01234567);
79 
80       *((double*) output) = wasm_f64x2_extract_lane(vo01234567, 0);
81       output += 8;
82     }
83     if XNN_UNLIKELY(c != 0) {
84       const v128_t vtl01234567 = wasm_i16x8_load8x8(i0);
85       const v128_t vtr01234567 = wasm_i16x8_load8x8(i1);
86       const v128_t vbl01234567 = wasm_i16x8_load8x8(i2);
87       const v128_t vbr01234567 = wasm_i16x8_load8x8(i3);
88 
89       const v128_t vdr01234567 = wasm_i16x8_sub(vbr01234567, vtr01234567);
90       const v128_t vt0123 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vtr01234567, vtl01234567, 0, 8, 1, 9, 2, 10, 3, 11), valphah);
91       const v128_t vdl01234567 = wasm_i16x8_sub(vbl01234567, vtl01234567);
92       const v128_t vt4567 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vtr01234567, vtl01234567, 4, 12, 5, 13, 6, 14, 7, 15), valphah);
93 
94       const v128_t vd0123 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vdr01234567, vdl01234567, 0, 8, 1, 9, 2, 10, 3, 11), valphah);
95       const v128_t vd4567 = wasm_i32x4_dot_i16x8(wasm_v16x8_shuffle(vdr01234567, vdl01234567, 4, 12, 5, 13, 6, 14, 7, 15), valphah);
96 
97       v128_t vacc0123 = wasm_i32x4_mul(vd0123, valphav);
98       v128_t vacc4567 = wasm_i32x4_mul(vd4567, valphav);
99 
100       vacc0123 = wasm_i32x4_add(wasm_i32x4_shl(vt0123, 11), vacc0123);
101       vacc4567 = wasm_i32x4_add(wasm_i32x4_shl(vt4567, 11), vacc4567);
102 
103       vacc0123 = wasm_i32x4_shr(wasm_i16x8_add(vacc0123, vrounding), 22);
104       vacc4567 = wasm_i32x4_shr(wasm_i16x8_add(vacc4567, vrounding), 22);
105 
106       const v128_t vacc01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567);
107 
108       v128_t vo01234567 = wasm_i8x16_narrow_i16x8(vacc01234567, vacc01234567);
109 
110       if (c & (4 * sizeof(int8_t))) {
111         *((float*) output) = wasm_f32x4_extract_lane(vo01234567, 0);
112         output += 4;
113         vo01234567 = wasm_u64x2_shr(vo01234567, 32);
114       }
115       uint32_t vo0123 = (uint32_t) wasm_i32x4_extract_lane(vo01234567, 0);
116       if (c & (2 * sizeof(int8_t))) {
117         *((uint16_t*) output) = (uint16_t) vo0123;
118         output += 2;
119         vo0123 >>= 16;
120       }
121       if (c & (1 * sizeof(int8_t))) {
122         *output++ = (uint8_t) vo0123;
123       }
124     }
125 
126     output = (int8_t*) ((uintptr_t) output + output_increment);
127   } while (--output_pixels != 0);
128 }
129