blob: eed9b273ae0e71b623f0e01e9cd40b7539bac0a1 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 "arm_compute/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"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010030#include "src/core/helpers/AutoConfiguration.h"
31#include "src/core/helpers/WindowHelpers.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33#include <arm_neon.h>
34#include <cstdint>
35
36using namespace arm_compute;
37
38namespace arm_compute
39{
40class Coordinates;
41} // namespace arm_compute
42
43namespace
44{
45inline 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
53NEBitwiseNotKernel::NEBitwiseNotKernel()
54 : _input(nullptr), _output(nullptr)
55{
56}
57
58void 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 output_access.set_valid_region(win, input->info()->valid_region());
82
83 INEKernel::configure(win);
84}
85
Moritz Pflanzerc186b572017-09-07 09:48:04 +010086void NEBitwiseNotKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087{
Moritz Pflanzerc186b572017-09-07 09:48:04 +010088 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
90 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
91 Iterator input(_input, window);
92 Iterator output(_output, window);
93
Michalis Spyroua4f378d2019-04-26 14:54:54 +010094 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010095 {
96 bitwise_not_U8_U8(input.ptr(), output.ptr());
97 },
98 input, output);
99}