clang 20.0.0git
hlsl_detail.h
Go to the documentation of this file.
1//===----- detail.h - HLSL definitions for intrinsics ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _HLSL_HLSL_DETAILS_H_
10#define _HLSL_HLSL_DETAILS_H_
11
12namespace hlsl {
13
14namespace __detail {
15
16template <typename T, typename U> struct is_same {
17 static const bool value = false;
18};
19
20template <typename T> struct is_same<T, T> {
21 static const bool value = true;
22};
23
24template <bool B, typename T> struct enable_if {};
25
26template <typename T> struct enable_if<true, T> {
27 using Type = T;
28};
29
30template <bool B, class T = void>
32
33template <typename U, typename T, int N>
34constexpr enable_if_t<sizeof(U) == sizeof(T), vector<U, N>>
35bit_cast(vector<T, N> V) {
36 return __builtin_bit_cast(vector<U, N>, V);
37}
38
39template <typename U, typename T>
40constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) {
41 return __builtin_bit_cast(U, F);
42}
43
44template <typename T>
45constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
47 return __builtin_elementwise_abs(X);
48}
49
50template <typename T, int N>
51constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
52length_vec_impl(vector<T, N> X) {
53 return __builtin_elementwise_sqrt(__builtin_hlsl_dot(X, X));
54}
55
56template <typename T>
57constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
59 return length_impl(X - Y);
60}
61
62template <typename T, int N>
63constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
64distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
65#if (__has_builtin(__builtin_spirv_distance))
66 return __builtin_spirv_distance(X, Y);
67#else
68 return length_vec_impl(X - Y);
69#endif
70}
71} // namespace __detail
72} // namespace hlsl
73#endif //_HLSL_HLSL_DETAILS_H_
#define V(N, I)
Definition: ASTContext.h:3453
#define X(type, name)
Definition: Value.h:144
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > distance_impl(T X, T Y)
Definition: hlsl_detail.h:58
typename enable_if< B, T >::Type enable_if_t
Definition: hlsl_detail.h:31
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > distance_vec_impl(vector< T, N > X, vector< T, N > Y)
Definition: hlsl_detail.h:64
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > length_impl(T X)
Definition: hlsl_detail.h:46
constexpr enable_if_t< is_same< float, T >::value||is_same< half, T >::value, T > length_vec_impl(vector< T, N > X)
Definition: hlsl_detail.h:52
constexpr enable_if_t< sizeof(U)==sizeof(T), vector< U, N > > bit_cast(vector< T, N > V)
Definition: hlsl_detail.h:35
#define true
Definition: stdbool.h:25
static const bool value
Definition: hlsl_detail.h:17