コード例 #1
0
ファイル: MathIntrinsics.cs プロジェクト: adamreeve/ILGPU
 public MathIntrinsicAttribute(
     MathIntrinsicKind kind,
     ArithmeticFlags flags)
 {
     IntrinsicKind  = kind;
     IntrinsicFlags = flags;
 }
コード例 #2
0
ファイル: MathIntrinsics.cs プロジェクト: rpfeuti/ILGPU
 public MathIntrinsicAttribute(
     MathIntrinsicKind intrinsicKind,
     ArithmeticFlags intrinsicFlags)
 {
     IntrinsicKind  = intrinsicKind;
     IntrinsicFlags = intrinsicFlags;
 }
コード例 #3
0
        /// <summary>
        /// Handles general math operations and performs double-intrinsic to float-intrinsic conversions if requested.
        /// </summary>
        /// <param name="context">The current invocation context.</param>
        /// <param name="kind">The kind of the math intrinsic.</param>
        /// <returns>The resulting value.</returns>
        private Value?MakeMathInternal(InvocationContext context, MathIntrinsicKind kind)
        {
            kind = kind.ResolveIntrinsicKind(context.Unit.Force32BitFloats);
            var targetMethod = GPUMath.MathFunctionMapping[kind];

            context = MakeDefaultMathRemapping(context, targetMethod);
            return(MakeMath(context, kind));
        }
コード例 #4
0
 /// <summary>
 /// Resolves the appropriate intrinsic kind for the desired scenario.
 /// </summary>
 /// <param name="kind">The intrinsic kind.</param>
 /// <param name="force32BitMath">True, iff the intrinsic should treat f64 as f32.</param>
 /// <returns>The resolved intrinsic kind.</returns>
 public static MathIntrinsicKind ResolveIntrinsicKind(this MathIntrinsicKind kind, bool force32BitMath)
 {
     if (force32BitMath && kind.IsF64Intrinsic())
     {
         return((MathIntrinsicKind)((int)kind - 1));
     }
     return(kind);
 }
コード例 #5
0
        /// <summary cref="CompilerDeviceFunctions.MakeMath(InvocationContext, MathIntrinsicKind)"/>
        protected override Value?MakeMath(InvocationContext context, MathIntrinsicKind kind)
        {
            var ptxAttr = context.Method.GetCustomAttribute <PTXMathFunctionAttribute>();

            if (ptxAttr == null)
            {
                throw context.CompilationContext.GetNotSupportedException(
                          ErrorMessages.NotSupportedMathIntrinsic, kind);
            }
            string funcName = ptxAttr.Name;

            if (context.Unit.HasFlags(CompileUnitFlags.FastMath))
            {
                var ptxFastAttr = context.Method.GetCustomAttribute <PTXFastMathFunctionAttribute>();
                if (ptxFastAttr != null)
                {
                    funcName = ptxFastAttr.Name;
                }
            }

            var func = GetNamedFunction(context.Unit.LLVMModule, funcName);

            if (func.Pointer == IntPtr.Zero)
            {
                throw context.CompilationContext.GetNotSupportedException(
                          ErrorMessages.NotSupportedMathIntrinsic, kind);
            }

            var args     = context.GetArgs();
            var llvmArgs = new LLVMValueRef[args.Length];

            for (int i = 0; i < args.Length; ++i)
            {
                llvmArgs[i] = args[i].LLVMValue;
            }

            var builder = context.Builder;
            var call    = BuildCall(builder, func, llvmArgs);

            // Check for required comparison for i32 return-types instead of bool values
            if (ptxAttr.BoolAsInt32)
            {
                call = BuildTrunc(builder, call, context.LLVMContext.Int1Type, string.Empty);
            }
            var info = context.Method as MethodInfo;

            Debug.Assert(info != null, "Invalid method invocation");
            return(new Value(info.ReturnType, call));
        }
コード例 #6
0
ファイル: MathIntrinsics.cs プロジェクト: adamreeve/ILGPU
 public MathIntrinsicAttribute(MathIntrinsicKind kind)
     : this(kind, ArithmeticFlags.None)
 {
 }
コード例 #7
0
 /// <summary>
 /// Handles general math operations.
 /// </summary>
 /// <param name="context">The current invocation context.</param>
 /// <param name="kind">The kind of the math intrinsic.</param>
 /// <returns>The resulting value.</returns>
 protected abstract Value?MakeMath(InvocationContext context, MathIntrinsicKind kind);
コード例 #8
0
 public MathIntrinsicAttribute(MathIntrinsicKind kind)
 {
     IntrinsicKind = kind;
 }
コード例 #9
0
 public static bool IsIntIntrinsic(this MathIntrinsicKind kind)
 {
     return(kind > MathIntrinsicKind.__IntIntrinsics);
 }
コード例 #10
0
 /// <summary>
 /// Returns true iff the given intrinsic kind represents an intrinsic operation
 /// that works on 6432bit floats.
 /// </summary>
 /// <param name="kind">The intrinsic kind.</param>
 /// <returns>
 /// True, iff the given intrinsic kind represents an intrinsic operation
 /// that works on 64bit floats.
 /// </returns>
 public static bool IsF64Intrinsic(this MathIntrinsicKind kind)
 {
     return(kind.IsFloatIntrinsic() && ((int)kind % 2) == 1);
 }