/// <summary cref="IBackendCodeGenerator.GenerateCode(TernaryArithmeticValue)"/> public void GenerateCode(TernaryArithmeticValue value) { if (!CLInstructions.TryGetArithmeticOperation( value.Kind, value.BasicValueType.IsFloat(), out string operation)) { throw new InvalidCodeGenerationException(); } var first = Load(value.First); var second = Load(value.Second); var third = Load(value.Third); var target = Allocate(value, value.ArithmeticBasicValueType); using var statement = BeginStatement(target); statement.AppendCast(value.ArithmeticBasicValueType); statement.AppendCommand(operation); statement.BeginArguments(); statement.AppendArgument(); statement.AppendCast(value.ArithmeticBasicValueType); statement.Append(first); statement.AppendArgument(); statement.AppendCast(value.ArithmeticBasicValueType); statement.Append(second); statement.AppendArgument(); statement.AppendCast(value.ArithmeticBasicValueType); statement.Append(third); statement.EndArguments(); }
public void Visit(TernaryArithmeticValue value) { if (Get <TernaryArithmeticValue>().Kind != value.Kind || Get <TernaryArithmeticValue>().Flags != value.Flags) { Fail(); } }
/// <summary cref="IBackendCodeGenerator.GenerateCode(TernaryArithmeticValue)"/> public void GenerateCode(TernaryArithmeticValue value) { var first = LoadPrimitive(value.First); var second = LoadPrimitive(value.Second); var third = LoadPrimitive(value.Third); var targetRegister = Allocate(value, first.Description); using var command = BeginCommand( PTXInstructions.GetArithmeticOperation( value.Kind, value.ArithmeticBasicValueType)); command.AppendArgument(targetRegister); command.AppendArgument(first); command.AppendArgument(second); command.AppendArgument(third); }
/// <summary> /// Creates a ternary arithmetic operation. /// </summary> /// <param name="location">The current location.</param> /// <param name="first">The first operand.</param> /// <param name="second">The second operand.</param> /// <param name="third">The second operand.</param> /// <param name="kind">The operation kind.</param> /// <param name="flags">Operation flags.</param> /// <returns>A node that represents the arithmetic operation.</returns> public ValueReference CreateArithmetic( Location location, Value first, Value second, Value third, TernaryArithmeticKind kind, ArithmeticFlags flags) { if (UseConstantPropagation) { // Check for constants if (first is PrimitiveValue firstValue && second is PrimitiveValue secondValue) { var value = BinaryArithmeticFoldConstants( location, firstValue, secondValue, TernaryArithmeticValue.GetLeftBinaryKind(kind), flags); // Try to fold right hand side as well var rightOperation = TernaryArithmeticValue.GetRightBinaryKind(kind); return(CreateArithmetic( location, value, third, rightOperation)); } } return(Append(new TernaryArithmeticValue( GetInitializer(location), first, second, third, kind, flags))); }
/// <summary> /// Creates a ternary arithmetic operation. /// </summary> /// <param name="first">The first operand.</param> /// <param name="second">The second operand.</param> /// <param name="third">The second operand.</param> /// <param name="kind">The operation kind.</param> /// <param name="flags">Operation flags.</param> /// <returns>A node that represents the arithmetic operation.</returns> public ValueReference CreateArithmetic( Value first, Value second, Value third, TernaryArithmeticKind kind, ArithmeticFlags flags) { Debug.Assert(first != null, "Invalid first node"); Debug.Assert(second != null, "Invalid second node"); Debug.Assert(third != null, "Invalid third node"); if (UseConstantPropagation) { // Check for constants if (first is PrimitiveValue firstValue && second is PrimitiveValue secondValue) { var value = BinaryArithmeticFoldConstants( firstValue, secondValue, TernaryArithmeticValue.GetLeftBinaryKind(kind), flags); // Try to fold right hand side as well var rightOperation = TernaryArithmeticValue.GetRightBinaryKind(kind); return(CreateArithmetic(value, third, rightOperation)); } } return(Append(new TernaryArithmeticValue( BasicBlock, first, second, third, kind, flags))); }
/// <summary cref="IValueVisitor.Visit(TernaryArithmeticValue)"/> public void Visit(TernaryArithmeticValue value) => CodeGenerator.GenerateCode(value);