arithm_bitwise_or_mask.cl 52.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
//    Jiang Liyuan, jlyuan001.good@163.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other oclMaterials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors as is and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#if defined (DOUBLE_SUPPORT)
#pragma OPENCL EXTENSION cl_khr_fp64:enable
#endif

//////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////BITWISE_OR////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/**************************************bitwise_or with mask**************************************/
__kernel void arithm_bitwise_or_with_mask_C1_D0 (__global uchar *src1, int src1_step, int src1_offset,
                                          __global uchar *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global uchar *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 2;

        #define dst_align (dst_offset & 3)
68 69
        int src1_index = mad24(y, src1_step, x + src1_offset - dst_align);
        int src2_index = mad24(y, src2_step, x + src2_offset - dst_align);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + x & (int)0xfffffffc);

        uchar4 src1_data = vload4(0, src1 + src1_index);
        uchar4 src2_data = vload4(0, src2 + src2_index);
        uchar4 mask_data = vload4(0, mask + mask_index);

        uchar4 data = *((__global uchar4 *)(dst + dst_index));
        uchar4 tmp_data = src1_data | src2_data;

        data.x = ((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : data.x;
        data.y = ((mask_data.y) && (dst_index + 1 >= dst_start) && (dst_index + 1 < dst_end)) ? tmp_data.y : data.y;
        data.z = ((mask_data.z) && (dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.z : data.z;
        data.w = ((mask_data.w) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end)) ? tmp_data.w : data.w;

        *((__global uchar4 *)(dst + dst_index)) = data;
    }
}



__kernel void arithm_bitwise_or_with_mask_C1_D1 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 2;

        #define dst_align (dst_offset & 3)
109 110
        int src1_index = mad24(y, src1_step, x + src1_offset - dst_align);
        int src2_index = mad24(y, src2_step, x + src2_offset - dst_align);
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + x & (int)0xfffffffc);

        char4 src1_data = vload4(0, src1 + src1_index);
        char4 src2_data = vload4(0, src2 + src2_index);
        uchar4 mask_data = vload4(0, mask + mask_index);

        char4 data = *((__global char4 *)(dst + dst_index));
        char4 tmp_data = src1_data | src2_data;

        data.x = convert_char((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : data.x;
        data.y = convert_char((mask_data.y) && (dst_index + 1 >= dst_start) && (dst_index + 1 < dst_end)) ? tmp_data.y : data.y;
        data.z = convert_char((mask_data.z) && (dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.z : data.z;
        data.w = convert_char((mask_data.w) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end)) ? tmp_data.w : data.w;

        *((__global char4 *)(dst + dst_index)) = data;
    }
}



__kernel void arithm_bitwise_or_with_mask_C1_D2 (__global ushort *src1, int src1_step, int src1_offset,
                                          __global ushort *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global ushort *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align ((dst_offset >> 1) & 1)
150 151
        int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1));
        int src2_index = mad24(y, src2_step, (x << 1) + src2_offset - (dst_align << 1));
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffffc);

        ushort2 src1_data = vload2(0, (__global ushort *)((__global char *)src1 + src1_index));
        ushort2 src2_data = vload2(0, (__global ushort *)((__global char *)src2 + src2_index));
        uchar2  mask_data = vload2(0, mask + mask_index);

        ushort2 data = *((__global ushort2 *)((__global uchar *)dst + dst_index));
        ushort2 tmp_data = src1_data | src2_data;

        data.x = convert_ushort((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : data.x;
        data.y = convert_ushort((mask_data.y) && (dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.y : data.y;

        *((__global ushort2 *)((__global uchar *)dst + dst_index)) = data;
    }
}



__kernel void arithm_bitwise_or_with_mask_C1_D3 (__global short *src1, int src1_step, int src1_offset,
                                          __global short *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global short *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align ((dst_offset >> 1) & 1)
189 190
        int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1));
        int src2_index = mad24(y, src2_step, (x << 1) + src2_offset - (dst_align << 1));
191 192 193 194 195 196 197 198 199 200
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffffc);

        short2 src1_data = vload2(0, (__global short *)((__global char *)src1 + src1_index));
        short2 src2_data = vload2(0, (__global short *)((__global char *)src2 + src2_index));
        uchar2  mask_data = vload2(0, mask + mask_index);

