Skip to content

Commit 67e347f

Browse files
committed
libclc: clspv: create gen_convert.cl for clspv
Create clspv own convert.cl This is needed as Vulkan SPIR-V does not respect the assumptions needed to have the generic convert.cl compliant on many platforms. It is needed because of the conversion of TYPE_MAX and TYPE_MIN. Depending on the platform the behaviour can vary, but most of them just do not convert correctly those 2 values. Because of that, we also need to avoid having explicit function for simple conversions because it allows llvm to optimise the code, thus removing some of the added checks that are in fact needed. Here are the differences between this new gen_convert.cl and the one in generic: ``` 4a5 > # Copyright (c) 2023 Romaric Jodin <[email protected]> 144a146 > Copyright (c) 2023 Romaric Jodin <[email protected]> 254,257d255 < for src in types: < for dst in types: < generate_default_conversion(src, dst, "") < 260a259,260 > if mode == "_rte": > continue 310,311c310,311 < y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS}); < y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS}); --- > y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS}); > y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS}); 435c435 < print(" {SRC}{N} y = convert_{SRC}{N}(r);".format(SRC=src, N=size)) --- > print(" {SRC}{N} y = convert_{SRC}{N}_sat(r);".format(SRC=src, N=size)) 450a451,457 > print(" {BOOL}{N} c = convert_{BOOL}{N}(abs_y > abs_x);".format(BOOL=bool_type[dst], N=size)) > if sizeof_type[src] >= 4 and src in int_types: > print( > " c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == x);".format( > BOOL=bool_type[dst], N=size, SRC=src, SRC_MAX=limit_max[src] > ) > ) 452,453c459,460 < " return select(r, nextafter(r, sign(r) * ({DST}{N})-INFINITY), convert_{BOOL}{N}(abs_y > abs_x));".format( < DST=dst, N=size, BOOL=bool_type[dst] --- > " return select(r, nextafter(r, sign(r) * ({DST}{N})-INFINITY), c);".format( > DST=dst, N=size, BOOL=bool_type[dst], SRC=src 462a470,476 > print(" {BOOL}{N} c = convert_{BOOL}{N}(y > x);".format(BOOL=bool_type[dst], N=size)) > if sizeof_type[src] >= 4 and src in int_types: > print( > " c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == x);".format( > BOOL=bool_type[dst], N=size, SRC=src, SRC_MAX=limit_max[src] > ) > ) 464,465c478,479 < " return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x));".format( < DST=dst, N=size, BOOL=bool_type[dst] --- > " return select(r, nextafter(r, ({DST}{N})-INFINITY), c);".format( > DST=dst, N=size, BOOL=bool_type[dst], SRC=src 486a501,502 > if mode == "_rte": > continue ```
1 parent b83a1ed commit 67e347f

File tree

2 files changed

+522
-2
lines changed

2 files changed

+522
-2
lines changed

libclc/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ add_custom_command(
176176
DEPENDS ${script_loc} )
177177
add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
178178

179+
file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/clspv/lib/gen_convert.py script_loc )
180+
add_custom_command(
181+
OUTPUT clspv-convert.cl
182+
COMMAND ${Python3_EXECUTABLE} ${script_loc} > clspv-convert.cl
183+
DEPENDS ${script_loc} )
184+
add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
185+
179186
enable_testing()
180187

181188
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -220,11 +227,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
220227
# Add the generated convert.cl here to prevent adding
221228
# the one listed in SOURCES
222229
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
223-
set( rel_files convert.cl )
224-
set( objects convert.cl )
225230
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL "clspv" AND
226231
NOT ${ARCH} STREQUAL "clspv64" )
232+
set( rel_files convert.cl )
233+
set( objects convert.cl )
227234
list( APPEND rel_files generic/lib/subnormal_use_default.ll )
235+
elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
236+
set( rel_files clspv-convert.cl )
237+
set( objects clspv-convert.cl )
228238
endif()
229239
else()
230240
set( rel_files )
@@ -288,6 +298,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
288298
# multiple invocations
289299
add_dependencies( builtins.link.${arch_suffix}
290300
generate_convert.cl )
301+
add_dependencies( builtins.link.${arch_suffix}
302+
clspv-generate_convert.cl )
291303
# CMake will turn this include into absolute path
292304
target_include_directories( builtins.link.${arch_suffix} PRIVATE
293305
"generic/include" )

0 commit comments

Comments
 (0)