Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary cref="IBackendCodeGenerator.GenerateCode(AddressSpaceCast)"/>
        public void GenerateCode(AddressSpaceCast value)
        {
            var sourceType           = value.SourceType as AddressSpaceType;
            var targetAdressRegister = AllocatePlatformRegister(
                value,
                out RegisterDescription _);

            Debug.Assert(value.IsPointerCast, "Invalid pointer access");

            var address                     = LoadPrimitive(value.Value);
            var toGeneric                   = value.TargetAddressSpace == MemoryAddressSpace.Generic;
            var addressSpaceOperation       = PTXInstructions.GetAddressSpaceCast(toGeneric);
            var addressSpaceOperationSuffix =
                PTXInstructions.GetAddressSpaceCastSuffix(Backend);

            using var command = BeginCommand(addressSpaceOperation);
            command.AppendAddressSpace(
                toGeneric ? sourceType.AddressSpace : value.TargetAddressSpace);
            command.AppendSuffix(addressSpaceOperationSuffix);
            command.AppendArgument(targetAdressRegister);
            command.AppendArgument(address);
        }
Exemplo n.º 3
0
        /// <summary cref="IValueVisitor.Visit(AddressSpaceCast)"/>
        public void Visit(AddressSpaceCast value)
        {
            var sourceType           = value.SourceType as AddressSpaceType;
            var targetAdressRegister = AllocatePlatformRegister(value, out RegisterDescription _);

            PrimitiveRegister address;

            if (value.IsPointerCast)
            {
                address = LoadPrimitive(value.Value);
            }
            else
            {
                var viewSource = LoadAs <ViewImplementationRegister>(value.Value);
                address = viewSource.Pointer;

                // Reuse the existing length register since we don't modify the result
                var viewTarget = new ViewImplementationRegister(
                    value.Type as ViewType,
                    targetAdressRegister,
                    viewSource.Length);
                Bind(value, viewTarget);
            }

            var toGeneric                   = value.TargetAddressSpace == MemoryAddressSpace.Generic;
            var addressSpaceOperation       = PTXInstructions.GetAddressSpaceCast(toGeneric);
            var addressSpaceOperationSuffix = PTXInstructions.GetAddressSpaceCastSuffix(ABI);

            using (var command = BeginCommand(addressSpaceOperation))
            {
                command.AppendAddressSpace(
                    toGeneric ? sourceType.AddressSpace : value.TargetAddressSpace);
                command.AppendSuffix(addressSpaceOperationSuffix);
                command.AppendArgument(targetAdressRegister);
                command.AppendArgument(address);
            }
        }