201 202
    short2 data = *((__global short2 *)((__global uchar *)dst + dst_index));
    short2 tmp_data = src1_data | src2_data;
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

        data.x = convert_short((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end)) ? tmp_data.x : data.x;
        data.y = convert_short((mask_data.y) && (dst_index + 2 >= dst_start) && (dst_index + 2 < dst_end)) ? tmp_data.y : data.y;

        *((__global short2 *)((__global uchar *)dst + dst_index)) = data;
    }
}



__kernel void arithm_bitwise_or_with_mask_C1_D4 (__global int   *src1, int src1_step, int src1_offset,
                                          __global int   *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global int   *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        int src_data1 = *((__global int *)((__global char *)src1 + src1_index));
        int src_data2 = *((__global int *)((__global char *)src2 + src2_index));
        int dst_data  = *((__global int *)((__global char *)dst  + dst_index));

        int data = src_data1 | src_data2;
237
        data = mask_data ? data : dst_data;
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

        *((__global int *)((__global char *)dst + dst_index)) = data;
    }
}



__kernel void arithm_bitwise_or_with_mask_C1_D5 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char4 src_data1 = *((__global char4 *)((__global char *)src1 + src1_index));
        char4 src_data2 = *((__global char4 *)((__global char *)src2 + src2_index));
        char4 dst_data  = *((__global char4 *)((__global char *)dst  + dst_index));

        char4 data = src_data1 | src_data2;
269
        data = mask_data ? data : dst_data;
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301

        *((__global char4 *)((__global char *)dst + dst_index)) = data;
    }
}



#if defined (DOUBLE_SUPPORT)
__kernel void arithm_bitwise_or_with_mask_C1_D6 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 3) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 3) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 3) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char8 src_data1 = *((__global char8 *)((__global char *)src1 + src1_index));
        char8 src_data2 = *((__global char8 *)((__global char *)src2 + src2_index));
        char8 dst_data  = *((__global char8 *)((__global char *)dst  + dst_index));

        char8 data = src_data1 | src_data2;
302
        data = mask_data ? data : dst_data;
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

        *((__global char8 *)((__global char *)dst + dst_index)) = data;
    }

}
#endif



__kernel void arithm_bitwise_or_with_mask_C2_D0 (__global uchar *src1, int src1_step, int src1_offset,
                                          __global uchar *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global uchar *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align ((dst_offset >> 1) & 1)
327 328
        int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1));
        int src2_index = mad24(y, src2_step, (x << 1) + src2_offset - (dst_align << 1));
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffffc);

        uchar4 src1_data = vload4(0, src1 + src1_index);
        uchar4 src2_data = vload4(0, src2 + src2_index);
        uchar2 mask_data = vload2(0, mask + mask_index);

        uchar4 data = *((__global uchar4 *)(dst + dst_index));
        uchar4 tmp_data = src1_data | src2_data;

        data.xy = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data.xy : data.xy;
        data.zw = ((mask_data.y) && (dst_index + 2 <  dst_end  )) ? tmp_data.zw : data.zw;

        *((__global uchar4 *)(dst + dst_index)) = data;
    }
}


__kernel void arithm_bitwise_or_with_mask_C2_D1 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align ((dst_offset >> 1) & 1)
365 366
        int src1_index = mad24(y, src1_step, (x << 1) + src1_offset - (dst_align << 1));
        int src2_index = mad24(y, src2_step, (x << 1) + src2_offset - (dst_align << 1));
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x << 1) & (int)0xfffffffc);

        char4 src1_data = vload4(0, src1 + src1_index);
        char4 src2_data = vload4(0, src2 + src2_index);
        uchar2 mask_data = vload2(0, mask + mask_index);

        char4 data = *((__global char4 *)(dst + dst_index));
        char4 tmp_data = src1_data | src2_data;

        data.xy = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data.xy : data.xy;
        data.zw = ((mask_data.y) && (dst_index + 2 <  dst_end  )) ? tmp_data.zw : data.zw;

        *((__global char4 *)(dst + dst_index)) = data;
    }
}

