示例#1
0
        /// <summary cref="IValueVisitor.Visit(NewView)"/>
        public void Visit(NewView value)
        {
            var pointer = LoadPrimitive(value.Pointer);
            var length  = LoadPrimitive(value.Length);

            var viewValue = new ViewImplementationRegister(
                value.Type as ViewType,
                pointer,
                length);

            Bind(value, viewValue);
        }
示例#2
0
        /// <summary cref="IValueVisitor.Visit(ViewCast)"/>
        public void Visit(ViewCast value)
        {
            var source  = LoadAs <ViewImplementationRegister>(value.Value);
            var pointer = source.Pointer;
            var length  = source.Length;

            var sourceElementSize = ABI.GetSizeOf(value.SourceElementType);
            var targetElementSize = ABI.GetSizeOf(value.TargetElementType);

            // var newLength = length * sourceElementSize / targetElementSize;
            var lengthTimesSourceElementSize = AllocateRegister(length.Description);
            var newLength = AllocateRegister(length.Description);

            using (var command = BeginCommand(
                       PTXInstructions.GetArithmeticOperation(
                           BinaryArithmeticKind.Mul,
                           ArithmeticBasicValueType.Int32,
                           FastMath)))
            {
                command.AppendArgument(lengthTimesSourceElementSize);
                command.AppendArgument(length);
                command.AppendConstant(sourceElementSize);
            }

            using (var command = BeginCommand(
                       PTXInstructions.GetArithmeticOperation(
                           BinaryArithmeticKind.Div,
                           ArithmeticBasicValueType.Int32,
                           FastMath)))
            {
                command.AppendArgument(newLength);
                command.AppendArgument(lengthTimesSourceElementSize);
                command.AppendConstant(targetElementSize);
            }

            var newView = new ViewImplementationRegister(
                value.Type as ViewType,
                pointer,
                newLength);

            Bind(value, newView);

            FreeRegister(lengthTimesSourceElementSize);
        }
示例#3
0
        /// <summary cref="IValueVisitor.Visit(SubViewValue)"/>
        public void Visit(SubViewValue value)
        {
            var viewType = value.Type as ViewType;
            var source   = LoadAs <ViewImplementationRegister>(value.Source);
            var offset   = LoadPrimitive(value.Offset);
            var length   = LoadPrimitive(value.Length);

            var targetAddressRegister = AllocatePlatformRegister(value, out RegisterDescription _);

            MakeLoadElementAddress(
                viewType,
                offset,
                targetAddressRegister,
                source.Pointer);

            var newSubView = new ViewImplementationRegister(
                viewType,
                targetAddressRegister,
                length);

            Bind(value, newSubView);
        }
示例#4
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);
            }
        }