Exemplo n.º 1
0
        /// <summary>
        /// Resolves a binary arithmetic operation.
        /// </summary>
        /// <param name="kind">The arithmetic kind.</param>
        /// <param name="type">The operation type.</param>
        /// <param name="fastMath">True, to use a fast-math operation.</param>
        /// <returns>The resolved arithmetic operation.</returns>
        public static string GetArithmeticOperation(
            BinaryArithmeticKind kind,
            ArithmeticBasicValueType type,
            bool fastMath)
        {
            var key = (kind, type);

            if (fastMath &&
                BinaryArithmeticOperationsFastMath.TryGetValue(key, out string operation) ||
                BinaryArithmeticOperations.TryGetValue(key, out operation))
            {
                return(operation);
            }
            throw new NotSupportedIntrinsicException(kind.ToString());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Resolves an unary arithmetic operation.
 /// </summary>
 /// <param name="kind">The arithmetic kind.</param>
 /// <param name="basicValueType">The arithmetic basic value type.</param>
 /// <param name="isFunction">
 /// True, if the resolved operation is a function call.
 /// </param>
 /// <returns>The resolved arithmetic operation.</returns>
 public static string GetArithmeticOperation(
     UnaryArithmeticKind kind,
     ArithmeticBasicValueType basicValueType,
     out bool isFunction)
 {
     if (!UnaryCategoryLookup.TryGetValue(basicValueType, out var category) ||
         !UnaryArithmeticOperations.TryGetValue(
             (kind, category),
             out var operation))
     {
         throw new NotSupportedIntrinsicException(kind.ToString());
     }
     isFunction = operation.Item2;
     return(operation.Item1);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Resolves a compare operation.
        /// </summary>
        /// <param name="kind">The compare kind.</param>
        /// <param name="flags">The compare flags.</param>
        /// <param name="type">The type to compare.</param>
        /// <returns>The resolved compare operation.</returns>
        public static string GetCompareOperation(
            CompareKind kind,
            CompareFlags flags,
            ArithmeticBasicValueType type)
        {
            var unorderedFloatComparison = type.IsFloat() && flags.HasFlag(CompareFlags.UnsignedOrUnordered);

            if (unorderedFloatComparison)
            {
                if (CompareUnorderedFloatOperations.TryGetValue((kind, type), out string operation))
                {
                    return(operation);
                }
            }
            else
            {
                if (CompareOperations.TryGetValue((kind, type), out string operation))
                {
                    return(operation);
                }
            }
            throw new NotSupportedIntrinsicException(kind.ToString());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructs a new primitive variable.
 /// </summary>
 /// <param name="id">The current variable id.</param>
 /// <param name="basicValueType">The basic value type.</param>
 internal PrimitiveVariable(int id, ArithmeticBasicValueType basicValueType)
     : base(id)
 {
     BasicValueType = basicValueType;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Allocates the given type.
 /// </summary>
 /// <param name="basicValueType">The type to allocate.</param>
 /// <returns>The allocated variable.</returns>
 public Variable AllocateType(ArithmeticBasicValueType basicValueType) =>
 new PrimitiveVariable(idCounter++, basicValueType);
Exemplo n.º 6
0
 /// <summary>
 /// Returns the native PrintF format for the given basic value type.
 /// </summary>
 /// <param name="valueType">The basic value type.</param>
 /// <returns>The resolved PrintF format.</returns>
 public static string GetPrintFFormat(ArithmeticBasicValueType valueType) =>
 PrintFFormats[(int)valueType];
Exemplo n.º 7
0
 /// <summary>
 /// Resolves a convert operation.
 /// </summary>
 /// <param name="source">The source type to convert from.</param>
 /// <param name="target">The target type to convert to.</param>
 /// <returns>The resolved convert operation.</returns>
 public static string GetConvertOperation(
     ArithmeticBasicValueType source,
     ArithmeticBasicValueType target) =>
 ConvertOperations.TryGetValue((source, target), out string operation)
Exemplo n.º 8
0
 /// <summary>
 /// Resolves a LEA operation.
 /// </summary>
 /// <param name="pointerType">The pointer type.</param>
 /// <returns>The resolved LEA operation.</returns>
 public static string GetLEAMulOperation(ArithmeticBasicValueType pointerType) =>
 LEAMulOperations[pointerType];
Exemplo n.º 9
0
 /// <summary>
 /// Resolves the given basic-value type to an atomic OpenCL type name.
 /// </summary>
 /// <param name="basicValueType">The basic-value type to resolve.</param>
 /// <returns>The resolved atomic OpenCL type name.</returns>
 public string GetAtomicType(ArithmeticBasicValueType basicValueType) =>
 basicValueType == ArithmeticBasicValueType.Float16 && !Capabilities.Float16
     ? throw CLCapabilityContext.GetNotSupportedFloat16Exception()
     : basicValueType == ArithmeticBasicValueType.Float64 && !Capabilities.Float64
         ? throw CLCapabilityContext.GetNotSupportedFloat64Exception()
         : AtomicTypeMapping[(int)basicValueType];
Exemplo n.º 10
0
 public static string GetAtomicOperationSuffix(AtomicKind kind, ArithmeticBasicValueType type) =>
Exemplo n.º 11
0
 public static string GetConvertOperation(ArithmeticBasicValueType source, ArithmeticBasicValueType target) =>
Exemplo n.º 12
0
 public static string GetCompareOperation(CompareKind kind, ArithmeticBasicValueType type) =>
Exemplo n.º 13
0
 /// <summary>
 /// Resolves the given basic-value type to an atomic OpenCL type name.
 /// </summary>
 /// <param name="basicValueType">The basic-value type to resolve.</param>
 /// <returns>The resolved atomic OpenCL type name.</returns>
 public static string GetAtomicType(ArithmeticBasicValueType basicValueType) =>
 AtomicTypeMapping[(int)basicValueType];
Exemplo n.º 14
0
            /// <summary>
            /// Appends a cast to the given arithmetic basic value type.
            /// </summary>
            /// <param name="type">The target type.</param>
            public void AppendCast(ArithmeticBasicValueType type)
            {
                var typeExpression = CLTypeGenerator.GetBasicValueType(type);

                AppendCast(typeExpression);
            }