__kernel void arithm_bitwise_or_with_mask_C2_D2 (__global ushort *src1, int src1_step, int src1_offset,
                                          __global ushort *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global ushort *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        ushort2 src_data1 = *((__global ushort2 *)((__global char *)src1 + src1_index));
        ushort2 src_data2 = *((__global ushort2 *)((__global char *)src2 + src2_index));
        ushort2 dst_data  = *((__global ushort2 *)((__global char *)dst  + dst_index));

        ushort2 data = src_data1 | src_data2;
411
        data = mask_data ? data : dst_data;
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

        *((__global ushort2 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C2_D3 (__global short *src1, int src1_step, int src1_offset,
                                          __global short *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global short *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        short2 src_data1 = *((__global short2 *)((__global char *)src1 + src1_index));
        short2 src_data2 = *((__global short2 *)((__global char *)src2 + src2_index));
        short2 dst_data  = *((__global short2 *)((__global char *)dst  + dst_index));

        short2 data = src_data1 | src_data2;
440
        data = mask_data ? data : dst_data;
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468

        *((__global short2 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C2_D4 (__global int   *src1, int src1_step, int src1_offset,
                                          __global int   *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global int    *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 3) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 3) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 3) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        int2 src_data1 = *((__global int2 *)((__global char *)src1 + src1_index));
        int2 src_data2 = *((__global int2 *)((__global char *)src2 + src2_index));
        int2 dst_data  = *((__global int2 *)((__global char *)dst  + dst_index));

        int2 data = src_data1 | src_data2;
469
        data = mask_data ? data : dst_data;
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497

        *((__global int2 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C2_D5 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 3) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 3) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 3) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char8 src_data1 = *((__global char8 *)((__global char *)src1 + src1_index));
        char8 src_data2 = *((__global char8 *)((__global char *)src2 + src2_index));
        char8 dst_data  = *((__global char8 *)((__global char *)dst  + dst_index));

        char8 data = src_data1 | src_data2;
498
        data = mask_data ? data : dst_data;
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527

        *((__global char8 *)((__global char *)dst + dst_index)) = data;
    }
}
#if defined (DOUBLE_SUPPORT)
__kernel void arithm_bitwise_or_with_mask_C2_D6 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 4) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 4) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 4) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char16 src_data1 = *((__global char16 *)((__global char *)src1 + src1_index));
        char16 src_data2 = *((__global char16 *)((__global char *)src2 + src2_index));
        char16 dst_data  = *((__global char16 *)((__global char *)dst  + dst_index));

        char16 data = src_data1 | src_data2;
528
        data = mask_data ? data : dst_data;
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551

        *((__global char16 *)((__global char *)dst + dst_index)) = data;
    }
}
#endif



__kernel void arithm_bitwise_or_with_mask_C3_D0 (__global uchar *src1, int src1_step, int src1_offset,
                                          __global uchar *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global uchar *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 2;

        #define dst_align (((dst_offset % dst_step) / 3 ) & 3)
552 553
        int src1_index = mad24(y, src1_step, (x * 3) + src1_offset - (dst_align * 3));
        int src2_index = mad24(y, src2_step, (x * 3) + src2_offset - (dst_align * 3));
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 3) - (dst_align * 3));

        uchar4 src1_data_0 = vload4(0, src1 + src1_index + 0);
        uchar4 src1_data_1 = vload4(0, src1 + src1_index + 4);
        uchar4 src1_data_2 = vload4(0, src1 + src1_index + 8);

        uchar4 src2_data_0 = vload4(0, src2 + src2_index + 0);
        uchar4 src2_data_1 = vload4(0, src2 + src2_index + 4);
        uchar4 src2_data_2 = vload4(0, src2 + src2_index + 8);

        uchar4 mask_data = vload4(0, mask + mask_index);

        uchar4 data_0 = *((__global uchar4 *)(dst + dst_index + 0));
        uchar4 data_1 = *((__global uchar4 *)(dst + dst_index + 4));
        uchar4 data_2 = *((__global uchar4 *)(dst + dst_index + 8));

        uchar4 tmp_data_0 =  src1_data_0 | src2_data_0;
        uchar4 tmp_data_1 =  src1_data_1 | src2_data_1;
        uchar4 tmp_data_2 =  src1_data_2 | src2_data_2;

        data_0.xyz = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data_0.xyz : data_0.xyz;
579
        data_0.w   = ((mask_data.y) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end))
580 581
                     ? tmp_data_0.w : data_0.w;

582
        data_1.xy  = ((mask_data.y) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end))
