1
1
# This file contains common variables and helper functions used by the
2
2
# `gen_convert.py` in both the libclc and libspirv libraries.
3
3
4
- types = ['char' , 'uchar' , 'short' , 'ushort' , 'int' , 'uint' , 'long' , 'ulong' , 'float' , 'double' ]
5
- int_types = ['char' , 'uchar' , 'short' , 'ushort' , 'int' , 'uint' , 'long' , 'ulong' ]
4
+ types = ['char' , 'schar' , ' uchar' , 'short' , 'ushort' , 'int' , 'uint' , 'long' , 'ulong' , 'half ' , 'float' , 'double' ]
5
+ int_types = ['char' , 'schar' , ' uchar' , 'short' , 'ushort' , 'int' , 'uint' , 'long' , 'ulong' ]
6
6
unsigned_types = ['uchar' , 'ushort' , 'uint' , 'ulong' ]
7
- signed_types = ['char' , 'short' , 'int' , 'long' ]
8
- float_types = ['float' , 'double' ]
7
+ signed_types = ['char' , 'schar' , ' short' , 'int' , 'long' ]
8
+ float_types = ['half' , ' float' , 'double' ]
9
9
int64_types = ['long' , 'ulong' ]
10
10
float64_types = ['double' ]
11
+ float16_types = ['half' ]
11
12
vector_sizes = ['' , '2' , '3' , '4' , '8' , '16' ]
12
- half_sizes = { '2' : '' , '4' : '2' , '8' : '4' , '16' : '8' }
13
+ half_sizes = [( '2' , '' ), ( '4' , '2' ), ( '8' , '4' ), ( '16' , '8' )]
13
14
14
15
saturation = ['' ,'_sat' ]
15
16
rounding_modes = ['_rtz' ,'_rte' ,'_rtp' ,'_rtn' ]
16
17
float_prefix = {'float' :'FLT_' , 'double' :'DBL_' }
17
18
float_suffix = {'float' :'f' , 'double' :'' }
18
19
19
- bool_type = {'char' : 'char' ,
20
- 'uchar' : 'char' ,
21
- 'short' : 'short' ,
22
- 'ushort' : 'short' ,
23
- 'int' : 'int' ,
24
- 'uint' : 'int' ,
25
- 'long' : 'long' ,
26
- 'ulong' : 'long' ,
20
+ bool_type = {'char' : 'char' ,
21
+ 'schar' : 'schar' ,
22
+ 'uchar' : 'schar' ,
23
+ 'short' : 'short' ,
24
+ 'ushort' : 'short' ,
25
+ 'int' : 'int' ,
26
+ 'uint' : 'int' ,
27
+ 'long' : 'long' ,
28
+ 'ulong' : 'long' ,
29
+ 'half' : 'short' ,
27
30
'float' : 'int' ,
28
31
'double' : 'long' }
29
32
30
33
unsigned_type = {'char' : 'uchar' ,
34
+ 'schar' : 'uchar' ,
31
35
'uchar' : 'uchar' ,
32
36
'short' : 'ushort' ,
33
37
'ushort' : 'ushort' ,
36
40
'long' : 'ulong' ,
37
41
'ulong' : 'ulong' }
38
42
39
- sizeof_type = {'char' : 1 , 'uchar' : 1 ,
43
+ sizeof_type = {'char' : 1 , 'schar' : 1 , ' uchar' : 1 ,
40
44
'short' : 2 , 'ushort' : 2 ,
41
45
'int' : 4 , 'uint' : 4 ,
42
46
'long' : 8 , 'ulong' : 8 ,
43
- 'float' : 4 , 'double' : 8 }
47
+ 'half' : 2 , 'float' : 4 ,
48
+ 'double' : 8 }
44
49
45
50
limit_max = {'char' : 'CHAR_MAX' ,
51
+ 'schar' : 'CHAR_MAX' ,
46
52
'uchar' : 'UCHAR_MAX' ,
47
53
'short' : 'SHRT_MAX' ,
48
54
'ushort' : 'USHRT_MAX' ,
52
58
'ulong' : 'ULONG_MAX' }
53
59
54
60
limit_min = {'char' : 'CHAR_MIN' ,
61
+ 'schar' : 'CHAR_MIN' ,
55
62
'uchar' : '0' ,
56
63
'short' : 'SHRT_MIN' ,
57
64
'ushort' : '0' ,
@@ -70,55 +77,35 @@ def conditional_guard(src, dst):
70
77
"""
71
78
int64_count = 0
72
79
float64_count = 0
73
- if src in int64_types :
74
- int64_count = int64_count + 1
75
- elif src in float64_types :
76
- float64_count = float64_count + 1
77
- if dst in int64_types :
78
- int64_count = int64_count + 1
79
- elif dst in float64_types :
80
- float64_count = float64_count + 1
80
+ float16_count = 0
81
+ if src in int64_types or dst in int64_types :
82
+ int64_count = 1
83
+ if src in float64_types or dst in float64_types :
84
+ float64_count = 1
85
+ if src in float16_types or dst in float16_types :
86
+ float16_count = 1
87
+ if float16_count > 0 :
88
+ print ("#ifdef cl_khr_fp16" )
81
89
if float64_count > 0 :
82
90
#In embedded profile, if cl_khr_fp64 is supported cles_khr_int64 has to be
83
91
print ("#ifdef cl_khr_fp64" )
84
- return True
92
+ return 1 + float16_count
85
93
elif int64_count > 0 :
86
94
print ("#if defined cles_khr_int64 || !defined(__EMBEDDED_PROFILE__)" )
87
- return True
88
- return False
95
+ return 1 + float16_count
96
+ return float16_count
89
97
90
-
91
-
92
- def spirv_fn_name (src , dst , size = '' , mode = '' , sat = '' ):
98
+ def close_conditional_guard (close_conditional ):
93
99
"""
94
- This helper function returns the correct SPIR-V function name for a given source and destination
95
- type, with optional size, mode and saturation arguments.
100
+ This function will close conditional guard opened by conditional_guard.
96
101
"""
97
- is_src_float = src in float_types
98
- is_src_unsigned = src in unsigned_types
99
- is_src_signed = src in signed_types
100
- is_dst_float = dst in float_types
101
- is_dst_unsigned = dst in unsigned_types
102
- is_dst_signed = dst in signed_types
103
- is_sat = sat != ''
102
+ for _ in range (close_conditional ):
103
+ print ("#endif" )
104
104
105
- if is_src_unsigned and is_dst_signed and is_sat :
106
- return '__spirv_SatConvertUToS_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
107
- elif is_src_signed and is_dst_unsigned and is_sat :
108
- return '__spirv_SatConvertSToU_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
109
- elif is_src_float and is_dst_signed :
110
- return '__spirv_ConvertFToS_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
111
- elif is_src_float and is_dst_unsigned :
112
- return '__spirv_ConvertFToU_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
113
- elif is_src_signed and is_dst_float :
114
- return '__spirv_ConvertSToF_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
115
- elif is_src_unsigned and is_dst_float :
116
- return '__spirv_ConvertUToF_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
117
- elif is_src_float and is_dst_float :
118
- return '__spirv_FConvert_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
119
- elif is_src_unsigned and is_dst_unsigned :
120
- return '__spirv_UConvert_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
121
- elif is_src_signed and is_dst_signed :
122
- return '__spirv_SConvert_R{DST}{N}{MODE}' .format (DST = dst , N = size , MODE = mode )
123
- else :
124
- return None
105
+ def clc_core_fn_name (dst , size = '' , mode = '' , sat = '' ):
106
+ """
107
+ This helper function returns the correct clc core conversion function name
108
+ for a given source and destination type, with optional size, mode
109
+ and saturation arguments.
110
+ """
111
+ return "__clc_convert_{DST}{N}{SAT}{MODE}" .format (DST = dst , N = size , SAT = sat , MODE = mode )
0 commit comments