@@ -9,43 +9,81 @@ SPDX-License-Identifier: MIT
9
9
#include "../include/BiF_Definitions.cl"
10
10
#include "../../Headers/spirv.h"
11
11
12
+ // Bitselect can be implemented with the following boolean function:
13
+ // s0 & s1 | ~s0 & s2
14
+ // where s0 = c, s1 = b, s2 = a
15
+ // This maps to boolean function 0xD8.
12
16
13
17
INLINE
14
18
char SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN (bitselect , _i8_i8_i8 , )( char a , char b , char c )
15
19
{
16
- char temp ;
17
- temp = (c & b ) | (~c & a );
18
- return temp ;
20
+ if (BIF_FLAG_CTRL_GET (UseBfn ))
21
+ {
22
+ return (char ) __builtin_IB_bfn_i16 ((short )as_uchar (c ), (short )as_uchar (b ), (short )as_uchar (a ), 0xD8 );
23
+ }
24
+ else
25
+ {
26
+ char temp ;
27
+ temp = (c & b ) | (~c & a );
28
+ return temp ;
29
+ }
19
30
}
20
31
21
32
GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS ( bitselect , char , char , i8 )
22
33
23
34
INLINE
24
35
short SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN (bitselect , _i16_i16_i16 , )( short a , short b , short c )
25
36
{
26
- short temp ;
27
- temp = (c & b ) | (~c & a );
28
- return temp ;
37
+ if (BIF_FLAG_CTRL_GET (UseBfn ))
38
+ {
39
+ return __builtin_IB_bfn_i16 (c , b , a , 0xD8 );
40
+ }
41
+ else
42
+ {
43
+ short temp ;
44
+ temp = (c & b ) | (~c & a );
45
+ return temp ;
46
+ }
29
47
}
30
48
31
49
GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS ( bitselect , short , short , i16 )
32
50
33
51
INLINE
34
52
int SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN (bitselect , _i32_i32_i32 , )( int a , int b , int c )
35
53
{
36
- int temp ;
37
- temp = (c & b ) | (~c & a );
38
- return temp ;
54
+ if (BIF_FLAG_CTRL_GET (UseBfn ))
55
+ {
56
+ return __builtin_IB_bfn_i32 (c , b , a , 0xD8 );
57
+ }
58
+ else
59
+ {
60
+ int temp ;
61
+ temp = (c & b ) | (~c & a );
62
+ return temp ;
63
+ }
39
64
}
40
65
41
66
GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS ( bitselect , int , int , i32 )
42
67
43
68
INLINE
44
69
long SPIRV_OVERLOADABLE SPIRV_OCL_BUILTIN (bitselect , _i64_i64_i64 , )( long a , long b , long c )
45
70
{
46
- long temp ;
47
- temp = (c & b ) | (~c & a );
48
- return temp ;
71
+ if (BIF_FLAG_CTRL_GET (UseBfn ))
72
+ {
73
+ int2 tmpA = as_int2 (a );
74
+ int2 tmpB = as_int2 (b );
75
+ int2 tmpC = as_int2 (c );
76
+ int2 tmpResult ;
77
+ tmpResult .s0 = __builtin_IB_bfn_i32 (tmpC .s0 , tmpB .s0 , tmpA .s0 , 0xD8 );
78
+ tmpResult .s1 = __builtin_IB_bfn_i32 (tmpC .s1 , tmpB .s1 , tmpA .s1 , 0xD8 );
79
+ return as_long (tmpResult );
80
+ }
81
+ else
82
+ {
83
+ long temp ;
84
+ temp = (c & b ) | (~c & a );
85
+ return temp ;
86
+ }
49
87
}
50
88
51
89
GENERATE_SPIRV_OCL_VECTOR_FUNCTIONS_3ARGS ( bitselect , long , long , i64 )
0 commit comments