On Tue Dec 13 19:03:45 2022 +0000, Francisco Casas wrote:
`elementwise_intrinsic_convert_args()` converts all arguments to the same common type by means of:
- Ensuring that matrices and vectors are not used at the same time as arguments.
- Truncating vector (or matrix) arguments to the common shape.
- Converting all arguments base type to the common base type.
without knowing of the intrinsic where it is used. So it may be the case that this common type has base-type `int` if all the provided arguments have base-type `int`. I did it this way because it is my understanding that not all intrinsic functions always return a `float` if all arguments are `int`, so it is responsibility of the function to do this conversion. This often can be done converting the base-type of a single argument to float and let the uses of `add_binary_arithmetic_expr` propagate this conversion. It gets a little more complicated with intrinsics that take 3 arguments though such as `smoothstep()`, though. It seems that indeed I can remove the calls to `expr_common_shape()` and some of the calls to `add_implicit_conversion()` here, or add a `bool convert_to_float` argument to `elementwise_intrinsic_convert_args()`. I will give it more thought, maybe I can write a shader to test where in the implementation of `smoothstep()` the conversion of `int` args to float takes place.
In the end I went for adding the `bool convert_to_float` to `elementwise_intrinsic_convert_args()`.
Also, I checked the native compiler's output on all the intrinsics that use this function, while passing only uniform int args, to see if there is an `itof` that converts all arguments to `float`, to know when to set this `convert_to_float` to true.