Ejemplo n.º 1
0
        /// <summary cref="IBackendCodeGenerator.GenerateCode(IfPredicate)"/>
        public void GenerateCode(IfPredicate predicate)
        {
            var condition  = Load(predicate.Condition);
            var trueValue  = Load(predicate.TrueValue);
            var falseValue = Load(predicate.FalseValue);

            var target = Allocate(predicate);

            using var statement = BeginStatement(target);
            statement.AppendArgument(condition);
            statement.AppendCommand(CLInstructions.SelectOperation1);
            statement.AppendArgument(trueValue);
            statement.AppendCommand(CLInstructions.SelectOperation2);
            statement.AppendArgument(falseValue);
        }
Ejemplo n.º 2
0
        /// <summary cref="IBackendCodeGenerator.GenerateCode(IfPredicate)"/>
        public void GenerateCode(IfPredicate predicate)
        {
            var condition  = LoadPrimitive(predicate.Condition);
            var trueValue  = Load(predicate.TrueValue);
            var falseValue = Load(predicate.FalseValue);

            var targetRegister = Allocate(predicate);

            if (predicate.BasicValueType == BasicValueType.Int1)
            {
                // We need a specific sequence of instructions for predicate registers
                var conditionRegister = EnsureHardwareRegister(condition);
                using (var statement1 = BeginMove(
                           new PredicateConfiguration(conditionRegister, true)))
                {
                    statement1.AppendSuffix(BasicValueType.Int1);
                    statement1.AppendArgument(targetRegister as PrimitiveRegister);
                    statement1.AppendArgument(trueValue as PrimitiveRegister);
                }

                using var statement2 = BeginMove(
                          new PredicateConfiguration(conditionRegister, false));
                statement2.AppendSuffix(BasicValueType.Int1);
                statement2.AppendArgument(targetRegister as PrimitiveRegister);
                statement2.AppendArgument(falseValue as PrimitiveRegister);
            }
            else
            {
                EmitComplexCommand(
                    PTXInstructions.GetSelectValueOperation(predicate.BasicValueType),
                    new PredicateEmitter(condition),
                    targetRegister,
                    trueValue,
                    falseValue);
            }
        }
Ejemplo n.º 3
0
 /// <summary cref="IValueVisitor.Visit(IfPredicate)"/>
 public void Visit(IfPredicate predicate) =>
 CodeGenerator.GenerateCode(predicate);
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs an if-then constraint.
 /// </summary>
 /// <typeparam name="T">Type of the variation being acted on.</typeparam>
 /// <param name="ifPredicate">The "if" portion of the if-then.</param>
 /// <param name="predicate">The test of the "then".</param>
 /// <returns>The if-then constraint.</returns>
 public static IfThenConstraint <T> Then <T>(this IfPredicate <T> ifPredicate, Expression <Func <T, bool> > predicate) where T : new()
 {
     return(new IfThenConstraint <T>(ifPredicate, predicate));
 }