diff options
| author | Robert Stepinski <rob.stepinski@gmail.com> | 2019-05-01 12:33:50 -0400 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-05-01 09:33:50 -0700 |
| commit | 88a3f6476c37f3245de6d607d8055879f8892ee4 (patch) | |
| tree | a0fbe01fae015014a4b7e17305ff9d0a451d0f55 /source/slang/emit.cpp | |
| parent | 4880789e3003441732cca4471091563f36531635 (diff) | |
Fix bitwise And & Or for scalar bool (#960)
* Convert bitwise Or & And to logical operations on scalar bools
* Test bitwise operations on scalar bools
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 24d1ce56c..675d459e9 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -3938,9 +3938,7 @@ struct EmitVisitor CASE_COMPARE(kIROp_Geq, Geq, >=); CASE_COMPARE(kIROp_Leq, Leq, <=); - CASE(kIROp_BitAnd, BitAnd, &); CASE(kIROp_BitXor, BitXor, ^); - CASE(kIROp_BitOr, BitOr, |); CASE(kIROp_And, And, &&); CASE(kIROp_Or, Or, ||); @@ -3989,6 +3987,7 @@ struct EmitVisitor emitIROperand(ctx, inst->getOperand(0), mode, rightSide(prec, outerPrec)); } break; + case kIROp_BitNot: { auto prec = kEOp_Prefix; @@ -4006,6 +4005,60 @@ struct EmitVisitor } break; + case kIROp_BitAnd: + { + auto prec = kEOp_BitAnd; + needClose = maybeEmitParens(outerPrec, prec); + + // TODO: handle a bitwise And of a vector of bools by casting to + // a uvec and performing the bitwise operation + + emitIROperand(ctx, inst->getOperand(0), mode, leftSide(outerPrec, prec)); + + // Are we targetting GLSL, and are both operands scalar bools? + // In that case convert the operation to a logical And + if (getTarget(ctx) == CodeGenTarget::GLSL + && as<IRBoolType>(inst->getOperand(0)->getDataType()) + && as<IRBoolType>(inst->getOperand(1)->getDataType())) + { + emit("&&"); + } + else + { + emit("&"); + } + + emitIROperand(ctx, inst->getOperand(1), mode, rightSide(outerPrec, prec)); + } + break; + + case kIROp_BitOr: + { + auto prec = kEOp_BitOr; + needClose = maybeEmitParens(outerPrec, prec); + + // TODO: handle a bitwise Or of a vector of bools by casting to + // a uvec and performing the bitwise operation + + emitIROperand(ctx, inst->getOperand(0), mode, leftSide(outerPrec, prec)); + + // Are we targetting GLSL, and are both operands scalar bools? + // In that case convert the operation to a logical Or + if (getTarget(ctx) == CodeGenTarget::GLSL + && as<IRBoolType>(inst->getOperand(0)->getDataType()) + && as<IRBoolType>(inst->getOperand(1)->getDataType())) + { + emit("||"); + } + else + { + emit("|"); + } + + emitIROperand(ctx, inst->getOperand(1), mode, rightSide(outerPrec, prec)); + } + break; + case kIROp_Load: { auto base = inst->getOperand(0); |
