Cindy Liu | 43879e4 | 2023-10-18 11:18:03 -0700 | [diff] [blame] | 1 | /* |
Lun Dong | 3b8d3cb | 2024-05-07 01:50:35 -0700 | [diff] [blame^] | 2 | * Copyright 2024 Google LLC |
Cindy Liu | 43879e4 | 2023-10-18 11:18:03 -0700 | [diff] [blame] | 3 | * |
| 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 Damme | 59112ad | 2023-08-11 11:10:33 -0700 | [diff] [blame] | 16 | |
| 17 | #include "crt/kelvin.h" |
| 18 | #include "tflm/opt/opt.h" |
| 19 | |
| 20 | namespace kelvin::opt { |
Lun Dong | 3b8d3cb | 2024-05-07 01:50:35 -0700 | [diff] [blame^] | 21 | void 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 Damme | 59112ad | 2023-08-11 11:10:33 -0700 | [diff] [blame] | 25 | 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 |