//===----- hlsl_intrinsics.h - HLSL definitions for intrinsics ----------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _HLSL_HLSL_INTRINSICS_H_ #define _HLSL_HLSL_INTRINSICS_H_ #include "hlsl/hlsl_intrinsic_helpers.h" namespace hlsl { // Generated by clang-tblgen from HLSLIntrinsics.td (detail/inline intrinsics). #include "hlsl_inline_intrinsics_gen.inc" //===----------------------------------------------------------------------===// // asfloat builtins //===----------------------------------------------------------------------===// /// \fn float asfloat(T Val) /// \brief Interprets the bit pattern of x as float point number. /// \param Val The input value. template constexpr matrix asfloat(matrix V) { return __detail::bit_cast(V); } template constexpr vector asfloat(vector V) { return __detail::bit_cast(V); } template constexpr float asfloat(T F) { return __detail::bit_cast(F); } //===----------------------------------------------------------------------===// // asint builtins //===----------------------------------------------------------------------===// /// \fn int asint(T Val) /// \brief Interprets the bit pattern of x as an integer. /// \param Val The input value. template constexpr matrix asint(matrix V) { return __detail::bit_cast(V); } template constexpr vector asint(vector V) { return __detail::bit_cast(V); } template constexpr int asint(T F) { return __detail::bit_cast(F); } //===----------------------------------------------------------------------===// // asint16 builtins //===----------------------------------------------------------------------===// /// \fn int16_t asint16(T X) /// \brief Interprets the bit pattern of \a X as an 16-bit integer. /// \param X The input value. #ifdef __HLSL_ENABLE_16_BIT template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value || __detail::is_same::value, vector> asint16(vector V) { return __detail::bit_cast(V); } template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value || __detail::is_same::value, int16_t> asint16(T F) { return __detail::bit_cast(F); } #endif //===----------------------------------------------------------------------===// // asuint builtins //===----------------------------------------------------------------------===// /// \fn uint asuint(T Val) /// \brief Interprets the bit pattern of x as an unsigned integer. /// \param Val The input value. template constexpr matrix asuint(matrix V) { return __detail::bit_cast(V); } template constexpr vector asuint(vector V) { return __detail::bit_cast(V); } template constexpr uint asuint(T F) { return __detail::bit_cast(F); } //===----------------------------------------------------------------------===// // asuint splitdouble builtins //===----------------------------------------------------------------------===// /// \fn void asuint(double D, out uint lowbits, out int highbits) /// \brief Split and interprets the lowbits and highbits of double D into uints. /// \param D The input double. /// \param lowbits The output lowbits of D. /// \param highbits The output highbits of D. _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble) void asuint(double, out uint, out uint); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble) void asuint(double2, out uint2, out uint2); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble) void asuint(double3, out uint3, out uint3); _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble) void asuint(double4, out uint4, out uint4); template _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble) void asuint(matrix, out matrix, out matrix); //===----------------------------------------------------------------------===// // asuint16 builtins //===----------------------------------------------------------------------===// /// \fn uint16_t asuint16(T X) /// \brief Interprets the bit pattern of \a X as an 16-bit unsigned integer. /// \param X The input value. #ifdef __HLSL_ENABLE_16_BIT template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value || __detail::is_same::value, vector> asuint16(vector V) { return __detail::bit_cast(V); } template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value || __detail::is_same::value, uint16_t> asuint16(T F) { return __detail::bit_cast(F); } #endif //===----------------------------------------------------------------------===// // firstbithigh builtins //===----------------------------------------------------------------------===// /// \fn T firstbithigh(T Val) /// \brief Returns the location of the first set bit starting from the lowest /// order bit and working upward, per component. /// \param Val the input value. #ifdef __HLSL_ENABLE_16_BIT template _HLSL_AVAILABILITY(shadermodel, 6.2) const inline __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value, uint> firstbithigh(T X) { return __detail::firstbithigh_impl(X); } template _HLSL_AVAILABILITY(shadermodel, 6.2) const inline __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value, vector> firstbithigh(vector X) { return __detail::firstbithigh_impl, vector, 16>(X); } #endif template const inline __detail::enable_if_t< __detail::is_same::value || __detail::is_same::value, uint> firstbithigh(T X) { return __detail::firstbithigh_impl(X); } template const inline __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value, vector> firstbithigh(vector X) { return __detail::firstbithigh_impl, vector, 32>(X); } template const inline __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value, uint> firstbithigh(T X) { return __detail::firstbithigh_impl(X); } template const inline __detail::enable_if_t<__detail::is_same::value || __detail::is_same::value, vector> firstbithigh(vector X) { return __detail::firstbithigh_impl, vector, 64>(X); } //===----------------------------------------------------------------------===// // mul builtins //===----------------------------------------------------------------------===// /// \fn R mul(X x, Y y) /// \brief Multiplies x and y using matrix math. /// \param x [in] The first input value. If x is a vector, it is treated as a /// row vector. /// \param y [in] The second input value. If y is a vector, it is treated as a /// column vector. /// /// The inner dimension x-columns and y-rows must be equal. The result has the /// dimension x-rows x y-columns. When both x and y are vectors, the result is /// a dot product (scalar). Scalar operands are multiplied element-wise. /// /// This function supports 9 overloaded forms: /// 1. scalar * scalar -> scalar /// 2. scalar * vector -> vector /// 3. scalar * matrix -> matrix /// 4. vector * scalar -> vector /// 5. vector * vector -> scalar (dot product) /// 6. vector * matrix -> vector /// 7. matrix * scalar -> matrix /// 8. matrix * vector -> vector /// 9. matrix * matrix -> matrix // Cases 1, 2, 3, 4, 5, and 7 of mul are defined below as // header-only implementations because they are elementwise operations and dot // products easily expressed in HLSL. // Cases 6, 8, and 9 are defined in hlsl_alias_intrinsics.h to alias the mul // builtin so that they can be lowered to the llvm.matrix.multiply intrinsic // which is not exposed directly to HLSL. // Case 1: scalar * scalar -> scalar template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr __detail::enable_if_t<__detail::is_arithmetic::Value && __detail::is_same::value, T> mul(T x, T y) { return x * y; } template constexpr __detail::enable_if_t< __detail::is_arithmetic::Value && !__detail::is_same::value, T> mul(T x, T y) { return x * y; } // Case 2: scalar * vector -> vector template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr vector mul(half x, vector y) { return x * y; } template constexpr vector mul(T x, vector y) { return x * y; } // Case 3: scalar * matrix -> matrix template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr matrix mul(half x, matrix y) { return x * y; } template constexpr matrix mul(T x, matrix y) { return x * y; } // Case 4: vector * scalar -> vector template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr vector mul(vector x, half y) { return x * y; } template constexpr vector mul(vector x, T y) { return x * y; } // Case 5: vector * vector -> scalar (dot product) template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) half mul(vector x, vector y) { return __detail::mul_vec_impl(x, y); } template T mul(vector x, vector y) { return __detail::mul_vec_impl(x, y); } // Case 7: matrix * scalar -> matrix template _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) constexpr matrix mul(matrix x, half y) { return x * y; } template constexpr matrix mul(matrix x, T y) { return x * y; } } // namespace hlsl #endif //_HLSL_HLSL_INTRINSICS_H_