public MathIntrinsicAttribute( MathIntrinsicKind kind, ArithmeticFlags flags) { IntrinsicKind = kind; IntrinsicFlags = flags; }
public MathIntrinsicAttribute( MathIntrinsicKind intrinsicKind, ArithmeticFlags intrinsicFlags) { IntrinsicKind = intrinsicKind; IntrinsicFlags = intrinsicFlags; }
/// <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)); }
/// <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); }
/// <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)); }
public MathIntrinsicAttribute(MathIntrinsicKind kind) : this(kind, ArithmeticFlags.None) { }
/// <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);
public MathIntrinsicAttribute(MathIntrinsicKind kind) { IntrinsicKind = kind; }
public static bool IsIntIntrinsic(this MathIntrinsicKind kind) { return(kind > MathIntrinsicKind.__IntIntrinsics); }
/// <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); }