Beispiel #1
0
        /// <summary>
        /// The Cuda (PTX) implementation.
        /// </summary>
        /// <remarks>
        /// Note that this function signature corresponds to the PTX-backend specific
        /// delegate type <see cref="PTXIntrinsic.Handler"/>.
        /// </remarks>
        static void GeneratePTXCode(
            PTXBackend backend,
            PTXCodeGenerator codeGenerator,
            Value value)
        {
            // The passed value will be the call node in this case
            // Load X parameter register (first argument)
            var xRegister = codeGenerator.LoadPrimitive(value[0]);

            // Allocate target register to write our result to
            var target = codeGenerator.AllocateHardware(value);

            // Emit our desired instructions
            using (var command = codeGenerator.BeginCommand(
                       PTXInstructions.GetArithmeticOperation(
                           BinaryArithmeticKind.Mul,
                           ArithmeticBasicValueType.Int32,
                           backend.Capabilities,
                           false)))
            {
                command.AppendArgument(target);
                command.AppendArgument(xRegister);
                command.AppendConstant(2);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates intrinsic math instructions for the following kinds:
        /// Rcp, Sqrt, Sin, Cos, Exp2, Log2, IsInf, IsNaN
        /// </summary>
        /// <param name="backend">The current backend.</param>
        /// <param name="codeGenerator">The code generator.</param>
        /// <param name="value">The value to generate code for.</param>
        public static void GenerateMathIntrinsic(
            PTXBackend backend,
            PTXCodeGenerator codeGenerator,
            Value value)
        {
            var arithmeticValue = value as UnaryArithmeticValue;
            var instruction     = PTXInstructions.GetArithmeticOperation(
                arithmeticValue.Kind,
                arithmeticValue.ArithmeticBasicValueType,
                codeGenerator.FastMath);

            var argument       = codeGenerator.LoadPrimitive(arithmeticValue.Value);
            var targetRegister = codeGenerator.AllocateHardware(arithmeticValue);

            using var command = codeGenerator.BeginCommand(instruction);
            command.AppendArgument(targetRegister);
            command.AppendArgument(argument);
        }