diff options
author | Brian <[email protected]> | 2007-03-28 15:16:33 -0600 |
---|---|---|
committer | Brian <[email protected]> | 2007-03-28 15:16:33 -0600 |
commit | f2f5d06853f17bcbecf68ebb07c8cc19a2cfdeb5 (patch) | |
tree | 842f0be0c4a1a7bf40535c0816eab53210df9312 /src/mesa/shader/slang/slang_codegen.c | |
parent | b2ac30ac36c66122d6d8a73e7057a84b74c3d930 (diff) |
Handle logical NOT and XOR without library functions. Results in much tighter code.
Diffstat (limited to 'src/mesa/shader/slang/slang_codegen.c')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index 6350dff06d6..8a6da16771c 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1646,6 +1646,52 @@ _slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper) +static slang_ir_node * +_slang_gen_not(slang_assemble_ctx * A, const slang_operation *oper) +{ + slang_ir_node *n; + + assert(oper->type == SLANG_OPER_NOT); + + /* type-check expression */ + if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) { + slang_info_log_error(A->log, + "scalar/boolean expression expected for '!'"); + return NULL; + } + + n = _slang_gen_operation(A, &oper->children[0]); + if (n) + return new_not(n); + else + return NULL; +} + + +static slang_ir_node * +_slang_gen_xor(slang_assemble_ctx * A, const slang_operation *oper) +{ + slang_ir_node *n1, *n2; + + assert(oper->type == SLANG_OPER_LOGICALXOR); + + if (!_slang_is_scalar_or_boolean(A, &oper->children[0]) || + !_slang_is_scalar_or_boolean(A, &oper->children[0])) { + slang_info_log_error(A->log, + "scalar/boolean expressions expected for '^^'"); + return NULL; + } + + n1 = _slang_gen_operation(A, &oper->children[0]); + if (!n1) + return NULL; + n2 = _slang_gen_operation(A, &oper->children[1]); + if (!n2) + return NULL; + return new_node2(IR_NOTEQUAL, n1, n2); +} + + /** * Generate IR node for storage of a temporary of given size. */ @@ -2582,20 +2628,9 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper) return n; } case SLANG_OPER_LOGICALXOR: - { - slang_ir_node *n; - assert(oper->num_children == 2); - n = _slang_gen_function_call_name(A, "__logicalXor", oper, NULL); - return n; - } + return _slang_gen_xor(A, oper); case SLANG_OPER_NOT: - { - slang_ir_node *n; - assert(oper->num_children == 1); - n = _slang_gen_function_call_name(A, "__logicalNot", oper, NULL); - return n; - } - + return _slang_gen_not(A, oper); case SLANG_OPER_SELECT: /* b ? x : y */ { slang_ir_node *n; |