blob: 4da07f93b0dc828f8e16172abdb655c905661a88 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2019 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"
30
31#include <arm_neon.h>
32#include <cstdint>
33
34using namespace arm_compute;
35
36namespace arm_compute
37{
38class Coordinates;
39} // namespace arm_compute
40
41namespace
42{
43inline void bitwise_not_U8_U8(const uint8_t *__restrict input, uint8_t *__restrict output)
44{
45 const uint8x16_t val0 = vld1q_u8(input);
46
47 vst1q_u8(output, vmvnq_u8(val0));
48}
49} // namespace
50
51NEBitwiseNotKernel::NEBitwiseNotKernel()
52 : _input(nullptr), _output(nullptr)
53{
54}
55
56void NEBitwiseNotKernel::configure(const ITensor *input, ITensor *output)
57{
58 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
59
60 set_shape_if_empty(*output->info(), input->info()->tensor_shape());
61
62 set_format_if_unknown(*output->info(), Format::U8);
63 set_format_if_unknown(*input->info(), Format::U8);
64
65 ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(input, output);
66 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
67 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::U8);
68 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
69
70 _input = input;
71 _output = output;
72
73 constexpr unsigned int num_elems_processed_per_iteration = 16;
74
75 // Configure kernel window
76 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
77 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
78 update_window_and_padding(win, AccessWindowHorizontal(input->info(), 0, num_elems_processed_per_iteration), output_access);
79 output_access.set_valid_region(win, input->info()->valid_region());
80
81 INEKernel::configure(win);
82}
83
Moritz Pflanzerc186b572017-09-07 09:48:04 +010084void NEBitwiseNotKernel::run(const Window &window, const ThreadInfo &info)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085{
Moritz Pflanzerc186b572017-09-07 09:48:04 +010086 ARM_COMPUTE_UNUSED(info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010087 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
88 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
89 Iterator input(_input, window);
90 Iterator output(_output, window);
91
Michalis Spyroua4f378d2019-04-26 14:54:54 +010092 execute_window_loop(window, [&](const Coordinates &)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093 {
94 bitwise_not_U8_U8(input.ptr(), output.ptr());
95 },
96 input, output);
97}