| // Copyright 2021 Google LLC |
| // |
| // This source code is licensed under the BSD-style license found in the |
| // LICENSE file in the root directory of this source tree. |
| |
| $assert BATCH_TILE >= 1 |
| $ABC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| #include <assert.h> |
| |
| #include <xnnpack/lut.h> |
| #include <xnnpack/common.h> |
| |
| |
| void xnn_x8_lut_ukernel__scalar_x${BATCH_TILE}( |
| size_t n, |
| const uint8_t* x, |
| uint8_t* y, |
| const uint8_t t[restrict XNN_MIN_ELEMENTS(256)]) |
| { |
| assert(n != 0); |
| assert(x != NULL); |
| assert(y != NULL); |
| |
| $if BATCH_TILE > 1: |
| for (; n >= ${BATCH_TILE} * sizeof(uint8_t); n -= ${BATCH_TILE} * sizeof(uint8_t)) { |
| $for N in range(BATCH_TILE): |
| const size_t vx${N} = (size_t) x[${N}]; |
| x += ${BATCH_TILE}; |
| |
| $for N in range(BATCH_TILE): |
| const uint32_t vt${N} = (uint32_t) t[vx${N}]; |
| |
| $for N in range(BATCH_TILE): |
| y[${N}] = (uint8_t) vt${N}; |
| y += ${BATCH_TILE}; |
| } |
| if XNN_UNLIKELY(n != 0) { |
| $if BATCH_TILE > 2: |
| do { |
| const size_t vx = (size_t) *x++; |
| const uint32_t vt = (uint32_t) t[vx]; |
| *y++ = (uint8_t) vt; |
| n -= sizeof(uint8_t); |
| } while (n != 0); |
| $else: |
| const size_t vx = (size_t) *x; |
| const uint32_t vt = (uint32_t) t[vx]; |
| *y = (uint8_t) vt; |
| } |
| $else: |
| do { |
| const size_t vx = (size_t) *x++; |
| const uint32_t vt = (uint32_t) t[vx]; |
| *y++ = (uint8_t) vt; |
| n -= sizeof(uint8_t); |
| } while (n != 0); |
| } |