From b0460de935e2aba35acebf9f5b6184f2e2ab3337 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Wed, 31 Jul 2013 11:48:43 +0000 Subject: [PATCH 1/1] Fold for div op --- fold.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fold.c b/fold.c index c7abaeb..98e854e 100644 --- a/fold.c +++ b/fold.c @@ -357,6 +357,22 @@ static GMQCC_INLINE ast_expression *fold_op_mul(fold_t *fold, ast_value *a, ast_ return NULL; } +static GMQCC_INLINE ast_expression *fold_op_div(fold_t *fold, ast_value *a, ast_value *b) { + if (isfloatonly(a)) { + return (fold_possible(a) && fold_possible(b)) + ? fold_constgen_float(fold, fold_immvalue_float(a) / fold_immvalue_float(b)) + : NULL; + } + + if (isvectoronly(a)) { + if (fold_possible(a) && fold_possible(b)) + return fold_constgen_vector(fold, vec3_mulvf(fold_immvalue_vector(a), 1.0f / fold_immvalue_float(b))); + else if (fold_possible(b)) + return fold_constgen_float (fold, 1.0f / fold_immvalue_float(b)); + } + return NULL; +} + ast_expression *fold_op(fold_t *fold, const oper_info *info, ast_expression **opexprs) { ast_value *a = (ast_value*)opexprs[0]; ast_value *b = (ast_value*)opexprs[1]; @@ -423,7 +439,7 @@ ast_expression *fold_op(fold_t *fold, const oper_info *info, ast_expression **op : NULL; case opid1('*'): return fold_op_mul(fold, a, b); - case opid1('/'): + case opid1('/'): return fold_op_div(fold, a, b); /* TODO: seperate function for this case */ return NULL; case opid2('|','|'): -- 2.39.2