583
                     ? tmp_data_1.xy : data_1.xy;
584
        data_1.zw  = ((mask_data.z) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
585 586
                     ? tmp_data_1.zw : data_1.zw;

587
        data_2.x   = ((mask_data.z) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
588
                     ? tmp_data_2.x : data_2.x;
589
        data_2.yzw = ((mask_data.w) && (dst_index + 9 >= dst_start) && (dst_index + 9 < dst_end))
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
                     ? tmp_data_2.yzw : data_2.yzw;

        *((__global uchar4 *)(dst + dst_index + 0)) = data_0;
        *((__global uchar4 *)(dst + dst_index + 4)) = data_1;
        *((__global uchar4 *)(dst + dst_index + 8)) = data_2;
    }
}


__kernel void arithm_bitwise_or_with_mask_C3_D1 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 2;

        #define dst_align (((dst_offset % dst_step) / 3 ) & 3)
614 615
        int src1_index = mad24(y, src1_step, (x * 3) + src1_offset - (dst_align * 3));
        int src2_index = mad24(y, src2_step, (x * 3) + src2_offset - (dst_align * 3));
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 3) - (dst_align * 3));

        char4 src1_data_0 = vload4(0, src1 + src1_index + 0);
        char4 src1_data_1 = vload4(0, src1 + src1_index + 4);
        char4 src1_data_2 = vload4(0, src1 + src1_index + 8);

        char4 src2_data_0 = vload4(0, src2 + src2_index + 0);
        char4 src2_data_1 = vload4(0, src2 + src2_index + 4);
        char4 src2_data_2 = vload4(0, src2 + src2_index + 8);

        uchar4 mask_data = vload4(0, mask + mask_index);

        char4 data_0 = *((__global char4 *)(dst + dst_index + 0));
        char4 data_1 = *((__global char4 *)(dst + dst_index + 4));
        char4 data_2 = *((__global char4 *)(dst + dst_index + 8));

        char4 tmp_data_0 =  src1_data_0 | src2_data_0;
        char4 tmp_data_1 =  src1_data_1 | src2_data_1;
        char4 tmp_data_2 =  src1_data_2 | src2_data_2;

        data_0.xyz = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data_0.xyz : data_0.xyz;
641
        data_0.w   = ((mask_data.y) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end))
642 643
                     ? tmp_data_0.w : data_0.w;

644
        data_1.xy  = ((mask_data.y) && (dst_index + 3 >= dst_start) && (dst_index + 3 < dst_end))
645
                     ? tmp_data_1.xy : data_1.xy;
646
        data_1.zw  = ((mask_data.z) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
647 648
                     ? tmp_data_1.zw : data_1.zw;

649
        data_2.x   = ((mask_data.z) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
650
                     ? tmp_data_2.x : data_2.x;
651
        data_2.yzw = ((mask_data.w) && (dst_index + 9 >= dst_start) && (dst_index + 9 < dst_end))
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
                     ? tmp_data_2.yzw : data_2.yzw;

        *((__global char4 *)(dst + dst_index + 0)) = data_0;
        *((__global char4 *)(dst + dst_index + 4)) = data_1;
        *((__global char4 *)(dst + dst_index + 8)) = data_2;
    }
}

__kernel void arithm_bitwise_or_with_mask_C3_D2 (__global ushort *src1, int src1_step, int src1_offset,
                                          __global ushort *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global ushort *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align (((dst_offset % dst_step) / 6 ) & 1)
675 676
        int src1_index = mad24(y, src1_step, (x * 6) + src1_offset - (dst_align * 6));
        int src2_index = mad24(y, src2_step, (x * 6) + src2_offset - (dst_align * 6));
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 6) - (dst_align * 6));

        ushort2 src1_data_0 = vload2(0, (__global ushort *)((__global char *)src1 + src1_index + 0));
        ushort2 src1_data_1 = vload2(0, (__global ushort *)((__global char *)src1 + src1_index + 4));
        ushort2 src1_data_2 = vload2(0, (__global ushort *)((__global char *)src1 + src1_index + 8));

        ushort2 src2_data_0 = vload2(0, (__global ushort *)((__global char *)src2 + src2_index + 0));
        ushort2 src2_data_1 = vload2(0, (__global ushort *)((__global char *)src2 + src2_index + 4));
        ushort2 src2_data_2 = vload2(0, (__global ushort *)((__global char *)src2 + src2_index + 8));

        uchar2 mask_data = vload2(0, mask + mask_index);

        ushort2 data_0 = *((__global ushort2 *)((__global char *)dst + dst_index + 0));
        ushort2 data_1 = *((__global ushort2 *)((__global char *)dst + dst_index + 4));
        ushort2 data_2 = *((__global ushort2 *)((__global char *)dst + dst_index + 8));

        ushort2 tmp_data_0 =  src1_data_0 | src2_data_0 ;
        ushort2 tmp_data_1 =  src1_data_1 | src2_data_1 ;
        ushort2 tmp_data_2 =  src1_data_2 | src2_data_2 ;

        data_0.xy = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data_0.xy : data_0.xy;

