Exemplo n.º 1
0
 public AtomicIntrinsicAttribute(
     AtomicIntrinsicKind intrinsicKind,
     AtomicFlags intrinsicFlags)
 {
     IntrinsicKind  = intrinsicKind;
     IntrinsicFlags = intrinsicFlags;
 }
Exemplo n.º 2
0
 public AtomicIntrinsicAttribute(
     AtomicIntrinsicKind kind,
     AtomicFlags flags)
 {
     IntrinsicKind  = kind;
     IntrinsicFlags = flags;
 }
        /// <summary>
        /// Makes a general atomic invocation of the given kind.
        /// </summary>
        /// <param name="context">The current invocation context.</param>
        /// <param name="kind">The kind of the atomic operation.</param>
        /// <returns>The resulting value.</returns>
        protected virtual Value?MakeAtomic(InvocationContext context, AtomicIntrinsicKind kind)
        {
            var builder = context.Builder;
            var args    = context.GetArgs();

            // First arg is a VariableView<T>
            // Extract the pointer from the tuple
            var variableView = args[0];
            var ptr          = BuildExtractValue(builder, variableView.LLVMValue, 0, "ptr");
            var elementType  = variableView.ValueType.GetGenericArguments()[0];

            ptr = BuildBitCast(builder, ptr, Unit.GetType(elementType.MakePointerType()), "ptrT");

            var value = args[1].LLVMValue;

            switch (kind)
            {
            case AtomicIntrinsicKind.CmpXch:
                var cmpxch =
                    BuildAtomicCmpXchg(builder, ptr, value, args[2].LLVMValue,
                                       LLVMAtomicOrdering.LLVMAtomicOrderingSequentiallyConsistent, LLVMAtomicOrdering.LLVMAtomicOrderingSequentiallyConsistent, false);
                return(new Value(
                           elementType,
                           BuildExtractValue(builder, cmpxch, 0, string.Empty)));

            case AtomicIntrinsicKind.AddF32:
                return(MakeAtomicAdd(context, ptr, kind));

            case AtomicIntrinsicKind.IncU32:
                return(MakeAtomicInc(context, ptr, kind));

            case AtomicIntrinsicKind.DecU32:
                return(MakeAtomicDec(context, ptr, kind));

            default:
                return(new Value(
                           elementType,
                           BuildAtomicRMW(builder, (LLVMAtomicRMWBinOp)kind, ptr, value, LLVMAtomicOrdering.LLVMAtomicOrderingSequentiallyConsistent, false)));
            }
        }
 /// <summary>
 /// Makes a specifc atomic-dec invocation of the given kind.
 /// </summary>
 /// <param name="context">The current invocation context.</param>
 /// <param name="ptr">The pointer to the data location.</param>
 /// <param name="kind">The kind of the atomic operations.</param>
 /// <returns>The resulting value.</returns>
 protected abstract Value MakeAtomicDec(InvocationContext context, LLVMValueRef ptr, AtomicIntrinsicKind kind);
Exemplo n.º 5
0
        /// <summary cref="CompilerDeviceFunctions.MakeAtomicDec(InvocationContext, LLVMValueRef, AtomicIntrinsicKind)"/>
        protected override Value MakeAtomicDec(InvocationContext context, LLVMValueRef ptr, AtomicIntrinsicKind kind)
        {
            if (kind != AtomicIntrinsicKind.DecU32)
            {
                throw context.CompilationContext.GetNotSupportedException(
                          ErrorMessages.NotSupportedAtomicOperation, kind);
            }

            return(MakeCudaAtomic(context, ptr, AtomicDecU32.Value));
        }
 public AtomicIntrinsicAttribute(AtomicIntrinsicKind intrinsicKind)
 {
     IntrinsicKind = intrinsicKind;
 }