xref: /aosp_15_r20/external/XNNPACK/src/x8-lut/scalar.c.in (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1// Copyright 2021 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 >= 1
7$ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8#include <assert.h>
9
10#include <xnnpack/lut.h>
11#include <xnnpack/common.h>
12
13
14void xnn_x8_lut_ukernel__scalar_x${BATCH_TILE}(
15    size_t n,
16    const uint8_t* x,
17    uint8_t* y,
18    const uint8_t t[restrict XNN_MIN_ELEMENTS(256)])
19{
20  assert(n != 0);
21  assert(x != NULL);
22  assert(y != NULL);
23
24  $if BATCH_TILE > 1:
25    for (; n >= ${BATCH_TILE} * sizeof(uint8_t); n -= ${BATCH_TILE} * sizeof(uint8_t)) {
26      $for N in range(BATCH_TILE):
27        const size_t vx${N} = (size_t) x[${N}];
28      x += ${BATCH_TILE};
29
30      $for N in range(BATCH_TILE):
31        const uint32_t vt${N} = (uint32_t) t[vx${N}];
32
33      $for N in range(BATCH_TILE):
34        y[${N}] = (uint8_t) vt${N};
35      y += ${BATCH_TILE};
36    }
37    if XNN_UNLIKELY(n != 0) {
38      $if BATCH_TILE > 2:
39        do {
40          const size_t vx = (size_t) *x++;
41          const uint32_t vt = (uint32_t) t[vx];
42          *y++ = (uint8_t) vt;
43          n -= sizeof(uint8_t);
44        } while (n != 0);
45      $else:
46        const size_t vx = (size_t) *x;
47        const uint32_t vt = (uint32_t) t[vx];
48        *y = (uint8_t) vt;
49    }
50  $else:
51    do {
52      const size_t vx = (size_t) *x++;
53      const uint32_t vt = (uint32_t) t[vx];
54      *y++ = (uint8_t) vt;
55      n -= sizeof(uint8_t);
56    } while (n != 0);
57}
58