703
        data_1.x  = ((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end))
704
                     ? tmp_data_1.x : data_1.x;
705
        data_1.y  = ((mask_data.y) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
706 707
                     ? tmp_data_1.y : data_1.y;

708
        data_2.xy = ((mask_data.y) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
                     ? tmp_data_2.xy : data_2.xy;

       *((__global ushort2 *)((__global char *)dst + dst_index + 0))= data_0;
       *((__global ushort2 *)((__global char *)dst + dst_index + 4))= data_1;
       *((__global ushort2 *)((__global char *)dst + dst_index + 8))= data_2;
    }
}
__kernel void arithm_bitwise_or_with_mask_C3_D3 (__global short *src1, int src1_step, int src1_offset,
                                          __global short *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global short *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        x = x << 1;

        #define dst_align (((dst_offset % dst_step) / 6 ) & 1)
731 732
        int src1_index = mad24(y, src1_step, (x * 6) + src1_offset - (dst_align * 6));
        int src2_index = mad24(y, src2_step, (x * 6) + src2_offset - (dst_align * 6));
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
        int mask_index = mad24(y, mask_step, x + mask_offset - dst_align);

        int dst_start  = mad24(y, dst_step, dst_offset);
        int dst_end    = mad24(y, dst_step, dst_offset + dst_step1);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 6) - (dst_align * 6));

        short2 src1_data_0 = vload2(0, (__global short *)((__global char *)src1 + src1_index + 0));
        short2 src1_data_1 = vload2(0, (__global short *)((__global char *)src1 + src1_index + 4));
        short2 src1_data_2 = vload2(0, (__global short *)((__global char *)src1 + src1_index + 8));

        short2 src2_data_0 = vload2(0, (__global short *)((__global char *)src2 + src2_index + 0));
        short2 src2_data_1 = vload2(0, (__global short *)((__global char *)src2 + src2_index + 4));
        short2 src2_data_2 = vload2(0, (__global short *)((__global char *)src2 + src2_index + 8));

        uchar2 mask_data = vload2(0, mask + mask_index);

        short2 data_0 = *((__global short2 *)((__global char *)dst + dst_index + 0));
        short2 data_1 = *((__global short2 *)((__global char *)dst + dst_index + 4));
        short2 data_2 = *((__global short2 *)((__global char *)dst + dst_index + 8));

        short2 tmp_data_0 =  src1_data_0 | src2_data_0 ;
        short2 tmp_data_1 =  src1_data_1 | src2_data_1 ;
        short2 tmp_data_2 =  src1_data_2 | src2_data_2 ;

        data_0.xy = ((mask_data.x) && (dst_index + 0 >= dst_start)) ? tmp_data_0.xy : data_0.xy;

759
        data_1.x  = ((mask_data.x) && (dst_index + 0 >= dst_start) && (dst_index + 0 < dst_end))
760
                     ? tmp_data_1.x : data_1.x;
