Пример #1
0
 public IOEmitter(
     PointerType targetType,
     PrimitiveRegister addressRegister)
 {
     TargetType      = targetType;
     AddressRegister = addressRegister;
 }
Пример #2
0
 public IOEmitter(
     PointerType sourceType,
     PrimitiveRegister addressRegister)
 {
     SourceType      = sourceType;
     AddressRegister = addressRegister;
 }
Пример #3
0
                /// <summary>
                /// Emits a new parameter load operation that converts generic address-
                /// space pointers into a specialized address space.
                /// </summary>
                public readonly void Emit(
                    PTXCodeGenerator codeGenerator,
                    string command,
                    PrimitiveRegister primitiveRegister,
                    int offset)
                {
                    // Load into the temporary register in the case of a pointer type
                    if (primitiveRegister.Type is AddressSpaceType addressSpaceType &&
                        addressSpaceType.AddressSpace != MemoryAddressSpace.Generic)
                    {
                        primitiveRegister.AssertNotNull(TempRegister);

                        using (var commandEmitter = BeginEmitLoad(
                                   codeGenerator,
                                   command,
                                   TempRegister))
                        {
                            commandEmitter.AppendRawValue(ParamName, offset);
                        }

                        // Convert the source value into the specialized address space
                        // using the previously allocated temp register
                        codeGenerator.CreateAddressSpaceCast(
                            TempRegister,
                            primitiveRegister as HardwareRegister,
                            MemoryAddressSpace.Generic,
                            addressSpaceType.AddressSpace);
                    }
Пример #4
0
        /// <summary>
        /// Creates a set of instructions to realize a generic lea operation.
        /// </summary>
        /// <param name="sourceType">The source address type (pointer or view).</param>
        /// <param name="elementIndex">The current element index (the offset).</param>
        /// <param name="targetAddressRegister">The allocated target pointer register to write to.</param>
        /// <param name="address">The source address.</param>
        private void MakeLoadElementAddress(
            AddressSpaceType sourceType,
            PrimitiveRegister elementIndex,
            PrimitiveRegister targetAddressRegister,
            PrimitiveRegister address)
        {
            var elementSize    = ABI.GetSizeOf(sourceType.ElementType);
            var offsetRegister = AllocatePlatformRegister(out RegisterDescription _);

            using (var command = BeginCommand(
                       PTXInstructions.GetLEAMulOperation(ABI.PointerArithmeticType)))
            {
                command.AppendArgument(offsetRegister);
                command.AppendArgument(elementIndex);
                command.AppendConstant(elementSize);
            }

            using (var command = BeginCommand(
                       PTXInstructions.GetArithmeticOperation(
                           BinaryArithmeticKind.Add,
                           ABI.PointerArithmeticType,
                           false)))
            {
                command.AppendArgument(targetAddressRegister);
                command.AppendArgument(address);
                command.AppendArgument(offsetRegister);
            }

            FreeRegister(offsetRegister);
        }
Пример #5
0
 /// <summary>
 /// Append the value given register argument.
 /// </summary>
 /// <param name="argument">The register argument.</param>
 public void AppendArgumentValue(PrimitiveRegister argument)
 {
     AppendArgument();
     stringBuilder.Append('[');
     stringBuilder.Append('%');
     stringBuilder.Append(GetStringRepresentation(argument));
     stringBuilder.Append(']');
 }
Пример #6
0
 internal ViewImplementationRegister(
     ViewType viewType,
     PrimitiveRegister pointer,
     PrimitiveRegister length)
     : base(viewType)
 {
     Pointer = pointer;
     Length  = length;
 }
Пример #7
0
 public PredicateScope(PrimitiveRegister predicateRegister)
 {
     Debug.Assert(predicateRegister != null, "Invalid register allocator");
     Debug.Assert(
         predicateRegister.Kind == PTXRegisterKind.Predicate,
         "Invalid predicate register");
     RegisterAllocator = null;
     PredicateRegister = predicateRegister;
 }
Пример #8
0
 public void Emit(
     PTXCodeGenerator codeGenerator,
     string command,
     PrimitiveRegister primitiveRegister,
     int offset) =>
 codeGenerator.EmitIOLoad(
     Emitter,
     command,
     primitiveRegister as HardwareRegister,
     offset);
Пример #9
0
 /// <summary>
 /// Constructs a new predicate configuration.
 /// </summary>
 /// <param name="predicateRegister">The predicate register to test.</param>
 /// <param name="isTrue">Branch if the predicate register is true.</param>
 public PredicateConfiguration(
     PrimitiveRegister predicateRegister,
     bool isTrue)
 {
     Debug.Assert(
         predicateRegister.Kind == PTXRegisterKind.Predicate,
         "Invalid predicate register");
     PredicateRegister = predicateRegister;
     IsTrue            = isTrue;
 }
Пример #10
0
 public void Emit(
     PTXCodeGenerator codeGenerator,
     string command,
     PrimitiveRegister register,
     int offset) =>
 codeGenerator.EmitIOStore(
     Emitter,
     command,
     register,
     offset);
Пример #11
0
 public void Emit(
     PTXCodeGenerator codeGenerator,
     string command,
     PrimitiveRegister primitiveRegister,
     int offset)
 {
     using var commandEmitter = codeGenerator.BeginCommand(command);
     commandEmitter.AppendSuffix(primitiveRegister.BasicValueType);
     commandEmitter.AppendRawValue(ParamName, offset);
     commandEmitter.AppendArgument(primitiveRegister);
 }
Пример #12
0
 /// <summary>
 /// Append the given register argument.
 /// </summary>
 /// <param name="argument">The register argument.</param>
 public void AppendArgument(PrimitiveRegister argument)
 {
     if (argument is ConstantRegister constantRegister)
     {
         AppendArgument(constantRegister);
     }
     else
     {
         AppendArgument(argument as HardwareRegister);
     }
 }
Пример #13
0
 public void Emit(
     PTXCodeGenerator codeGenerator,
     string command,
     PrimitiveRegister register,
     int offset)
 {
     using var commandEmitter = codeGenerator.BeginCommand(command);
     commandEmitter.AppendAddressSpace(TargetType.AddressSpace);
     commandEmitter.AppendSuffix(register.BasicValueType);
     commandEmitter.AppendArgumentValue(AddressRegister, offset);
     commandEmitter.AppendArgument(register);
 }
Пример #14
0
                private static CommandEmitter BeginEmitLoad(
                    PTXCodeGenerator codeGenerator,
                    string command,
                    PrimitiveRegister sourceRegister)
                {
                    var commandEmitter = codeGenerator.BeginCommand(command);

                    commandEmitter.AppendSuffix(
                        ResolveParameterBasicValueType(
                            sourceRegister.BasicValueType));
                    commandEmitter.AppendArgument(sourceRegister);
                    return(commandEmitter);
                }
Пример #15
0
        /// <summary>
        /// Creates an address-space cast conversion.
        /// </summary>
        /// <param name="sourceRegister">The source register.</param>
        /// <param name="targetRegister">The target register.</param>
        /// <param name="sourceAddressSpace">The source address space.</param>
        /// <param name="targetAddressSpace">The target address space.</param>
        private void CreateAddressSpaceCast(
            PrimitiveRegister sourceRegister,
            HardwareRegister targetRegister,
            MemoryAddressSpace sourceAddressSpace,
            MemoryAddressSpace targetAddressSpace)
        {
            var toGeneric                   = targetAddressSpace == MemoryAddressSpace.Generic;
            var addressSpaceOperation       = PTXInstructions.GetAddressSpaceCast(toGeneric);
            var addressSpaceOperationSuffix =
                PTXInstructions.GetAddressSpaceCastSuffix(Backend);

            using var command = BeginCommand(addressSpaceOperation);
            command.AppendAddressSpace(
                toGeneric ? sourceAddressSpace : targetAddressSpace);
            command.AppendSuffix(addressSpaceOperationSuffix);
            command.AppendArgument(targetRegister);
            command.AppendArgument(sourceRegister);
        }
Пример #16
0
 public PredicateEmitter(PrimitiveRegister predicateRegister)
 {
     PredicateRegister = predicateRegister;
 }
Пример #17
0
 /// <summary>
 /// Converts the underlying predicate register to a
 /// default target register.
 /// </summary>
 /// <param name="codeGenerator">The target code generator.</param>
 /// <param name="targetRegister">The target register to write to.</param>
 public void ConvertToValue(
     PTXCodeGenerator codeGenerator,
     PrimitiveRegister targetRegister) =>
 codeGenerator.ConvertPredicateToValue(
     PredicateRegister,
     targetRegister);
Пример #18
0
 public StoreEmitter(
     PointerType targetType,
     PrimitiveRegister addressRegister)
 {
     Emitter = new IOEmitter(targetType, addressRegister);
 }
Пример #19
0
 public LoadEmitter(
     PointerType sourceType,
     PrimitiveRegister addressRegister)
 {
     Emitter = new IOEmitter(sourceType, addressRegister);
 }
Пример #20
0
 /// <summary>
 /// Frees the given register.
 /// </summary>
 /// <param name="register">The register to free.</param>
 public abstract void FreeRegister(PrimitiveRegister register);