Skip to content

Commit 6c2d418

Browse files
authored
[libclc] Fix int<->float conversion builtins (#126905)
While working on moving the conversion builtins to the CLC library in 25c0554 it was discovered that many weren't passing the OpenCL-CTS tests. As it happens, the clspv-specific code for conversion implementations between integer and floating-point types was more correct. However: * The clspv code was generating 'sat' conversions to floating-point types, which are not legal * The clspv code around rtn/rtz conversions needed tweaking as it wasn't validating when sizeof(dst) > sizeof(src), e.g., int -> double. With this commit, the CTS failures seen before have been resolved. This also assumes that the new implementations are correct also for clspv. If this is the case, then 'clc' and 'clspv' modes are mutually exclusive and we can simplify the build process for conversions by not building clc-clspv-convert.cl.
1 parent 7a9f53c commit 6c2d418

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

libclc/generic/lib/gen_convert.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,13 @@ def generate_saturated_conversion(src, dst, size):
369369

370370
elif src in float_types:
371371

372-
if clspv:
373-
# Conversion from float to int
374-
print(
375-
f""" {dstn} y = __clc_convert_{dstn}(x);
372+
# Conversion from float to int
373+
print(
374+
f""" {dstn} y = __clc_convert_{dstn}(x);
376375
y = __clc_select(y, ({dstn}){dst_min}, {bool_prefix}(x <= ({srcn}){dst_min}){bool_suffix});
377376
y = __clc_select(y, ({dstn}){dst_max}, {bool_prefix}(x >= ({srcn}){dst_max}){bool_suffix});
378377
return y;"""
379-
)
380-
else:
381-
# Conversion from float to int
382-
print(
383-
f""" {dstn} y = __clc_convert_{dstn}(x);
384-
y = __clc_select(y, ({dstn}){dst_min}, {bool_prefix}(x < ({srcn}){dst_min}){bool_suffix});
385-
y = __clc_select(y, ({dstn}){dst_max}, {bool_prefix}(x > ({srcn}){dst_max}){bool_suffix});
386-
return y;"""
387-
)
378+
)
388379
else:
389380

390381
# Integer to integer convesion with sizeof(src) == sizeof(dst)
@@ -494,7 +485,7 @@ def generate_float_conversion(src, dst, size, mode, sat):
494485
print(f" return __clc_convert_{dstn}(x);")
495486
else:
496487
print(f" {dstn} r = __clc_convert_{dstn}(x);")
497-
if clspv:
488+
if src in int_types:
498489
print(f" {srcn} y = __clc_convert_{srcn}_sat(r);")
499490
else:
500491
print(f" {srcn} y = __clc_convert_{srcn}(r);")
@@ -507,7 +498,7 @@ def generate_float_conversion(src, dst, size, mode, sat):
507498
print(f" {srcn} abs_x = __clc_fabs(x);")
508499
print(f" {srcn} abs_y = __clc_fabs(y);")
509500
print(f" {booln} c = __clc_convert_{booln}(abs_y > abs_x);")
510-
if clspv and sizeof_type[src] >= 4 and src in int_types:
501+
if sizeof_type[src] >= sizeof_type[dst] and src in int_types:
511502
print(f" c = c || __clc_convert_{booln}(({srcn}){src_max} == x);")
512503
print(
513504
f" {dstn} sel = __clc_select(r, __clc_nextafter(r, __clc_sign(r) * ({dstn})-INFINITY), c);"
@@ -533,7 +524,7 @@ def generate_float_conversion(src, dst, size, mode, sat):
533524
print(" return sel;")
534525
if mode == "_rtn":
535526
print(f" {booln} c = __clc_convert_{booln}(y > x);")
536-
if clspv and sizeof_type[src] >= 4 and src in int_types:
527+
if sizeof_type[src] >= sizeof_type[dst] and src in int_types:
537528
print(f" c = c || __clc_convert_{booln}(({srcn}){src_max} == x);")
538529
print(
539530
f" {dstn} sel = __clc_select(r, __clc_nextafter(r, ({dstn})-INFINITY), c);"

0 commit comments

Comments
 (0)