761
        data_1.y  = ((mask_data.y) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
762 763
                     ? tmp_data_1.y : data_1.y;

764
        data_2.xy = ((mask_data.y) && (dst_index + 6 >= dst_start) && (dst_index + 6 < dst_end))
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
                     ? tmp_data_2.xy : data_2.xy;

       *((__global short2 *)((__global char *)dst + dst_index + 0))= data_0;
       *((__global short2 *)((__global char *)dst + dst_index + 4))= data_1;
       *((__global short2 *)((__global char *)dst + dst_index + 8))= data_2;
    }
}
__kernel void arithm_bitwise_or_with_mask_C3_D4 (__global int   *src1, int src1_step, int src1_offset,
                                          __global int   *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global int   *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
784 785
        int src1_index = mad24(y, src1_step, (x * 12) + src1_offset);
        int src2_index = mad24(y, src2_step, (x * 12) + src2_offset);
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827
        int mask_index = mad24(y, mask_step, x + mask_offset);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 12));

        int src1_data_0 = *((__global int *)((__global char *)src1 + src1_index + 0));
        int src1_data_1 = *((__global int *)((__global char *)src1 + src1_index + 4));
        int src1_data_2 = *((__global int *)((__global char *)src1 + src1_index + 8));

        int src2_data_0 = *((__global int *)((__global char *)src2 + src2_index + 0));
        int src2_data_1 = *((__global int *)((__global char *)src2 + src2_index + 4));
        int src2_data_2 = *((__global int *)((__global char *)src2 + src2_index + 8));

        uchar mask_data = * (mask + mask_index);

        int data_0 = *((__global int *)((__global char *)dst + dst_index + 0));
        int data_1 = *((__global int *)((__global char *)dst + dst_index + 4));
        int data_2 = *((__global int *)((__global char *)dst + dst_index + 8));

        int tmp_data_0 =  src1_data_0 |  src2_data_0 ;
        int tmp_data_1 =  src1_data_1 |  src2_data_1 ;
        int tmp_data_2 =  src1_data_2 |  src2_data_2 ;

        data_0 = mask_data ? tmp_data_0 : data_0;
        data_1 = mask_data ? tmp_data_1 : data_1;
        data_2 = mask_data ? tmp_data_2 : data_2;

       *((__global int *)((__global char *)dst + dst_index + 0))= data_0;
       *((__global int *)((__global char *)dst + dst_index + 4))= data_1;
       *((__global int *)((__global char *)dst + dst_index + 8))= data_2;
    }
}
__kernel void arithm_bitwise_or_with_mask_C3_D5 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
828 829
        int src1_index = mad24(y, src1_step, (x * 12) + src1_offset);
        int src2_index = mad24(y, src2_step, (x * 12) + src2_offset);
830 831 832 833 834 835
        int mask_index = mad24(y, mask_step, x + mask_offset);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 12));

        char4 src1_data_0 = *((__global char4 *)((__global char *)src1 + src1_index + 0));
        char4 src1_data_1 = *((__global char4 *)((__global char *)src1 + src1_index + 4));
        char4 src1_data_2 = *((__global char4 *)((__global char *)src1 + src1_index + 8));
836

837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
        char4 src2_data_0 = *((__global char4 *)((__global char *)src2 + src2_index + 0));
        char4 src2_data_1 = *((__global char4 *)((__global char *)src2 + src2_index + 4));
        char4 src2_data_2 = *((__global char4 *)((__global char *)src2 + src2_index + 8));

        uchar mask_data = * (mask + mask_index);

        char4 data_0 = *((__global char4 *)((__global char *)dst + dst_index + 0));
        char4 data_1 = *((__global char4 *)((__global char *)dst + dst_index + 4));
        char4 data_2 = *((__global char4 *)((__global char *)dst + dst_index + 8));

        char4 tmp_data_0 = src1_data_0 | src2_data_0;
        char4 tmp_data_1 = src1_data_1 | src2_data_1;
        char4 tmp_data_2 = src1_data_2 | src2_data_2;

        data_0 = mask_data ? tmp_data_0 : data_0;
        data_1 = mask_data ? tmp_data_1 : data_1;
        data_2 = mask_data ? tmp_data_2 : data_2;

       *((__global char4 *)((__global char *)dst + dst_index + 0))= data_0;
       *((__global char4 *)((__global char *)dst + dst_index + 4))= data_1;
       *((__global char4 *)((__global char *)dst + dst_index + 8))= data_2;
    }
}
#if defined (DOUBLE_SUPPORT)
__kernel void arithm_bitwise_or_with_mask_C3_D6 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
873 874
        int src1_index = mad24(y, src1_step, (x * 24) + src1_offset);
        int src2_index = mad24(y, src2_step, (x * 24) + src2_offset);
