[VENTUS][fix] Correct edge-case logic for integer to float rounding (#190)
The conversion script previously applied a complex saturation check to all integer-to-float conversions using the _rtz and _rtn rounding modes. This logic is only necessary for `int` and `uint` to `float` conversions, where precision loss near the maximum value can occur. It was incorrectly applied to other types like `long` or `char`, and to conversions targeting `double`. This commit refines the conditional logic to ensure this specific check is now applied only to the four intended cases: - int -> float (_rtz/_rtn) - uint -> float (_rtz/_rtn)
This commit is contained in:
parent
d12d13ec8b
commit
64d0deb8ce
|
@ -445,12 +445,18 @@ def generate_float_conversion(src, dst, size, mode, sat):
|
||||||
USRC=unsigned_type[src], N=size
|
USRC=unsigned_type[src], N=size
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# For integer sources, check for saturation case
|
if dst == "float" and src in ["int", "uint"]:
|
||||||
print(
|
print(
|
||||||
" return select(r, nextafter(r, sign(r) * ({DST}{N})-INFINITY), convert_{BOOL}{N}(abs_y > abs_x || (abs_y == abs_x && abs_y == ({USRC}{N}){SRC_MAX})));".format(
|
" return select(r, nextafter(r, sign(r) * ({DST}{N})-INFINITY), convert_{BOOL}{N}(abs_y > abs_x || (abs_y == abs_x && abs_y == ({USRC}{N}){SRC_MAX})));".format(
|
||||||
DST=dst, N=size, BOOL=bool_type[dst], USRC=unsigned_type[src], SRC_MAX=limit_max[src]
|
DST=dst, N=size, BOOL=bool_type[dst], USRC=unsigned_type[src], SRC_MAX=limit_max[src]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
" 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]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
print(" {SRC}{N} abs_x = fabs(x);".format(SRC=src, N=size))
|
print(" {SRC}{N} abs_x = fabs(x);".format(SRC=src, N=size))
|
||||||
print(" {SRC}{N} abs_y = fabs(y);".format(SRC=src, N=size))
|
print(" {SRC}{N} abs_y = fabs(y);".format(SRC=src, N=size))
|
||||||
|
@ -467,15 +473,19 @@ def generate_float_conversion(src, dst, size, mode, sat):
|
||||||
)
|
)
|
||||||
if mode == "_rtn":
|
if mode == "_rtn":
|
||||||
if src in int_types:
|
if src in int_types:
|
||||||
# For integer sources, check for saturation case when converting back
|
if dst == "float" and src in ["int", "uint"]:
|
||||||
# Cast the constant to source type to match vector element type
|
print(
|
||||||
print(
|
" return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x || (y == x && y == ({SRC}{N}){SRC_MAX})));".format(
|
||||||
" return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x || (y == x && y == ({SRC}{N}){SRC_MAX})));".format(
|
DST=dst, N=size, BOOL=bool_type[dst], SRC=src, SRC_MAX=limit_max[src]
|
||||||
DST=dst, N=size, BOOL=bool_type[dst], SRC=src, SRC_MAX=limit_max[src]
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
" return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x));".format(
|
||||||
|
DST=dst, N=size, BOOL=bool_type[dst]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# For float sources, use original logic
|
|
||||||
print(
|
print(
|
||||||
" return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x));".format(
|
" return select(r, nextafter(r, ({DST}{N})-INFINITY), convert_{BOOL}{N}(y > x));".format(
|
||||||
DST=dst, N=size, BOOL=bool_type[dst]
|
DST=dst, N=size, BOOL=bool_type[dst]
|
||||||
|
|
Loading…
Reference in New Issue