示例#1
0
 public void Visit(UnaryArithmeticValue value)
 {
     if (Get <UnaryArithmeticValue>().Kind != value.Kind)
     {
         Fail();
     }
 }
示例#2
0
        /// <summary cref="IValueVisitor.Visit(UnaryArithmeticValue)"/>
        public void Visit(UnaryArithmeticValue value)
        {
            var argument = Load(value.Value);
            var target   = Allocate(value, value.ArithmeticBasicValueType);

            using (var statement = BeginStatement(target))
            {
                statement.AppendCast(value.ArithmeticBasicValueType);
                var operation = CLInstructions.GetArithmeticOperation(
                    value.Kind,
                    value.BasicValueType.IsFloat(),
                    out bool isFunction);

                if (isFunction)
                {
                    statement.AppendCommand(operation);
                }
                statement.BeginArguments();
                if (!isFunction)
                {
                    statement.AppendCommand(operation);
                }

                statement.AppendCast(value.ArithmeticBasicValueType);
                statement.AppendArgument(argument);
                statement.EndArguments();
            }
        }
示例#3
0
        /// <summary cref="IBackendCodeGenerator.GenerateCode(UnaryArithmeticValue)"/>
        public void GenerateCode(UnaryArithmeticValue value)
        {
            var argument = Load(value.Value);
            var target   = Allocate(
                value,
                value.BasicValueType == BasicValueType.Int1
                ? ArithmeticBasicValueType.UInt1 : value.ArithmeticBasicValueType);

            using var statement = BeginStatement(target);
            if (value.BasicValueType != BasicValueType.Int1)
            {
                statement.AppendCast(value.ArithmeticBasicValueType);
            }
            var operation = CLInstructions.GetArithmeticOperation(
                value.Kind,
                value.ArithmeticBasicValueType,
                out bool isFunction);

            if (isFunction)
            {
                statement.AppendCommand(operation);
            }
            statement.BeginArguments();
            if (!isFunction)
            {
                statement.AppendCommand(operation);
            }

            statement.AppendCast(value.ArithmeticBasicValueType);
            statement.AppendArgument(argument);
            statement.EndArguments();
        }
示例#4
0
        /// <summary cref="IBackendCodeGenerator.GenerateCode(UnaryArithmeticValue)"/>
        public void GenerateCode(UnaryArithmeticValue value)
        {
            var argument       = LoadPrimitive(value.Value);
            var targetRegister = AllocateHardware(value);

            using var command = BeginCommand(
                      PTXInstructions.GetArithmeticOperation(
                          value.Kind,
                          value.ArithmeticBasicValueType,
                          FastMath));
            command.AppendArgument(targetRegister);
            command.AppendArgument(argument);
        }
示例#5
0
 /// <summary cref="IValueVisitor.Visit(UnaryArithmeticValue)"/>
 public void Visit(UnaryArithmeticValue value) =>
 CodeGenerator.GenerateCode(value);
示例#6
0
 /// <summary>
 /// Tries to determine power of 2 information for the given unary operation.
 /// </summary>
 /// <param name="unary">The unary operation to analyze.</param>
 /// <returns>The power of 2 value (if any).</returns>
 private static int?TryGetPowerOf2(UnaryArithmeticValue unary) =>
 unary.Kind switch
 {