1 /*
2 * Copyright (c) 2016-2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 #include "src/core/NEON/kernels/NEBitwiseNotKernel.h"
25
26 #include "arm_compute/core/Helpers.h"
27 #include "arm_compute/core/ITensor.h"
28 #include "arm_compute/core/Types.h"
29 #include "arm_compute/core/Validate.h"
30 #include "src/core/helpers/AutoConfiguration.h"
31 #include "src/core/helpers/WindowHelpers.h"
32
33 #include <arm_neon.h>
34 #include <cstdint>
35
36 using namespace arm_compute;
37
38 namespace arm_compute
39 {
40 class Coordinates;
41 } // namespace arm_compute
42
43 namespace
44 {
bitwise_not_U8_U8(const uint8_t * __restrict input,uint8_t * __restrict output)45 inline void bitwise_not_U8_U8(const uint8_t *__restrict input, uint8_t *__restrict output)
46 {
47 const uint8x16_t val0 = vld1q_u8(input);
48
49 vst1q_u8(output, vmvnq_u8(val0));
50 }
51 } // namespace
52
NEBitwiseNotKernel()53 NEBitwiseNotKernel::NEBitwiseNotKernel()
54 : _input(nullptr), _output(nullptr)
55 {
56 }
57
configure(const ITensor * input,ITensor * output)58 void NEBitwiseNotKernel::configure(const ITensor *input, ITensor *output)
59 {
60 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
61
62 set_shape_if_empty(*output->info(), input->info()->tensor_shape());
63
64 set_format_if_unknown(*output->info(), Format::U8);
65 set_format_if_unknown(*input->info(), Format::U8);
66
67 ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input, output);
68 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
69 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8);
70 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
71
72 _input = input;
73 _output = output;
74
75 constexpr unsigned int num_elems_processed_per_iteration = 16;
76
77 // Configure kernel window
78 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
79 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
80 update_window_and_padding(win, AccessWindowHorizontal(input->info(), 0, num_elems_processed_per_iteration), output_access);
81
82 INEKernel::configure(win);
83 }
84
run(const Window & window,const ThreadInfo & info)85 void NEBitwiseNotKernel::run(const Window &window, const ThreadInfo &info)
86 {
87 ARM_COMPUTE_UNUSED(info);
88 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
89 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
90 Iterator input(_input, window);
91 Iterator output(_output, window);
92
93 execute_window_loop(window, [&](const Coordinates &)
94 {
95 bitwise_not_U8_U8(input.ptr(), output.ptr());
96 },
97 input, output);
98 }
99