[qfcc] Get scalar promotion working again

The cleanup of the scalar expressions lost the type promotion so using
ints in expressions didn't always work.
This commit is contained in:
Bill Currie 2023-08-23 21:51:01 +09:00
parent d7bab4e222
commit da1b797cb7

View file

@ -266,7 +266,7 @@ component_sum (int op, expr_t **c, expr_t **a, expr_t **b,
} }
static expr_t * static expr_t *
scale_expr (expr_t *a, expr_t *b) scale_expr (expr_t *a, expr_t *b, algebra_t *algebra)
{ {
if (!is_scalar (get_type (b))) { if (!is_scalar (get_type (b))) {
auto t = a; auto t = a;
@ -276,6 +276,11 @@ scale_expr (expr_t *a, expr_t *b)
auto scale_type = get_type (a); auto scale_type = get_type (a);
int op = is_scalar (scale_type) ? '*' : SCALE; int op = is_scalar (scale_type) ? '*' : SCALE;
if (is_scalar (scale_type)) {
a = promote_scalar (algebra->type, a);
}
b = promote_scalar (algebra->type, b);
auto scale = new_binary_expr (op, a, b); auto scale = new_binary_expr (op, a, b);
scale->e.expr.type = scale_type; scale->e.expr.type = scale_type;
return fold_constants (scale); return fold_constants (scale);
@ -296,7 +301,7 @@ typedef void (*pga3_wedge) (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg);
static void static void
scale_component (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg) scale_component (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
{ {
auto scale = scale_expr (a, b); auto scale = scale_expr (a, b, alg);
int group = get_group (get_type (scale), alg); int group = get_group (get_type (scale), alg);
c[group] = scale; c[group] = scale;
} }
@ -313,7 +318,8 @@ pga3_x_y_z_w_wedge_x_y_z_w (expr_t **c, expr_t *a, expr_t *b, algebra_t *alg)
auto sb = new_offset_alias_expr (stype, b, 3); auto sb = new_offset_alias_expr (stype, b, 3);
c[1] = new_binary_expr (CROSS, va, vb); c[1] = new_binary_expr (CROSS, va, vb);
c[1]->e.expr.type = algebra_mvec_type (alg, 0x02); c[1]->e.expr.type = algebra_mvec_type (alg, 0x02);
c[3] = new_binary_expr ('-', scale_expr (vb, sa), scale_expr (va, sb)); c[3] = new_binary_expr ('-', scale_expr (vb, sa, alg),
scale_expr (va, sb, alg));
c[3]->e.expr.type = wedge_type; c[3]->e.expr.type = wedge_type;
} }