• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 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 CHANNEL_TILE >= 1
7$assert PIXEL_TILE == 1
8$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9#include <assert.h>
10
11#include <xnnpack/ibilinear.h>
12
13
14void xnn_f32_ibilinear_ukernel__scalar_c${CHANNEL_TILE}${"" if PIXEL_TILE == 1 else "x%d" % PIXEL_TILE}(
15    size_t output_pixels,
16    size_t channels,
17    const float**restrict input,
18    size_t input_offset,
19    const float*restrict weights,
20    float*restrict output,
21    size_t output_increment)
22{
23  assert(output_pixels != 0);
24  assert(channels != 0);
25  assert(channels % sizeof(float) == 0);
26
27  do {
28    const float* i0 = (const float*) ((uintptr_t) input[0] + input_offset);
29    const float* i1 = (const float*) ((uintptr_t) input[1] + input_offset);
30    const float* i2 = (const float*) ((uintptr_t) input[2] + input_offset);
31    const float* i3 = (const float*) ((uintptr_t) input[3] + input_offset);
32    input += 4;
33
34    const float valphah = weights[0];
35    const float valphav = weights[1];
36    weights += 2;
37
38    size_t c = channels;
39    $if CHANNEL_TILE > 1:
40      for (; c >= ${CHANNEL_TILE} * sizeof(float); c -= ${CHANNEL_TILE} * sizeof(float)) {
41        $for C in range(CHANNEL_TILE):
42          const float vtl${ABC[C]} = i0[${C}];
43          const float vtr${ABC[C]} = i1[${C}];
44          const float vbl${ABC[C]} = i2[${C}];
45          const float vbr${ABC[C]} = i3[${C}];
46        i0 += ${CHANNEL_TILE};
47        i1 += ${CHANNEL_TILE};
48        i2 += ${CHANNEL_TILE};
49        i3 += ${CHANNEL_TILE};
50
51        $for C in range(CHANNEL_TILE):
52          const float vtd${ABC[C]} = vtr${ABC[C]} - vtl${ABC[C]};
53          const float vbd${ABC[C]} = vbr${ABC[C]} - vbl${ABC[C]};
54
55        $for C in range(CHANNEL_TILE):
56          const float vt${ABC[C]} = vtl${ABC[C]} + vtd${ABC[C]} * valphah;
57          const float vb${ABC[C]} = vbl${ABC[C]} + vbd${ABC[C]} * valphah;
58
59        $for C in range(CHANNEL_TILE):
60          const float vd${ABC[C]} = vb${ABC[C]} - vt${ABC[C]};
61
62        $for C in range(CHANNEL_TILE):
63          const float vo${ABC[C]} = vt${ABC[C]} + vd${ABC[C]} * valphav;
64
65        $for C in range(CHANNEL_TILE):
66          output[${C}] = vo${ABC[C]};
67        output += ${CHANNEL_TILE};
68      }
69      for (; c >= sizeof(float); c -= sizeof(float)) {
70        const float vtl = *i0++;
71        const float vtr = *i1++;
72        const float vbl = *i2++;
73        const float vbr = *i3++;
74
75        const float vtd = vtr - vtl;
76        const float vbd = vbr - vbl;
77
78        const float vt = vtl + vtd * valphah;
79        const float vb = vbl + vbd * valphah;
80
81        const float vd = vb - vt;
82
83        const float vo = vt + vd * valphav;
84
85        *output++ = vo;
86      }
87    $else:
88      do {
89        const float vtl = *i0++;
90        const float vtr = *i1++;
91        const float vbl = *i2++;
92        const float vbr = *i3++;
93
94        const float vtd = vtr - vtl;
95        const float vbd = vbr - vbl;
96
97        const float vt = vtl + vtd * valphah;
98        const float vb = vbl + vbd * valphah;
99
100        const float vd = vb - vt;
101
102        const float vo = vt + vd * valphav;
103
104        *output++ = vo;
105
106        c -= sizeof(float);
107      } while (c != 0);
108
109    output = (float*) ((uintptr_t) output + output_increment);
110  } while (--output_pixels != 0);
111}
112