875 876 877 878 879 880
        int mask_index = mad24(y, mask_step, x + mask_offset);
        int dst_index  = mad24(y, dst_step, dst_offset + (x * 24));

        char8 src1_data_0 = *((__global char8 *)((__global char *)src1 + src1_index + 0 ));
        char8 src1_data_1 = *((__global char8 *)((__global char *)src1 + src1_index + 8 ));
        char8 src1_data_2 = *((__global char8 *)((__global char *)src1 + src1_index + 16));
881

882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
        char8 src2_data_0 = *((__global char8 *)((__global char *)src2 + src2_index + 0 ));
        char8 src2_data_1 = *((__global char8 *)((__global char *)src2 + src2_index + 8 ));
        char8 src2_data_2 = *((__global char8 *)((__global char *)src2 + src2_index + 16));

        uchar mask_data = * (mask + mask_index);

        char8 data_0 = *((__global char8 *)((__global char *)dst + dst_index + 0 ));
        char8 data_1 = *((__global char8 *)((__global char *)dst + dst_index + 8 ));
        char8 data_2 = *((__global char8 *)((__global char *)dst + dst_index + 16));

        char8 tmp_data_0 = src1_data_0 | src2_data_0;
        char8 tmp_data_1 = src1_data_1 | src2_data_1;
        char8 tmp_data_2 = src1_data_2 | src2_data_2;

        data_0 = mask_data ? tmp_data_0 : data_0;
        data_1 = mask_data ? tmp_data_1 : data_1;
        data_2 = mask_data ? tmp_data_2 : data_2;

       *((__global char8 *)((__global char *)dst + dst_index + 0 ))= data_0;
       *((__global char8 *)((__global char *)dst + dst_index + 8 ))= data_1;
       *((__global char8 *)((__global char *)dst + dst_index + 16))= data_2;
    }
}
#endif



__kernel void arithm_bitwise_or_with_mask_C4_D0 (__global uchar *src1, int src1_step, int src1_offset,
                                          __global uchar *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global uchar *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        uchar4 src_data1 = *((__global uchar4 *)(src1 + src1_index));
        uchar4 src_data2 = *((__global uchar4 *)(src2 + src2_index));
        uchar4 dst_data  = *((__global uchar4 *)(dst  + dst_index));

        uchar4 data = src_data1 | src_data2;
933
        data = mask_data ? data : dst_data;
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963

        *((__global uchar4 *)(dst + dst_index)) = data;
    }
}


__kernel void arithm_bitwise_or_with_mask_C4_D1 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 2) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 2) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 2) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char4 src_data1 = *((__global char4 *)(src1 + src1_index));
        char4 src_data2 = *((__global char4 *)(src2 + src2_index));
        char4 dst_data  = *((__global char4 *)(dst  + dst_index));

        char4 data = src_data1 | src_data2;
964
        data = mask_data ? data : dst_data;
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993

        *((__global char4 *)(dst + dst_index)) = data;
    }
}

__kernel void arithm_bitwise_or_with_mask_C4_D2 (__global ushort *src1, int src1_step, int src1_offset,
                                          __global ushort *src2, int src2_step, int src2_offset,
                                          __global uchar  *mask, int mask_step, int mask_offset,
                                          __global ushort *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 3) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 3) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 3) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        ushort4 src_data1 = *((__global ushort4 *)((__global char *)src1 + src1_index));
        ushort4 src_data2 = *((__global ushort4 *)((__global char *)src2 + src2_index));
        ushort4 dst_data  = *((__global ushort4 *)((__global char *)dst  + dst_index));

        ushort4 data = src_data1 | src_data2;
994
        data = mask_data ? data : dst_data;
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022

        *((__global ushort4 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C4_D3 (__global short *src1, int src1_step, int src1_offset,
                                          __global short *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global short *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 3) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 3) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 3) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        short4 src_data1 = *((__global short4 *)((__global char *)src1 + src1_index));
        short4 src_data2 = *((__global short4 *)((__global char *)src2 + src2_index));
        short4 dst_data  = *((__global short4 *)((__global char *)dst  + dst_index));

        short4 data = src_data1 | src_data2;
