From d0db75779a7a67574cb53c4506bfcc893eea3e09 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 28 Nov 2024 21:11:09 +0900 Subject: [PATCH] [qfcc] Add a check for shifts and expand math ops I found a need to check for shifts separately (not sure it's the right approach for that problem, though), and there are a few more math ops than just +-*/. --- tools/qfcc/include/expr.h | 7 +++++++ tools/qfcc/source/expr.c | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 354295989..5c1a5709d 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -893,6 +893,13 @@ const expr_t *constant_expr (const expr_t *e); */ bool is_compare (int op) __attribute__((const)); +/** Check if the op-code is a bit-shift. + + \param op The op-code to check. + \return True if the op-code is a bit-shift operator. +*/ +bool is_shift (int op) __attribute__((const)); + /** Check if the op-code is a math operator. \param op The op-code to check. diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index e129aa488..31061342f 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -1900,11 +1900,25 @@ is_compare (int op) return false; } +bool +is_shift (int op) +{ + if (op == QC_SHL || op == QC_SHR) { + return true; + } + return false; +} + bool is_math_op (int op) { - if (op == '*' || op == '/' || op == '+' || op == '-') + if (op == '*' || op == '/' || op == '+' || op == '-' || op == '%' + || op == QC_MOD || op == QC_SCALE || op == QC_GEOMETRIC + || op == QC_QMUL || op == QC_QVMUL || op == QC_VQMUL + || op == QC_HADAMARD || op == QC_CROSS || op == QC_DOT + || op == QC_OUTER || op == QC_WEDGE || op == QC_REGRESSIVE) { return true; + } return false; }