diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -476,5 +476,61 @@ __attribute__((clang_builtin_alias(__builtin_elementwise_min))) double4 min(double4, double4); +// reversebits builtins +#ifdef __HLSL_ENABLE_16_BIT +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int16_t reversebits(int16_t); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int16_t2 reversebits(int16_t2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int16_t3 reversebits(int16_t3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int16_t4 reversebits(int16_t4); + +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint16_t reversebits(uint16_t); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint16_t2 reversebits(uint16_t2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint16_t3 reversebits(uint16_t3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint16_t4 reversebits(uint16_t4); +#endif + +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) int +reversebits(int); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int2 reversebits(int2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int3 reversebits(int3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int4 reversebits(int4); + +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint reversebits(uint); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint2 reversebits(uint2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint3 reversebits(uint3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint4 reversebits(uint4); + +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int64_t reversebits(int64_t); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int64_t2 reversebits(int64_t2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int64_t3 reversebits(int64_t3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +int64_t4 reversebits(int64_t4); + +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint64_t reversebits(uint64_t); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint64_t2 reversebits(uint64_t2); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint64_t3 reversebits(uint64_t3); +__attribute__((clang_builtin_alias(__builtin_elementwise_bitreverse))) +uint64_t4 reversebits(uint64_t4); } // namespace hlsl #endif //_HLSL_HLSL_INTRINSICS_H_ diff --git a/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl b/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/bitreverse.hlsl @@ -0,0 +1,155 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \ +// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s + +#ifdef __HLSL_ENABLE_16_BIT +// CHECK: define noundef i16 @ +// CHECK: call i16 @llvm.bitreverse.i16( +int16_t test_bitreverse_short(int16_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i16> @ +// CHECK: call <2 x i16> @llvm.bitreverse.v2i16( +int16_t2 test_bitreverse_short2(int16_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i16> @ +// CHECK: call <3 x i16> @llvm.bitreverse.v3i16 +int16_t3 test_bitreverse_short3(int16_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i16> @ +// CHECK: call <4 x i16> @llvm.bitreverse.v4i16 +int16_t4 test_bitreverse_short4(int16_t4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i16 @ +// CHECK: call i16 @llvm.bitreverse.i16( +uint16_t test_bitreverse_ushort(uint16_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i16> @ +// CHECK: call <2 x i16> @llvm.bitreverse.v2i16 +uint16_t2 test_bitreverse_ushort2(uint16_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i16> @ +// CHECK: call <3 x i16> @llvm.bitreverse.v3i16 +uint16_t3 test_bitreverse_ushort3(uint16_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i16> @ +// CHECK: call <4 x i16> @llvm.bitreverse.v4i16 +uint16_t4 test_bitreverse_ushort4(uint16_t4 p0) +{ + return reversebits(p0); +} +#endif + +// CHECK: define noundef i32 @ +// CHECK: call i32 @llvm.bitreverse.i32( +int test_bitreverse_int(int p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i32> @ +// CHECK: call <2 x i32> @llvm.bitreverse.v2i32 +int2 test_bitreverse_int2(int2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i32> @ +// CHECK: call <3 x i32> @llvm.bitreverse.v3i32 +int3 test_bitreverse_int3(int3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i32> @ +// CHECK: call <4 x i32> @llvm.bitreverse.v4i32 +int4 test_bitreverse_int4(int4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i32 @ +// CHECK: call i32 @llvm.bitreverse.i32( +int test_bitreverse_uint(uint p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i32> @ +// CHECK: call <2 x i32> @llvm.bitreverse.v2i32 +uint2 test_bitreverse_uint2(uint2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i32> @ +// CHECK: call <3 x i32> @llvm.bitreverse.v3i32 +uint3 test_bitreverse_uint3(uint3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i32> @ +// CHECK: call <4 x i32> @llvm.bitreverse.v4i32 +uint4 test_bitreverse_uint4(uint4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i64 @ +// CHECK: call i64 @llvm.bitreverse.i64( +int64_t test_bitreverse_long(int64_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i64> @ +// CHECK: call <2 x i64> @llvm.bitreverse.v2i64 +int64_t2 test_bitreverse_long2(int64_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i64> @ +// CHECK: call <3 x i64> @llvm.bitreverse.v3i64 +int64_t3 test_bitreverse_long3(int64_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i64> @ +// CHECK: call <4 x i64> @llvm.bitreverse.v4i64 +int64_t4 test_bitreverse_long4(int64_t4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i64 @ +// CHECK: call i64 @llvm.bitreverse.i64( +uint64_t test_bitreverse_long(uint64_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i64> @ +// CHECK: call <2 x i64> @llvm.bitreverse.v2i64 +uint64_t2 test_bitreverse_long2(uint64_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i64> @ +// CHECK: call <3 x i64> @llvm.bitreverse.v3i64 +uint64_t3 test_bitreverse_long3(uint64_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i64> @ +// CHECK: call <4 x i64> @llvm.bitreverse.v4i64 +uint64_t4 test_bitreverse_long4(uint64_t4 p0) +{ + return reversebits(p0); +} diff --git a/clang/test/CodeGenHLSL/builtins/reversebits.hlsl b/clang/test/CodeGenHLSL/builtins/reversebits.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/reversebits.hlsl @@ -0,0 +1,155 @@ +// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ +// RUN: -D__HLSL_ENABLE_16_BIT -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s + +#ifdef __HLSL_ENABLE_16_BIT +// CHECK: define noundef i16 @ +// CHECK: call i16 @llvm.bitreverse.i16( +int16_t test_bitreverse_short(int16_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i16> @ +// CHECK: call <2 x i16> @llvm.bitreverse.v2i16( +int16_t2 test_bitreverse_short2(int16_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i16> @ +// CHECK: call <3 x i16> @llvm.bitreverse.v3i16 +int16_t3 test_bitreverse_short3(int16_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i16> @ +// CHECK: call <4 x i16> @llvm.bitreverse.v4i16 +int16_t4 test_bitreverse_short4(int16_t4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i16 @ +// CHECK: call i16 @llvm.bitreverse.i16( +uint16_t test_bitreverse_ushort(uint16_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i16> @ +// CHECK: call <2 x i16> @llvm.bitreverse.v2i16 +uint16_t2 test_bitreverse_ushort2(uint16_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i16> @ +// CHECK: call <3 x i16> @llvm.bitreverse.v3i16 +uint16_t3 test_bitreverse_ushort3(uint16_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i16> @ +// CHECK: call <4 x i16> @llvm.bitreverse.v4i16 +uint16_t4 test_bitreverse_ushort4(uint16_t4 p0) +{ + return reversebits(p0); +} +#endif + +// CHECK: define noundef i32 @ +// CHECK: call i32 @llvm.bitreverse.i32( +int test_bitreverse_int(int p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i32> @ +// CHECK: call <2 x i32> @llvm.bitreverse.v2i32 +int2 test_bitreverse_int2(int2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i32> @ +// CHECK: call <3 x i32> @llvm.bitreverse.v3i32 +int3 test_bitreverse_int3(int3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i32> @ +// CHECK: call <4 x i32> @llvm.bitreverse.v4i32 +int4 test_bitreverse_int4(int4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i32 @ +// CHECK: call i32 @llvm.bitreverse.i32( +int test_bitreverse_uint(uint p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i32> @ +// CHECK: call <2 x i32> @llvm.bitreverse.v2i32 +uint2 test_bitreverse_uint2(uint2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i32> @ +// CHECK: call <3 x i32> @llvm.bitreverse.v3i32 +uint3 test_bitreverse_uint3(uint3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i32> @ +// CHECK: call <4 x i32> @llvm.bitreverse.v4i32 +uint4 test_bitreverse_uint4(uint4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i64 @ +// CHECK: call i64 @llvm.bitreverse.i64( +int64_t test_bitreverse_long(int64_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i64> @ +// CHECK: call <2 x i64> @llvm.bitreverse.v2i64 +int64_t2 test_bitreverse_long2(int64_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i64> @ +// CHECK: call <3 x i64> @llvm.bitreverse.v3i64 +int64_t3 test_bitreverse_long3(int64_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i64> @ +// CHECK: call <4 x i64> @llvm.bitreverse.v4i64 +int64_t4 test_bitreverse_long4(int64_t4 p0) +{ + return reversebits(p0); +} + +// CHECK: define noundef i64 @ +// CHECK: call i64 @llvm.bitreverse.i64( +uint64_t test_bitreverse_long(uint64_t p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <2 x i64> @ +// CHECK: call <2 x i64> @llvm.bitreverse.v2i64 +uint64_t2 test_bitreverse_long2(uint64_t2 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <3 x i64> @ +// CHECK: call <3 x i64> @llvm.bitreverse.v3i64 +uint64_t3 test_bitreverse_long3(uint64_t3 p0) +{ + return reversebits(p0); +} +// CHECK: define noundef <4 x i64> @ +// CHECK: call <4 x i64> @llvm.bitreverse.v4i64 +uint64_t4 test_bitreverse_long4(uint64_t4 p0) +{ + return reversebits(p0); +}