1023
        data = mask_data ? data : dst_data;
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051

        *((__global short4 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C4_D4 (__global int   *src1, int src1_step, int src1_offset,
                                          __global int   *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global int   *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 4) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 4) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 4) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        int4 src_data1 = *((__global int4 *)((__global char *)src1 + src1_index));
        int4 src_data2 = *((__global int4 *)((__global char *)src2 + src2_index));
        int4 dst_data  = *((__global int4 *)((__global char *)dst  + dst_index));

        int4 data = src_data1 | src_data2;
1052
        data = mask_data ? data : dst_data;
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080

        *((__global int4 *)((__global char *)dst + dst_index)) = data;
    }
}
__kernel void arithm_bitwise_or_with_mask_C4_D5 (__global char *src1, int src1_step, int src1_offset,
                                          __global char *src2, int src2_step, int src2_offset,
                                          __global uchar *mask, int mask_step, int mask_offset,
                                          __global char *dst,  int dst_step,  int dst_offset,
                                          int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 4) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 4) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 4) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char16 src_data1 = *((__global char16 *)((__global char *)src1 + src1_index));
        char16 src_data2 = *((__global char16 *)((__global char *)src2 + src2_index));
        char16 dst_data  = *((__global char16 *)((__global char *)dst  + dst_index));

        char16 data = src_data1 | src_data2;
1081
        data = mask_data ? data : dst_data;
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125

        *((__global char16 *)((__global char *)dst + dst_index)) = data;
    }
}
#if defined (DOUBLE_SUPPORT)
__kernel void arithm_bitwise_or_with_mask_C4_D6 (__global char *src1, int src1_step, int src1_offset,
                                                  __global char *src2, int src2_step, int src2_offset,
                                                  __global uchar  *mask, int mask_step, int mask_offset,
                                                  __global char *dst,  int dst_step,  int dst_offset,
                                                  int rows, int cols, int dst_step1)
{

    int x = get_global_id(0);
    int y = get_global_id(1);

    if (x < cols && y < rows)
    {
        int src1_index = mad24(y, src1_step, (x << 5) + src1_offset);
        int src2_index = mad24(y, src2_step, (x << 5) + src2_offset);
        int mask_index = mad24(y, mask_step,  x       + mask_offset);
        int dst_index  = mad24(y, dst_step,  (x << 5) + dst_offset);

        uchar mask_data = *(mask + mask_index);

        char8 src_data1_0 = *((__global char8 *)((__global char *)src1 + src1_index + 0));
        char8 src_data1_1 = *((__global char8 *)((__global char *)src1 + src1_index + 8));
        char8 src_data1_2 = *((__global char8 *)((__global char *)src1 + src1_index + 16));
        char8 src_data1_3 = *((__global char8 *)((__global char *)src1 + src1_index + 24));

        char8 src_data2_0 = *((__global char8 *)((__global char *)src2 + src2_index + 0));
        char8 src_data2_1 = *((__global char8 *)((__global char *)src2 + src2_index + 8));
        char8 src_data2_2 = *((__global char8 *)((__global char *)src2 + src2_index + 16));
        char8 src_data2_3 = *((__global char8 *)((__global char *)src2 + src2_index + 24));

        char8 dst_data_0  = *((__global char8 *)((__global char *)dst  + dst_index + 0));
        char8 dst_data_1  = *((__global char8 *)((__global char *)dst  + dst_index + 8));
        char8 dst_data_2  = *((__global char8 *)((__global char *)dst  + dst_index + 16));
        char8 dst_data_3  = *((__global char8 *)((__global char *)dst  + dst_index + 24));

        char8 data_0 = src_data1_0 | src_data2_0;
        char8 data_1 = src_data1_1 | src_data2_1;
        char8 data_2 = src_data1_2 | src_data2_2;
        char8 data_3 = src_data1_3 | src_data2_3;

1126 1127 1128 1129
        data_0 = mask_data ? data_0 : dst_data_0;
        data_1 = mask_data ? data_1 : dst_data_1;
        data_2 = mask_data ? data_2 : dst_data_2;
        data_3 = mask_data ? data_3 : dst_data_3;
1130 1131 1132 1133 1134 1135 1136 1137

        *((__global char8 *)((__global char *)dst + dst_index + 0)) = data_0;
        *((__global char8 *)((__global char *)dst + dst_index + 8)) = data_1;
        *((__global char8 *)((__global char *)dst + dst_index + 16)) = data_2;
        *((__global char8 *)((__global char *)dst + dst_index + 24)) = data_3;
    }
}
#endif