Skip to content

Commit 083d949

Browse files
bob80905python3kgae
authored andcommitted
[HLSL] add sin library function
This change exposes the sin library function for HLSL, excluding long, int, and long long doubles. Sin is supported for all scalar, vector, and matrix types. Long and long long double support is missing in this patch because those types don't exist in HLSL. Int is missing because the sin function only works on floating type arguments. The full documentation of the HLSL sin function is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-sin Reviewed By: python3kgae Differential Revision: https://reviews.llvm.org/D138161
1 parent fd0aeaa commit 083d949

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,34 @@ double3 cos(double3);
130130
__attribute__((clang_builtin_alias(__builtin_elementwise_cos)))
131131
double4 cos(double4);
132132

133+
// sin builtins
134+
#ifdef __HLSL_ENABLE_16_BIT
135+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin))) half sin(half);
136+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
137+
half2 sin(half2);
138+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
139+
half3 sin(half3);
140+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
141+
half4 sin(half4);
142+
#endif
143+
144+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin))) float
145+
sin(float);
146+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
147+
float2 sin(float2);
148+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
149+
float3 sin(float3);
150+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
151+
float4 sin(float4);
152+
153+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin))) double
154+
sin(double);
155+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
156+
double2 sin(double2);
157+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
158+
double3 sin(double3);
159+
__attribute__((clang_builtin_alias(__builtin_elementwise_sin)))
160+
double4 sin(double4);
161+
133162
} // namespace hlsl
134163
#endif //_HLSL_HLSL_INTRINSICS_H_
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
4+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
5+
// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
6+
// RUN: -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
7+
8+
// CHECK: define noundef half @
9+
// CHECK: call half @llvm.sin.f16(
10+
// NO_HALF: define noundef float @"?test_sin_half@@YA$halff@$halff@@Z"(
11+
// NO_HALF: call float @llvm.sin.f32(
12+
half test_sin_half ( half p0 ) {
13+
return sin ( p0 );
14+
}
15+
// CHECK: define noundef <2 x half> @
16+
// CHECK: call <2 x half> @llvm.sin.v2f16
17+
// NO_HALF: define noundef <2 x float> @"?test_sin_float2@@YAT?$__vector@M$01@__clang@@T12@@Z"(
18+
// NO_HALF: call <2 x float> @llvm.sin.v2f32(
19+
half2 test_sin_half2 ( half2 p0 ) {
20+
return sin ( p0 );
21+
}
22+
// CHECK: define noundef <3 x half> @
23+
// CHECK: call <3 x half> @llvm.sin.v3f16
24+
// NO_HALF: define noundef <3 x float> @"?test_sin_float3@@YAT?$__vector@M$02@__clang@@T12@@Z"(
25+
// NO_HALF: call <3 x float> @llvm.sin.v3f32(
26+
half3 test_sin_half3 ( half3 p0 ) {
27+
return sin ( p0 );
28+
}
29+
// CHECK: define noundef <4 x half> @
30+
// CHECK: call <4 x half> @llvm.sin.v4f16
31+
// NO_HALF: define noundef <4 x float> @"?test_sin_float4@@YAT?$__vector@M$03@__clang@@T12@@Z"(
32+
// NO_HALF: call <4 x float> @llvm.sin.v4f32(
33+
half4 test_sin_half4 ( half4 p0 ) {
34+
return sin ( p0 );
35+
}
36+
37+
// CHECK: define noundef float @
38+
// CHECK: call float @llvm.sin.f32(
39+
float test_sin_float ( float p0 ) {
40+
return sin ( p0 );
41+
}
42+
// CHECK: define noundef <2 x float> @
43+
// CHECK: call <2 x float> @llvm.sin.v2f32
44+
float2 test_sin_float2 ( float2 p0 ) {
45+
return sin ( p0 );
46+
}
47+
// CHECK: define noundef <3 x float> @
48+
// CHECK: call <3 x float> @llvm.sin.v3f32
49+
float3 test_sin_float3 ( float3 p0 ) {
50+
return sin ( p0 );
51+
}
52+
// CHECK: define noundef <4 x float> @
53+
// CHECK: call <4 x float> @llvm.sin.v4f32
54+
float4 test_sin_float4 ( float4 p0 ) {
55+
return sin ( p0 );
56+
}

0 commit comments

Comments
 (0)