示例#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);
 }
 /// <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);