mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-24 04:41:25 +00:00
constant-fold the 1/N division from a_vector/N
This commit is contained in:
parent
a5029a510a
commit
ab8cc64dfd
1 changed files with 17 additions and 7 deletions
12
parser.c
12
parser.c
|
@ -937,9 +937,13 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
||||||
if (CanConstFold(exprs[0], exprs[1]))
|
if (CanConstFold(exprs[0], exprs[1]))
|
||||||
out = (ast_expression*)parser_const_vector(parser, vec3_mulvf(ConstV(0), 1.0/ConstF(1)));
|
out = (ast_expression*)parser_const_vector(parser, vec3_mulvf(ConstV(0), 1.0/ConstF(1)));
|
||||||
else {
|
else {
|
||||||
|
if (CanConstFold1(exprs[1])) {
|
||||||
|
out = (ast_expression*)parser_const_float(parser, 1.0 / ConstF(1));
|
||||||
|
} else {
|
||||||
out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
|
out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
|
||||||
(ast_expression*)parser_const_float_1(parser),
|
(ast_expression*)parser_const_float_1(parser),
|
||||||
exprs[1]);
|
exprs[1]);
|
||||||
|
}
|
||||||
if (!out) {
|
if (!out) {
|
||||||
compile_error(ctx, "internal error: failed to generate division");
|
compile_error(ctx, "internal error: failed to generate division");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1288,11 +1292,17 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
|
||||||
exprs[0], exprs[1]);
|
exprs[0], exprs[1]);
|
||||||
} else {
|
} else {
|
||||||
/* there's no DIV_VF */
|
/* there's no DIV_VF */
|
||||||
|
if (CanConstFold1(exprs[1])) {
|
||||||
|
out = (ast_expression*)parser_const_float(parser, 1.0 / ConstF(1));
|
||||||
|
} else {
|
||||||
out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
|
out = (ast_expression*)ast_binary_new(ctx, INSTR_DIV_F,
|
||||||
(ast_expression*)parser_const_float_1(parser),
|
(ast_expression*)parser_const_float_1(parser),
|
||||||
exprs[1]);
|
exprs[1]);
|
||||||
if (!out)
|
}
|
||||||
|
if (!out) {
|
||||||
|
compile_error(ctx, "internal error: failed to generate division");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_MUL_VF,
|
out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_MUL_VF,
|
||||||
exprs[0], out);
|
exprs[0], out);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue