blob: 0ef1648d944c4f196c70414fe9da6198f79061fd [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016, 2017 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 "helpers.h"
25
26/** This function performs table lookup on U8 input/output images.
27 *
28 * Global Workgroup Size [ DIV_CEIL(width, 8), height ]
29 *
30 *
31 * @param[in] src_ptr Pointer to the source image. Supported data types: U8
32 * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
33 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
34 * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
35 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
36 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
37 * @param[out] dst_ptr Pointer to the destination image. Supported data types: U8
38 * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes)
39 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
40 * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes)
41 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
42 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image
43 * @param[in] lut LUT table. Supported data types: U8
44 */
45__kernel void tablelookup_U8(
46 IMAGE_DECLARATION(src),
47 IMAGE_DECLARATION(dst),
48 __global uchar *lut)
49{
50 Image src = CONVERT_TO_IMAGE_STRUCT(src);
51 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
52
53 /* Load input data */
54 uchar8 data = vload8(0, src.ptr);
55
56 /* Load lut data */
57 uchar8 lut_data = (uchar8)(lut[data.s0], lut[data.s1], lut[data.s2], lut[data.s3],
58 lut[data.s4], lut[data.s5], lut[data.s6], lut[data.s7]);
59
60 /* Store result */
61 vstore8(lut_data, 0, dst.ptr);
62}
63
64/** This function performs table lookup on S16 input/output images.
65 *
66 * Global Workgroup Size [ DIV_CEIL(width, 8), height ]
67 *
68 * @param[in] src_ptr Pointer to the source image. Supported data types: S16
69 * @param[in] src_stride_x Stride of the source image in X dimension (in bytes)
70 * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes)
71 * @param[in] src_stride_y Stride of the source image in Y dimension (in bytes)
72 * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes)
73 * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source image
74 * @param[out] dst_ptr Pointer to the destination image. Supported data types: S16
75 * @param[in] dst_stride_x Stride of the destination image in X dimension (in bytes)
76 * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes)
77 * @param[in] dst_stride_y Stride of the destination image in Y dimension (in bytes)
78 * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes)
79 * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination image
80 * @param[in] lut LUT table. Supported data types: S16
81 * @param[in] offset LUT offset
82 * @param[in] count Number of elements in the LUT
83 */
84__kernel void tablelookup_S16(
85 IMAGE_DECLARATION(src),
86 IMAGE_DECLARATION(dst),
87 __global short *lut,
88 uint offset,
89 uint count)
90{
91 Image src = CONVERT_TO_IMAGE_STRUCT(src);
92 Image dst = CONVERT_TO_IMAGE_STRUCT(dst);
93
94 /* Load input data */
95 short8 data = vload8(0, (__global short *)src.ptr);
96
97 /* Load output data */
98 int8 out_data = convert_int8(vload8(0, (__global short *)dst.ptr));
99
100 /* Calculate index */
101 int8 index = convert_int8(data) + (int8)(offset);
102 int8 cond = (index >= 0 && index < (int8)count);
103 index = select(0, index, cond);
104
105 /* Load lut data */
106 int8 lut_data = (int8)(lut[index.s0], lut[index.s1], lut[index.s2], lut[index.s3],
107 lut[index.s4], lut[index.s5], lut[index.s6], lut[index.s7]);
108
109 /* Select output data depending on condition */
110 lut_data = select(out_data, lut_data, cond);
111
112 /* Store result */
113 vstore8(convert_short8(lut_data), 0, (__global short *)dst.ptr);
114}