From 83fb5887273fa9d9900ff966801a66c5ecdf7d53 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 10 Jun 2019 08:44:36 +0900 Subject: [PATCH] Support vector/quaternion division by float Implemented via v*(1/f) or q*(1/f) to give CSE a chance to optimize the division if necessary as otherwise the engine would have to divide every time. --- tools/qfcc/source/expr_binary.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/qfcc/source/expr_binary.c b/tools/qfcc/source/expr_binary.c index d53d3677c..2029726af 100644 --- a/tools/qfcc/source/expr_binary.c +++ b/tools/qfcc/source/expr_binary.c @@ -46,6 +46,7 @@ typedef struct { } expr_type_t; static expr_t *pointer_arithmetic (int op, expr_t *e1, expr_t *e2); +static expr_t *inverse_multiply (int op, expr_t *e1, expr_t *e2); static expr_type_t string_string[] = { {'+', &type_string}, @@ -85,7 +86,7 @@ static expr_type_t float_vector[] = { static expr_type_t float_quat[] = { {'*', &type_quaternion}, - {'/', &type_quaternion}, + {'/', 0, 0, 0, inverse_multiply}, {0, 0} }; @@ -113,7 +114,7 @@ static expr_type_t float_integer[] = { static expr_type_t vector_float[] = { {'*', &type_vector}, - {'/', &type_vector}, + {'/', 0, 0, 0, inverse_multiply}, {0, 0} }; @@ -601,6 +602,15 @@ pointer_arithmetic (int op, expr_t *e1, expr_t *e2) return cast_expr (ptype, e); } +static expr_t * +inverse_multiply (int op, expr_t *e1, expr_t *e2) +{ + // There is no vector/float or quaternion/float instruction and adding + // one would mean the engine would have to do 1/f every time + expr_t *one = new_float_expr (1); + return binary_expr ('*', e1, binary_expr ('/', one, e2)); +} + static expr_t * invalid_binary_expr (int op, expr_t *e1, expr_t *e2) {