https://github.com/joaosaffran created https://github.com/llvm/llvm-project/pull/107614
None >From eb176f0cef8943ae5ae9d64d71d01649dd30fd93 Mon Sep 17 00:00:00 2001 From: Joao Saffran <jdereze...@microsoft.com> Date: Fri, 6 Sep 2024 16:27:51 +0000 Subject: [PATCH] adding asfloat function to hlsl --- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 13 +++++++++++ clang/test/CodeGenHLSL/builtins/asuint.hlsl | 26 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 clang/test/CodeGenHLSL/builtins/asuint.hlsl diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index 5c08a45a35377d..195777f5b15823 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -391,6 +391,19 @@ float4 asin(float4); // atan builtins //===----------------------------------------------------------------------===// +__attribute__((__always_inline__, __nodebug__)) + static inline float asfloat(int __A) { + return __builtin_bit_cast(float, __A); // no-warning +} + + template<int N> +__attribute__((__always_inline__, __nodebug__)) + static inline vector<float, N> asfloat(vector<int, N> V) { + return __builtin_bit_cast(vector<float, N>, V); +} + + + /// \fn T atan(T Val) /// \brief Returns the arctangent of the input value, \a Val. /// \param Val The input value. diff --git a/clang/test/CodeGenHLSL/builtins/asuint.hlsl b/clang/test/CodeGenHLSL/builtins/asuint.hlsl new file mode 100644 index 00000000000000..3bbd49fa964824 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/asuint.hlsl @@ -0,0 +1,26 @@ +// // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s + + +// CHECK-LABEL: test_asuint4_uint +// CHECK: ret i32 %0 +export uint test_asuint4_uint(uint p0) { + return asuint(p0); +} + +// CHECK-LABEL: test_asuint4_int +// CHECK: %splat.splatinsert = insertelement <4 x i32> poison, i32 %0, i64 0 +export uint4 test_asuint4_int(int p0) { + return asuint(p0); +} + +// CHECK-LABEL: test_asuint_float +// CHECK: %1 = bitcast float %0 to i32 +export uint test_asuint_float(float p0) { + return asuint(p0); +} + +// CHECK-LABEL: test_asuint_float +// CHECK: %1 = bitcast <4 x float> %0 to <4 x i32> +export uint4 test_asuint_float4(float4 p0) { + return asuint(p0); +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits