xref: /aosp_15_r20/external/XNNPACK/src/s16-vlshift/scalar.c.in (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1// Copyright 2022 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#include <assert.h>
8#include <stddef.h>
9#include <stdint.h>
10
11#include <xnnpack/math.h>
12#include <xnnpack/vlshift.h>
13
14
15void xnn_s16_vlshift_ukernel__scalar_x${BATCH_TILE}(
16    size_t batch,
17    const int16_t* input,
18    int16_t* output,
19    uint32_t shift)
20{
21  assert(batch != 0);
22  assert(input != NULL);
23  assert(output != NULL);
24  assert(shift < 16);
25
26  $if BATCH_TILE > 1:
27    for (; batch >= ${BATCH_TILE}; batch -= ${BATCH_TILE}) {
28      $for C in range(BATCH_TILE):
29        const uint16_t vi${C} = (uint16_t) input[${C}];
30      input += ${BATCH_TILE};
31
32      $for C in range(BATCH_TILE):
33        const uint16_t vout${C} = vi${C} << shift;
34
35      $for C in range(BATCH_TILE):
36        output[${C}] = (int16_t) vout${C};
37      output += ${BATCH_TILE};
38    }
39 if XNN_UNLIKELY(batch != 0) {
40   do {
41     const uint16_t vi = (uint16_t) *input++;
42
43     const uint16_t vout = vi << shift;
44
45     *output++ = (int16_t) vout;
46   } while (--batch != 0);
47 }
48}
49