File: bitselect.cl

package info (click to toggle)
intel-graphics-compiler2 2.28.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792,744 kB
  • sloc: cpp: 5,761,745; ansic: 466,928; lisp: 312,143; python: 114,790; asm: 44,736; pascal: 10,930; sh: 8,033; perl: 7,914; ml: 3,625; awk: 3,523; yacc: 2,747; javascript: 2,667; lex: 1,898; f90: 1,028; cs: 573; xml: 474; makefile: 344; objc: 162
file content (131 lines) | stat: -rw-r--r-- 3,460 bytes parent folder | download
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
68
69
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*========================== begin_copyright_notice ============================

Copyright (C) 2017-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#include "../include/BiF_Definitions.cl"
#include "../../Headers/spirv.h"

// Bitselect can be implemented with the following boolean function:
//   s0 & s1 | ~s0 & s2
// where s0 = c, s1 = b, s2 = a
// This maps to boolean function 0xD8.

INLINE
char __attribute__((overloadable)) __spirv_ocl_bitselect( char a, char b, char c )
{
    if (BIF_FLAG_CTRL_GET(UseBfn))
    {
        return (char) __builtin_IB_bfn_i16((short)as_uchar(c), (short)as_uchar(b), (short)as_uchar(a), 0xD8);
    }
    else
    {
        char temp;
        temp = (c & b) | (~c & a);
        return temp;
    }
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, char, char, i8 )

INLINE
short __attribute__((overloadable)) __spirv_ocl_bitselect( short a, short b, short c )
{
    if (BIF_FLAG_CTRL_GET(UseBfn))
    {
        return __builtin_IB_bfn_i16(c, b, a, 0xD8);
    }
    else
    {
        short temp;
        temp = (c & b) | (~c & a);
        return temp;
    }
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, short, short, i16 )

INLINE
int __attribute__((overloadable)) __spirv_ocl_bitselect( int a, int b, int c )
{
    if (BIF_FLAG_CTRL_GET(UseBfn))
    {
        return __builtin_IB_bfn_i32(c, b, a, 0xD8);
    }
    else
    {
        int temp;
        temp = (c & b) | (~c & a);
        return temp;
    }
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, int, int, i32 )

INLINE
long __attribute__((overloadable)) __spirv_ocl_bitselect( long a, long b, long c )
{
    if (BIF_FLAG_CTRL_GET(UseBfn))
    {
        int2 tmpA = as_int2(a);
        int2 tmpB = as_int2(b);
        int2 tmpC = as_int2(c);
        int2 tmpResult;
        tmpResult.s0 = __builtin_IB_bfn_i32(tmpC.s0, tmpB.s0, tmpA.s0, 0xD8);
        tmpResult.s1 = __builtin_IB_bfn_i32(tmpC.s1, tmpB.s1, tmpA.s1, 0xD8);
        return as_long(tmpResult);
    }
    else
    {
        long temp;
        temp = (c & b) | (~c & a);
        return temp;
    }
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, long, long, i64 )

INLINE
float __attribute__((overloadable)) __spirv_ocl_bitselect( float a, float b, float c )
{
    return as_float( __spirv_ocl_bitselect(as_int(a), as_int(b), as_int(c)) );
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, float, float, f32 )

#if defined(cl_khr_fp64)

INLINE
double __attribute__((overloadable)) __spirv_ocl_bitselect( double a, double b, double c )
{
    return as_double( __spirv_ocl_bitselect(as_long(a), as_long(b), as_long(c)) );
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, double, double, f64 )

#endif // defined(cl_khr_fp64)

#ifdef cl_khr_fp16

INLINE
half __attribute__((overloadable)) __spirv_ocl_bitselect( half a, half b, half c )
{
    return as_half( __spirv_ocl_bitselect(as_short(a), as_short(b), as_short(c)) );
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, half, half, f16 )

#endif

#if defined(IGC_SPV_INTEL_bfloat16_arithmetic)
INLINE
bfloat __attribute__((overloadable)) __spirv_ocl_bitselect( bfloat a, bfloat b, bfloat c )
{
    return as_bfloat( __spirv_ocl_bitselect(as_short(a), as_short(b), as_short(c)) );
}

GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS( bitselect, bfloat, bfloat, )
#endif // defined(IGC_SPV_INTEL_bfloat16_arithmetic)