| /* |
| * Copyright 2024 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include "crt/kelvin.h" |
| #include "tflm/opt/opt.h" |
| |
| namespace kelvin::opt { |
| void ElementwiseAddS32(const int32_t* input1, const int32_t* input2, |
| int32_t* output, const int32_t output_activation_min, |
| const int32_t output_activation_max, |
| const int32_t block_size) { |
| int blocks = block_size; |
| int vl; |
| getmaxvl_w_m(vl); |
| while (blocks) { |
| int count = std::min(blocks, vl); |
| |
| vld_w_p_xx_m(vm0, input1, count); |
| vld_w_p_xx_m(vm1, input2, count); |
| |
| vadd_w_vv_m(vm0, vm0, vm1); |
| vmin_w_vx_m(vm0, vm0, output_activation_max); |
| vmax_w_vx_m(vm0, vm0, output_activation_min); |
| |
| vst_w_p_xx_m(vm0, output, count); |
| |
| blocks -= count; |
| } |
| } |
| } // namespace kelvin::opt |