On 1/19/22 12:30, Francisco Casas wrote:
- struct hlsl_ir_constant *src1, struct hlsl_ir_constant *src2)
+{
- enum hlsl_base_type type = tgt->node.data_type->base_type;
- uint32_t u1, u2;
- assert(type == src1->node.data_type->base_type);
- assert(type == src2->node.data_type->base_type);
- for (int k = 0; k < 4; k++)
- {
- switch (type)
- {
- case HLSL_TYPE_FLOAT:
- case HLSL_TYPE_HALF:
- tgt->value[k].f = src1->value[k].f + src2->value[k].f;
- break;
- case HLSL_TYPE_DOUBLE:
- tgt->value[k].d = src1->value[k].d + src2->value[k].d;
- break;
- case HLSL_TYPE_INT:
- u1 = src1->value[k].i;
- u2 = src2->value[k].i;
- tgt->value[k].i = (int32_t)(u1 + u2);
- break;
It seems simpler just to fall through to the next case.
That's clever, but maybe too clever! While it should work, I am inclined to leave it as it is, for readability and for having the peace of mind that it won't surprise us in the future.
We would have to remember to keep hlsl_constant_value as a union and, for instance, I have the same concern as this person: https://stackoverflow.com/questions/11373203/accessing-inactive-union-member... and the answers don't seem conclusive.
Type punning is allowed, and if int32_t can't be correctly reinterpreted as uint32_t we have bigger problems.