Skip to content

Commit f612d70

Browse files
authored
[HLSL] Add new int overloads for math builtins (#133162)
Add int overloads which cast the various ints to a float and call the float builtin. These overloads are conditional on hlsl version 202x or earlier. Add tests and puts tests in own files, including some of the tests added for double overloads. Closes #128229
1 parent 3a5d776 commit f612d70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2892
-527
lines changed

clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Lines changed: 136 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \
2+
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
3+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK
4+
5+
// CHECK-LABEL: test_acos_double
6+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
7+
float test_acos_double ( double p0 ) {
8+
return acos ( p0 );
9+
}
10+
11+
// CHECK-LABEL: test_acos_double2
12+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
13+
float2 test_acos_double2 ( double2 p0 ) {
14+
return acos ( p0 );
15+
}
16+
17+
// CHECK-LABEL: test_acos_double3
18+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
19+
float3 test_acos_double3 ( double3 p0 ) {
20+
return acos ( p0 );
21+
}
22+
23+
// CHECK-LABEL: test_acos_double4
24+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
25+
float4 test_acos_double4 ( double4 p0 ) {
26+
return acos ( p0 );
27+
}
28+
29+
// CHECK-LABEL: test_acos_int
30+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
31+
float test_acos_int ( int p0 ) {
32+
return acos ( p0 );
33+
}
34+
35+
// CHECK-LABEL: test_acos_int2
36+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
37+
float2 test_acos_int2 ( int2 p0 ) {
38+
return acos ( p0 );
39+
}
40+
41+
// CHECK-LABEL: test_acos_int3
42+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
43+
float3 test_acos_int3 ( int3 p0 ) {
44+
return acos ( p0 );
45+
}
46+
47+
// CHECK-LABEL: test_acos_int4
48+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
49+
float4 test_acos_int4 ( int4 p0 ) {
50+
return acos ( p0 );
51+
}
52+
53+
// CHECK-LABEL: test_acos_uint
54+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
55+
float test_acos_uint ( uint p0 ) {
56+
return acos ( p0 );
57+
}
58+
59+
// CHECK-LABEL: test_acos_uint2
60+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
61+
float2 test_acos_uint2 ( uint2 p0 ) {
62+
return acos ( p0 );
63+
}
64+
65+
// CHECK-LABEL: test_acos_uint3
66+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
67+
float3 test_acos_uint3 ( uint3 p0 ) {
68+
return acos ( p0 );
69+
}
70+
71+
// CHECK-LABEL: test_acos_uint4
72+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
73+
float4 test_acos_uint4 ( uint4 p0 ) {
74+
return acos ( p0 );
75+
}
76+
77+
// CHECK-LABEL: test_acos_int64_t
78+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
79+
float test_acos_int64_t ( int64_t p0 ) {
80+
return acos ( p0 );
81+
}
82+
83+
// CHECK-LABEL: test_acos_int64_t2
84+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
85+
float2 test_acos_int64_t2 ( int64_t2 p0 ) {
86+
return acos ( p0 );
87+
}
88+
89+
// CHECK-LABEL: test_acos_int64_t3
90+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
91+
float3 test_acos_int64_t3 ( int64_t3 p0 ) {
92+
return acos ( p0 );
93+
}
94+
95+
// CHECK-LABEL: test_acos_int64_t4
96+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
97+
float4 test_acos_int64_t4 ( int64_t4 p0 ) {
98+
return acos ( p0 );
99+
}
100+
101+
// CHECK-LABEL: test_acos_uint64_t
102+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
103+
float test_acos_uint64_t ( uint64_t p0 ) {
104+
return acos ( p0 );
105+
}
106+
107+
// CHECK-LABEL: test_acos_uint64_t2
108+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
109+
float2 test_acos_uint64_t2 ( uint64_t2 p0 ) {
110+
return acos ( p0 );
111+
}
112+
113+
// CHECK-LABEL: test_acos_uint64_t3
114+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
115+
float3 test_acos_uint64_t3 ( uint64_t3 p0 ) {
116+
return acos ( p0 );
117+
}
118+
119+
// CHECK-LABEL: test_acos_uint64_t4
120+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
121+
float4 test_acos_uint64_t4 ( uint64_t4 p0 ) {
122+
return acos ( p0 );
123+
}

clang/test/CodeGenHLSL/builtins/acos.hlsl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,3 @@ float3 test_acos_float3 ( float3 p0 ) {
5757
float4 test_acos_float4 ( float4 p0 ) {
5858
return acos ( p0 );
5959
}
60-
61-
// CHECK-LABEL: test_acos_double
62-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.acos.f32
63-
float test_acos_double ( double p0 ) {
64-
return acos ( p0 );
65-
}
66-
67-
// CHECK-LABEL: test_acos_double2
68-
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.acos.v2f32
69-
float2 test_acos_double2 ( double2 p0 ) {
70-
return acos ( p0 );
71-
}
72-
73-
// CHECK-LABEL: test_acos_double3
74-
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.acos.v3f32
75-
float3 test_acos_double3 ( double3 p0 ) {
76-
return acos ( p0 );
77-
}
78-
79-
// CHECK-LABEL: test_acos_double4
80-
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.acos.v4f32
81-
float4 test_acos_double4 ( double4 p0 ) {
82-
return acos ( p0 );
83-
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple \
2+
// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
3+
// RUN: -o - | FileCheck %s --check-prefixes=CHECK
4+
5+
// CHECK-LABEL: test_asin_double
6+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
7+
float test_asin_double ( double p0 ) {
8+
return asin ( p0 );
9+
}
10+
11+
// CHECK-LABEL: test_asin_double2
12+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
13+
float2 test_asin_double2 ( double2 p0 ) {
14+
return asin ( p0 );
15+
}
16+
17+
// CHECK-LABEL: test_asin_double3
18+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
19+
float3 test_asin_double3 ( double3 p0 ) {
20+
return asin ( p0 );
21+
}
22+
23+
// CHECK-LABEL: test_asin_double4
24+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
25+
float4 test_asin_double4 ( double4 p0 ) {
26+
return asin ( p0 );
27+
}
28+
29+
// CHECK-LABEL: test_asin_int
30+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
31+
float test_asin_int ( int p0 ) {
32+
return asin ( p0 );
33+
}
34+
35+
// CHECK-LABEL: test_asin_int2
36+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
37+
float2 test_asin_int2 ( int2 p0 ) {
38+
return asin ( p0 );
39+
}
40+
41+
// CHECK-LABEL: test_asin_int3
42+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
43+
float3 test_asin_int3 ( int3 p0 ) {
44+
return asin ( p0 );
45+
}
46+
47+
// CHECK-LABEL: test_asin_int4
48+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
49+
float4 test_asin_int4 ( int4 p0 ) {
50+
return asin ( p0 );
51+
}
52+
53+
// CHECK-LABEL: test_asin_uint
54+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
55+
float test_asin_uint ( uint p0 ) {
56+
return asin ( p0 );
57+
}
58+
59+
// CHECK-LABEL: test_asin_uint2
60+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
61+
float2 test_asin_uint2 ( uint2 p0 ) {
62+
return asin ( p0 );
63+
}
64+
65+
// CHECK-LABEL: test_asin_uint3
66+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
67+
float3 test_asin_uint3 ( uint3 p0 ) {
68+
return asin ( p0 );
69+
}
70+
71+
// CHECK-LABEL: test_asin_uint4
72+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
73+
float4 test_asin_uint4 ( uint4 p0 ) {
74+
return asin ( p0 );
75+
}
76+
77+
// CHECK-LABEL: test_asin_int64_t
78+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
79+
float test_asin_int64_t ( int64_t p0 ) {
80+
return asin ( p0 );
81+
}
82+
83+
// CHECK-LABEL: test_asin_int64_t2
84+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
85+
float2 test_asin_int64_t2 ( int64_t2 p0 ) {
86+
return asin ( p0 );
87+
}
88+
89+
// CHECK-LABEL: test_asin_int64_t3
90+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
91+
float3 test_asin_int64_t3 ( int64_t3 p0 ) {
92+
return asin ( p0 );
93+
}
94+
95+
// CHECK-LABEL: test_asin_int64_t4
96+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
97+
float4 test_asin_int64_t4 ( int64_t4 p0 ) {
98+
return asin ( p0 );
99+
}
100+
101+
// CHECK-LABEL: test_asin_uint64_t
102+
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
103+
float test_asin_uint64_t ( uint64_t p0 ) {
104+
return asin ( p0 );
105+
}
106+
107+
// CHECK-LABEL: test_asin_uint64_t2
108+
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
109+
float2 test_asin_uint64_t2 ( uint64_t2 p0 ) {
110+
return asin ( p0 );
111+
}
112+
113+
// CHECK-LABEL: test_asin_uint64_t3
114+
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
115+
float3 test_asin_uint64_t3 ( uint64_t3 p0 ) {
116+
return asin ( p0 );
117+
}
118+
119+
// CHECK-LABEL: test_asin_uint64_t4
120+
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
121+
float4 test_asin_uint64_t4 ( uint64_t4 p0 ) {
122+
return asin ( p0 );
123+
}

clang/test/CodeGenHLSL/builtins/asin.hlsl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,3 @@ float3 test_asin_float3 ( float3 p0 ) {
5757
float4 test_asin_float4 ( float4 p0 ) {
5858
return asin ( p0 );
5959
}
60-
61-
// CHECK-LABEL: test_asin_double
62-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.asin.f32
63-
float test_asin_double ( double p0 ) {
64-
return asin ( p0 );
65-
}
66-
67-
// CHECK-LABEL: test_asin_double2
68-
// CHECK: call reassoc nnan ninf nsz arcp afn <2 x float> @llvm.asin.v2f32
69-
float2 test_asin_double2 ( double2 p0 ) {
70-
return asin ( p0 );
71-
}
72-
73-
// CHECK-LABEL: test_asin_double3
74-
// CHECK: call reassoc nnan ninf nsz arcp afn <3 x float> @llvm.asin.v3f32
75-
float3 test_asin_double3 ( double3 p0 ) {
76-
return asin ( p0 );
77-
}
78-
79-
// CHECK-LABEL: test_asin_double4
80-
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.asin.v4f32
81-
float4 test_asin_double4 ( double4 p0 ) {
82-
return asin ( p0 );
83-
}

0 commit comments

Comments
 (0)