blob: ab2b3d18ce002677840a033de53ca14b6a8b8f23 [file] [log] [blame]
Cindy Liu43879e42023-10-18 11:18:03 -07001/*
Lun Dong3b8d3cb2024-05-07 01:50:35 -07002 * Copyright 2024 Google LLC
Cindy Liu43879e42023-10-18 11:18:03 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Alex Van Damme59112ad2023-08-11 11:10:33 -070016
17#include "crt/kelvin.h"
18#include "tflm/opt/opt.h"
19
20namespace kelvin::opt {
Lun Dong3b8d3cb2024-05-07 01:50:35 -070021void ElementwiseAddS32(const int32_t* input1, const int32_t* input2,
22 int32_t* output, const int32_t output_activation_min,
23 const int32_t output_activation_max,
24 const int32_t block_size) {
Alex Van Damme59112ad2023-08-11 11:10:33 -070025 int blocks = block_size;
26 int vl;
27 getmaxvl_w_m(vl);
28 while (blocks) {
29 int count = std::min(blocks, vl);
30
31 vld_w_p_xx_m(vm0, input1, count);
32 vld_w_p_xx_m(vm1, input2, count);
33
34 vadd_w_vv_m(vm0, vm0, vm1);
35 vmin_w_vx_m(vm0, vm0, output_activation_max);
36 vmax_w_vx_m(vm0, vm0, output_activation_min);
37
38 vst_w_p_xx_m(vm0, output, count);
39
40 blocks -= count;
41 }
42}
43} // namespace kelvin::opt